diff --git a/cmd/kubeadm/app/cmd/join.go b/cmd/kubeadm/app/cmd/join.go index 8376245e74..0fd87015ed 100644 --- a/cmd/kubeadm/app/cmd/join.go +++ b/cmd/kubeadm/app/cmd/join.go @@ -140,7 +140,7 @@ type joinData struct { skipTokenPrint bool initCfg *kubeadmapi.InitConfiguration tlsBootstrapCfg *clientcmdapi.Config - clientSets map[string]*clientset.Clientset + clientSet *clientset.Clientset ignorePreflightErrors sets.String outputWriter io.Writer certificateKey string @@ -178,7 +178,7 @@ func NewCmdJoin(out io.Writer, joinOptions *joinOptions) *cobra.Command { } ctx := map[string]string{ - "KubeConfigPath": data.KubeConfigPath(), + "KubeConfigPath": kubeadmconstants.GetAdminKubeConfigPath(), "etcdMessage": etcdMessage, } joinControPlaneDoneTemp.Execute(data.outputWriter, ctx) @@ -385,7 +385,6 @@ func newJoinData(cmd *cobra.Command, args []string, options *joinOptions, out io return &joinData{ cfg: cfg, - clientSets: map[string]*clientset.Clientset{}, ignorePreflightErrors: ignorePreflightErrorsSet, outputWriter: out, certificateKey: options.certificateKey, @@ -402,11 +401,6 @@ func (j *joinData) Cfg() *kubeadmapi.JoinConfiguration { return j.cfg } -// KubeConfigPath returns the default kubeconfig path. -func (j *joinData) KubeConfigPath() string { - return kubeadmconstants.GetAdminKubeConfigPath() -} - // TLSBootstrapCfg returns the cluster-info (kubeconfig). func (j *joinData) TLSBootstrapCfg() (*clientcmdapi.Config, error) { if j.tlsBootstrapCfg != nil { @@ -432,15 +426,17 @@ func (j *joinData) InitCfg() (*kubeadmapi.InitConfiguration, error) { return initCfg, err } -func (j *joinData) ClientSetFromFile(path string) (*clientset.Clientset, error) { - if client, ok := j.clientSets[path]; ok { - return client, nil +// ClientSet returns the ClientSet for accessing the cluster with the identity defined in admin.conf. +func (j *joinData) ClientSet() (*clientset.Clientset, error) { + if j.clientSet != nil { + return j.clientSet, nil } + path := kubeadmconstants.GetAdminKubeConfigPath() client, err := kubeconfigutil.ClientSetFromFile(path) if err != nil { return nil, errors.Wrap(err, "[join] couldn't create Kubernetes client") } - j.clientSets[path] = client + j.clientSet = client return client, nil } diff --git a/cmd/kubeadm/app/cmd/phases/join/checketcd.go b/cmd/kubeadm/app/cmd/phases/join/checketcd.go index ec3153dccb..98156ec70f 100644 --- a/cmd/kubeadm/app/cmd/phases/join/checketcd.go +++ b/cmd/kubeadm/app/cmd/phases/join/checketcd.go @@ -21,7 +21,6 @@ import ( "github.com/pkg/errors" "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow" - kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants" etcdphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/etcd" ) @@ -61,7 +60,7 @@ func runCheckEtcdPhase(c workflow.RunData) error { // Checks that the etcd cluster is healthy // NB. this check cannot be implemented before because it requires the admin.conf and all the certificates // for connecting to etcd already in place - client, err := data.ClientSetFromFile(kubeadmconstants.GetAdminKubeConfigPath()) + client, err := data.ClientSet() if err != nil { return err } diff --git a/cmd/kubeadm/app/cmd/phases/join/controlplanejoin.go b/cmd/kubeadm/app/cmd/phases/join/controlplanejoin.go index 11b5fe734b..50a52e6f9b 100644 --- a/cmd/kubeadm/app/cmd/phases/join/controlplanejoin.go +++ b/cmd/kubeadm/app/cmd/phases/join/controlplanejoin.go @@ -111,9 +111,8 @@ func runEtcdPhase(c workflow.RunData) error { return nil } - kubeConfigFile := data.KubeConfigPath() - - client, err := data.ClientSetFromFile(kubeConfigFile) + // gets access to the cluster using the identity defined in admin.conf + client, err := data.ClientSet() if err != nil { return errors.Wrap(err, "couldn't create Kubernetes client") } @@ -153,9 +152,8 @@ func runUploadConfigPhase(c workflow.RunData) error { return nil } - kubeConfigFile := data.KubeConfigPath() - - client, err := data.ClientSetFromFile(kubeConfigFile) + // gets access to the cluster using the identity defined in admin.conf + client, err := data.ClientSet() if err != nil { return errors.Wrap(err, "couldn't create Kubernetes client") } @@ -181,9 +179,8 @@ func runMarkControlPlanePhase(c workflow.RunData) error { return nil } - kubeConfigFile := data.KubeConfigPath() - - client, err := data.ClientSetFromFile(kubeConfigFile) + // gets access to the cluster using the identity defined in admin.conf + client, err := data.ClientSet() if err != nil { return errors.Wrap(err, "couldn't create Kubernetes client") } diff --git a/cmd/kubeadm/app/cmd/phases/join/data.go b/cmd/kubeadm/app/cmd/phases/join/data.go index 617dea2b00..2a3309964e 100644 --- a/cmd/kubeadm/app/cmd/phases/join/data.go +++ b/cmd/kubeadm/app/cmd/phases/join/data.go @@ -30,10 +30,9 @@ import ( type JoinData interface { CertificateKey() string Cfg() *kubeadmapi.JoinConfiguration - KubeConfigPath() string TLSBootstrapCfg() (*clientcmdapi.Config, error) InitCfg() (*kubeadmapi.InitConfiguration, error) - ClientSetFromFile(path string) (*clientset.Clientset, error) + ClientSet() (*clientset.Clientset, error) IgnorePreflightErrors() sets.String OutputWriter() io.Writer } diff --git a/cmd/kubeadm/app/cmd/phases/join/data_test.go b/cmd/kubeadm/app/cmd/phases/join/data_test.go index ee10d91186..18955f12dd 100644 --- a/cmd/kubeadm/app/cmd/phases/join/data_test.go +++ b/cmd/kubeadm/app/cmd/phases/join/data_test.go @@ -31,11 +31,10 @@ type testJoinData struct{} // testJoinData must satisfy JoinData. var _ JoinData = &testJoinData{} -func (j *testJoinData) CertificateKey() string { return "" } -func (j *testJoinData) Cfg() *kubeadmapi.JoinConfiguration { return nil } -func (j *testJoinData) KubeConfigPath() string { return "" } -func (j *testJoinData) TLSBootstrapCfg() (*clientcmdapi.Config, error) { return nil, nil } -func (j *testJoinData) InitCfg() (*kubeadmapi.InitConfiguration, error) { return nil, nil } -func (j *testJoinData) ClientSetFromFile(path string) (*clientset.Clientset, error) { return nil, nil } -func (j *testJoinData) IgnorePreflightErrors() sets.String { return nil } -func (j *testJoinData) OutputWriter() io.Writer { return nil } +func (j *testJoinData) CertificateKey() string { return "" } +func (j *testJoinData) Cfg() *kubeadmapi.JoinConfiguration { return nil } +func (j *testJoinData) TLSBootstrapCfg() (*clientcmdapi.Config, error) { return nil, nil } +func (j *testJoinData) InitCfg() (*kubeadmapi.InitConfiguration, error) { return nil, nil } +func (j *testJoinData) ClientSet() (*clientset.Clientset, error) { return nil, nil } +func (j *testJoinData) IgnorePreflightErrors() sets.String { return nil } +func (j *testJoinData) OutputWriter() io.Writer { return nil } diff --git a/cmd/kubeadm/app/cmd/phases/join/kubelet.go b/cmd/kubeadm/app/cmd/phases/join/kubelet.go index 46163969ae..fc7c690309 100644 --- a/cmd/kubeadm/app/cmd/phases/join/kubelet.go +++ b/cmd/kubeadm/app/cmd/phases/join/kubelet.go @@ -74,28 +74,28 @@ func NewKubeletStartPhase() workflow.Phase { } } -func getKubeletStartJoinData(c workflow.RunData) (JoinData, *kubeadmapi.JoinConfiguration, *kubeadmapi.InitConfiguration, *clientcmdapi.Config, error) { +func getKubeletStartJoinData(c workflow.RunData) (*kubeadmapi.JoinConfiguration, *kubeadmapi.InitConfiguration, *clientcmdapi.Config, error) { data, ok := c.(JoinData) if !ok { - return nil, nil, nil, nil, errors.New("kubelet-start phase invoked with an invalid data struct") + return nil, nil, nil, errors.New("kubelet-start phase invoked with an invalid data struct") } cfg := data.Cfg() initCfg, err := data.InitCfg() if err != nil { - return nil, nil, nil, nil, err + return nil, nil, nil, err } tlsBootstrapCfg, err := data.TLSBootstrapCfg() if err != nil { - return nil, nil, nil, nil, err + return nil, nil, nil, err } - return data, cfg, initCfg, tlsBootstrapCfg, nil + return cfg, initCfg, tlsBootstrapCfg, nil } // runKubeletStartJoinPhase executes the kubelet TLS bootstrap process. // This process is executed by the kubelet and completes with the node joining the cluster // with a dedicates set of credentials as required by the node authorizer func runKubeletStartJoinPhase(c workflow.RunData) error { - data, cfg, initCfg, tlsBootstrapCfg, err := getKubeletStartJoinData(c) + cfg, initCfg, tlsBootstrapCfg, err := getKubeletStartJoinData(c) if err != nil { return err } @@ -120,7 +120,7 @@ func runKubeletStartJoinPhase(c workflow.RunData) error { return err } - bootstrapClient, err := data.ClientSetFromFile(bootstrapKubeConfigFile) + bootstrapClient, err := kubeconfigutil.ClientSetFromFile(bootstrapKubeConfigFile) if err != nil { return errors.Errorf("couldn't create client from kubeconfig file %q", bootstrapKubeConfigFile) } @@ -157,7 +157,7 @@ func runKubeletStartJoinPhase(c workflow.RunData) error { } // When we know the /etc/kubernetes/kubelet.conf file is available, get the client - client, err := data.ClientSetFromFile(kubeadmconstants.GetKubeletKubeConfigPath()) + client, err := kubeconfigutil.ClientSetFromFile(kubeadmconstants.GetKubeletKubeConfigPath()) if err != nil { return err }