Merge pull request #75224 from neolit123/certs-print-key-on-phase

kubeadm: print key inside the upload-certs phase of init
pull/564/head
Kubernetes Prow Robot 2019-03-11 12:00:15 -07:00 committed by GitHub
commit 50bf223a05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 3 deletions

View File

@ -379,6 +379,11 @@ func (d *initData) SetCertificateKey(key string) {
d.certificateKey = key
}
// SkipCertificateKeyPrint returns the skipCertificateKeyPrint flag.
func (d *initData) SkipCertificateKeyPrint() bool {
return d.skipCertificateKeyPrint
}
// Cfg returns initConfiguration.
func (d *initData) Cfg() *kubeadmapi.InitConfiguration {
return d.cfg

View File

@ -30,6 +30,7 @@ type InitData interface {
UploadCerts() bool
CertificateKey() string
SetCertificateKey(key string)
SkipCertificateKeyPrint() bool
Cfg() *kubeadmapi.InitConfiguration
DryRun() bool
SkipTokenPrint() bool

View File

@ -33,6 +33,7 @@ var _ InitData = &testInitData{}
func (t *testInitData) UploadCerts() bool { return false }
func (t *testInitData) CertificateKey() string { return "" }
func (t *testInitData) SetCertificateKey(key string) {}
func (t *testInitData) SkipCertificateKeyPrint() bool { return false }
func (t *testInitData) Cfg() *kubeadmapi.InitConfiguration { return nil }
func (t *testInitData) DryRun() bool { return false }
func (t *testInitData) SkipTokenPrint() bool { return false }

View File

@ -21,7 +21,6 @@ import (
"github.com/pkg/errors"
"k8s.io/klog"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
@ -40,6 +39,7 @@ func NewUploadCertsPhase() workflow.Phase {
options.CfgPath,
options.UploadCerts,
options.CertificateKey,
options.SkipCertificateKeyPrint,
},
}
}
@ -51,7 +51,7 @@ func runUploadCerts(c workflow.RunData) error {
}
if !data.UploadCerts() {
klog.V(1).Infoln("[upload-certs] Skipping certs upload")
fmt.Printf("[upload-certs] Skipping phase. Please see --%s\n", options.UploadCerts)
return nil
}
client, err := data.Client()
@ -70,5 +70,8 @@ func runUploadCerts(c workflow.RunData) error {
if err := copycerts.UploadCerts(client, data.Cfg(), data.CertificateKey()); err != nil {
return errors.Wrap(err, "error uploading certs")
}
if !data.SkipCertificateKeyPrint() {
fmt.Printf("[upload-certs] Using certificate key:\n%s\n", data.CertificateKey())
}
return nil
}

View File

@ -85,7 +85,7 @@ func CreateCertificateKey() (string, error) {
//UploadCerts save certs needs to join a new control-plane on kubeadm-certs sercret.
func UploadCerts(client clientset.Interface, cfg *kubeadmapi.InitConfiguration, key string) error {
fmt.Printf("[upload-certs] storing the certificates in ConfigMap %q in the %q Namespace\n", kubeadmconstants.KubeadmCertsSecret, metav1.NamespaceSystem)
fmt.Printf("[upload-certs] Storing the certificates in ConfigMap %q in the %q Namespace\n", kubeadmconstants.KubeadmCertsSecret, metav1.NamespaceSystem)
decodedKey, err := hex.DecodeString(key)
if err != nil {
return err