diff --git a/pkg/minikube/bootstrapper/certs.go b/pkg/minikube/bootstrapper/certs.go index cd7bed704766f8aee6f97a22026c3287110b4133..5a556563c0ee34373c8ea3107d9317d9b69cf91f 100644 --- a/pkg/minikube/bootstrapper/certs.go +++ b/pkg/minikube/bootstrapper/certs.go @@ -25,6 +25,7 @@ import ( "path" "path/filepath" "strings" + "time" "github.com/golang/glog" "github.com/pkg/errors" @@ -37,6 +38,9 @@ import ( "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/kubeconfig" "k8s.io/minikube/pkg/util" + + "github.com/juju/clock" + "github.com/juju/mutex" ) const ( @@ -122,13 +126,25 @@ func SetupCerts(cmd command.Runner, k8s config.KubernetesConfig) error { } func generateCerts(k8s config.KubernetesConfig) error { + // TODO: Instead of racey manipulation of a shared certificate, use per-profile certs + spec := mutex.Spec{ + Name: "generateCerts", + Clock: clock.WallClock, + Delay: 10 * time.Second, + } + glog.Infof("acquiring lock: %+v", spec) + releaser, err := mutex.Acquire(spec) + if err != nil { + return errors.Wrapf(err, "unable to acquire lock for %+v", spec) + } + defer releaser.Release() + serviceIP, err := util.GetServiceClusterIP(k8s.ServiceCIDR) if err != nil { return errors.Wrap(err, "getting service cluster ip") } localPath := constants.GetMinipath() - caCertPath := filepath.Join(localPath, "ca.crt") caKeyPath := filepath.Join(localPath, "ca.key") diff --git a/pkg/util/crypto.go b/pkg/util/crypto.go index 48031ef97a08ba4c32a4dd8319562287fe2708e8..417417e2155194d34ff79b5de1043fe55eeab81e 100644 --- a/pkg/util/crypto.go +++ b/pkg/util/crypto.go @@ -30,6 +30,7 @@ import ( "path/filepath" "time" + "github.com/golang/glog" "github.com/pkg/errors" "k8s.io/minikube/pkg/util/lock" ) @@ -65,6 +66,7 @@ func GenerateCACert(certPath, keyPath string, name string) error { // GenerateSignedCert generates a signed certificate and key func GenerateSignedCert(certPath, keyPath, cn string, ips []net.IP, alternateDNS []string, signerCertPath, signerKeyPath string) error { + glog.Infof("Generating cert %s with IP's: %s", certPath, ips) signerCertBytes, err := ioutil.ReadFile(signerCertPath) if err != nil { return errors.Wrap(err, "Error reading file: signerCertPath") @@ -152,6 +154,7 @@ func writeCertsAndKeys(template *x509.Certificate, certPath string, signeeKey *r if err := os.MkdirAll(filepath.Dir(certPath), os.FileMode(0755)); err != nil { return errors.Wrap(err, "Error creating certificate directory") } + glog.Infof("Writing cert to %s ...", certPath) if err := lock.WriteFile(certPath, certBuffer.Bytes(), os.FileMode(0644)); err != nil { return errors.Wrap(err, "Error writing certificate to cert path") } @@ -159,6 +162,7 @@ func writeCertsAndKeys(template *x509.Certificate, certPath string, signeeKey *r if err := os.MkdirAll(filepath.Dir(keyPath), os.FileMode(0755)); err != nil { return errors.Wrap(err, "Error creating key directory") } + glog.Infof("Writing key to %s ...", keyPath) if err := lock.WriteFile(keyPath, keyBuffer.Bytes(), os.FileMode(0600)); err != nil { return errors.Wrap(err, "Error writing key file") }