Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 15 additions & 36 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -36,11 +35,10 @@ func main() {
}

const tlsCertRoot = "/etc/pki/tls/certs"
const runtimeCertRoot = "/etc/docker/certs.d"

clusterCASrc := fmt.Sprintf("%s/ca.crt", builder.SecretCertsMountPath)
clusterCADst := fmt.Sprintf("%s/cluster.crt", tlsCertRoot)
err := CopyFileIfExists(clusterCASrc, clusterCADst)
err := CopyIfExists(clusterCASrc, clusterCADst)
if err != nil {
fmt.Printf("Error setting up cluster CA cert: %v", err)
os.Exit(1)
Expand All @@ -49,57 +47,38 @@ func main() {
// TODO: Remove this once the config-map based mount approach lands after rebase
oldServiceCASrc := fmt.Sprintf("%s/service-ca.crt", builder.SecretCertsMountPath)
oldServiceCADst := fmt.Sprintf("%s/service.crt", tlsCertRoot)
err = CopyFileIfExists(oldServiceCASrc, oldServiceCADst)
err = CopyIfExists(oldServiceCASrc, oldServiceCADst)
if err != nil {
fmt.Printf("Error setting up service CA cert: %v", err)
os.Exit(1)
}

runtimeCASrc := fmt.Sprintf("%s/certs.d", builder.ConfigMapCertsMountPath)
err = CopyDirIfExists(runtimeCASrc, runtimeCertRoot)
newServiceCASrc := fmt.Sprintf("%s/service-ca.crt", builder.ConfigMapCertsMountPath)
newServiceCADst := fmt.Sprintf("%s/openshift-service.crt", tlsCertRoot)
err = CopyIfExists(newServiceCASrc, newServiceCADst)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bparees I think this restores copying the service-serving CA to the TLS root (the one injected by the controller)

if err != nil {
fmt.Printf("Error setting up service CA cert: %v", err)
os.Exit(1)
}

additionalCASrc := fmt.Sprintf("%s/additional-ca.crt", builder.ConfigMapCertsMountPath)
additionalCADst := fmt.Sprintf("%s/additional-ca.crt", tlsCertRoot)
err = CopyIfExists(additionalCASrc, additionalCADst)
if err != nil {
fmt.Printf("Error setting up additional trusted CA bundle: %v", err)
os.Exit(1)
}

basename := filepath.Base(os.Args[0])
command := CommandFor(basename)
if err := command.Execute(); err != nil {
os.Exit(1)
}
}

// CopyDirIfExists recursively copies a directory to the destination path.
// If the source directory does not exist, no error is returned.
// If the destination directory exists, any contents with matching file names
// will be overwritten.
func CopyDirIfExists(src, dst string) error {
srcInfo, err := os.Stat(src)
if os.IsNotExist(err) {
return nil
}
if err = os.MkdirAll(dst, srcInfo.Mode()); err != nil {
return err
}
dirInfo, err := ioutil.ReadDir(src)
for _, info := range dirInfo {
srcPath := filepath.Join(src, info.Name())
dstPath := filepath.Join(dst, info.Name())
if info.IsDir() {
err = CopyDirIfExists(srcPath, dstPath)
} else {
err = CopyFileIfExists(srcPath, dstPath)
}
if err != nil {
return err
}
}
return nil
}

// CopyFileIfExists copies the source file to the given destination, if the source file exists.
// CopyIfExists copies the source file to the given destination, if the source file exists.
// If the destination file exists, it will be overwritten and will not copy file attributes.
func CopyFileIfExists(src, dst string) error {
func CopyIfExists(src, dst string) error {
_, err := os.Stat(src)
if os.IsNotExist(err) {
return nil
Expand Down