Skip to content

Commit

Permalink
Merge pull request #80867 from fabriziopandini/fix-certs-generation-f…
Browse files Browse the repository at this point in the history
…or-external-etcd

kubeadm: fix-certs-generation-for-external-etcd
  • Loading branch information
k8s-ci-robot committed Aug 3, 2019
2 parents 3639196 + 59fb766 commit 44f3aaf
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions cmd/kubeadm/app/cmd/phases/init/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ func runCAPhase(ca *certsphase.KubeadmCert) func(c workflow.RunData) error {
return errors.New("certs phase invoked with an invalid data struct")
}

// if using external etcd, skips etcd certificate authority generation
if data.Cfg().Etcd.External != nil && ca.Name == "etcd-ca" {
fmt.Printf("[certs] External etcd mode: Skipping %s certificate authority generation\n", ca.BaseName)
return nil
}

if _, err := pkiutil.TryLoadCertFromDisk(data.CertificateDir(), ca.BaseName); err == nil {
if _, err := pkiutil.TryLoadKeyFromDisk(data.CertificateDir(), ca.BaseName); err == nil {
fmt.Printf("[certs] Using existing %s certificate authority\n", ca.BaseName)
Expand All @@ -227,12 +233,6 @@ func runCAPhase(ca *certsphase.KubeadmCert) func(c workflow.RunData) error {
return nil
}

// if using external etcd, skips etcd certificate authority generation
if data.Cfg().Etcd.External != nil && ca.Name == "etcd-ca" {
fmt.Printf("[certs] External etcd mode: Skipping %s certificate authority generation\n", ca.BaseName)
return nil
}

// if dryrunning, write certificates authority to a temporary folder (and defer restore to the path originally specified by the user)
cfg := data.Cfg()
cfg.CertificatesDir = data.CertificateWriteDir()
Expand All @@ -250,6 +250,12 @@ func runCertPhase(cert *certsphase.KubeadmCert, caCert *certsphase.KubeadmCert)
return errors.New("certs phase invoked with an invalid data struct")
}

// if using external etcd, skips etcd certificates generation
if data.Cfg().Etcd.External != nil && cert.CAName == "etcd-ca" {
fmt.Printf("[certs] External etcd mode: Skipping %s certificate generation\n", cert.BaseName)
return nil
}

if certData, _, err := pkiutil.TryLoadCertAndKeyFromDisk(data.CertificateDir(), cert.BaseName); err == nil {
caCertData, err := pkiutil.TryLoadCertFromDisk(data.CertificateDir(), caCert.BaseName)
if err != nil {
Expand All @@ -273,12 +279,6 @@ func runCertPhase(cert *certsphase.KubeadmCert, caCert *certsphase.KubeadmCert)
return certsphase.CreateCSR(cert, data.Cfg(), csrDir)
}

// if using external etcd, skips etcd certificates generation
if data.Cfg().Etcd.External != nil && cert.CAName == "etcd-ca" {
fmt.Printf("[certs] External etcd mode: Skipping %s certificate authority generation\n", cert.BaseName)
return nil
}

// if dryrunning, write certificates to a temporary folder (and defer restore to the path originally specified by the user)
cfg := data.Cfg()
cfg.CertificatesDir = data.CertificateWriteDir()
Expand Down

0 comments on commit 44f3aaf

Please sign in to comment.