Skip to content

Commit 4c27d6a

Browse files
cleanup-join-phases
1 parent 83fc13e commit 4c27d6a

File tree

6 files changed

+31
-41
lines changed

6 files changed

+31
-41
lines changed

cmd/kubeadm/app/cmd/join.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ type joinData struct {
140140
skipTokenPrint bool
141141
initCfg *kubeadmapi.InitConfiguration
142142
tlsBootstrapCfg *clientcmdapi.Config
143-
clientSets map[string]*clientset.Clientset
143+
clientSet *clientset.Clientset
144144
ignorePreflightErrors sets.String
145145
outputWriter io.Writer
146146
certificateKey string
@@ -178,7 +178,7 @@ func NewCmdJoin(out io.Writer, joinOptions *joinOptions) *cobra.Command {
178178
}
179179

180180
ctx := map[string]string{
181-
"KubeConfigPath": data.KubeConfigPath(),
181+
"KubeConfigPath": kubeadmconstants.GetAdminKubeConfigPath(),
182182
"etcdMessage": etcdMessage,
183183
}
184184
joinControPlaneDoneTemp.Execute(data.outputWriter, ctx)
@@ -385,7 +385,6 @@ func newJoinData(cmd *cobra.Command, args []string, options *joinOptions, out io
385385

386386
return &joinData{
387387
cfg: cfg,
388-
clientSets: map[string]*clientset.Clientset{},
389388
ignorePreflightErrors: ignorePreflightErrorsSet,
390389
outputWriter: out,
391390
certificateKey: options.certificateKey,
@@ -402,11 +401,6 @@ func (j *joinData) Cfg() *kubeadmapi.JoinConfiguration {
402401
return j.cfg
403402
}
404403

405-
// KubeConfigPath returns the default kubeconfig path.
406-
func (j *joinData) KubeConfigPath() string {
407-
return kubeadmconstants.GetAdminKubeConfigPath()
408-
}
409-
410404
// TLSBootstrapCfg returns the cluster-info (kubeconfig).
411405
func (j *joinData) TLSBootstrapCfg() (*clientcmdapi.Config, error) {
412406
if j.tlsBootstrapCfg != nil {
@@ -432,15 +426,17 @@ func (j *joinData) InitCfg() (*kubeadmapi.InitConfiguration, error) {
432426
return initCfg, err
433427
}
434428

435-
func (j *joinData) ClientSetFromFile(path string) (*clientset.Clientset, error) {
436-
if client, ok := j.clientSets[path]; ok {
437-
return client, nil
429+
// ClientSet returns the ClientSet for accessing the cluster with the identity defined in admin.conf.
430+
func (j *joinData) ClientSet() (*clientset.Clientset, error) {
431+
if j.clientSet != nil {
432+
return j.clientSet, nil
438433
}
434+
path := kubeadmconstants.GetAdminKubeConfigPath()
439435
client, err := kubeconfigutil.ClientSetFromFile(path)
440436
if err != nil {
441437
return nil, errors.Wrap(err, "[join] couldn't create Kubernetes client")
442438
}
443-
j.clientSets[path] = client
439+
j.clientSet = client
444440
return client, nil
445441
}
446442

cmd/kubeadm/app/cmd/phases/join/checketcd.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
"github.com/pkg/errors"
2323
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
24-
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
2524
etcdphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/etcd"
2625
)
2726

@@ -61,7 +60,7 @@ func runCheckEtcdPhase(c workflow.RunData) error {
6160
// Checks that the etcd cluster is healthy
6261
// NB. this check cannot be implemented before because it requires the admin.conf and all the certificates
6362
// for connecting to etcd already in place
64-
client, err := data.ClientSetFromFile(kubeadmconstants.GetAdminKubeConfigPath())
63+
client, err := data.ClientSet()
6564
if err != nil {
6665
return err
6766
}

cmd/kubeadm/app/cmd/phases/join/controlplanejoin.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ func runEtcdPhase(c workflow.RunData) error {
109109
return nil
110110
}
111111

112-
kubeConfigFile := data.KubeConfigPath()
113-
114-
client, err := data.ClientSetFromFile(kubeConfigFile)
112+
// gets access to the cluster using the identity defined in admin.conf
113+
client, err := data.ClientSet()
115114
if err != nil {
116115
return errors.Wrap(err, "couldn't create Kubernetes client")
117116
}
@@ -151,9 +150,8 @@ func runUploadConfigPhase(c workflow.RunData) error {
151150
return nil
152151
}
153152

154-
kubeConfigFile := data.KubeConfigPath()
155-
156-
client, err := data.ClientSetFromFile(kubeConfigFile)
153+
// gets access to the cluster using the identity defined in admin.conf
154+
client, err := data.ClientSet()
157155
if err != nil {
158156
return errors.Wrap(err, "couldn't create Kubernetes client")
159157
}
@@ -179,9 +177,8 @@ func runMarkControlPlanePhase(c workflow.RunData) error {
179177
return nil
180178
}
181179

182-
kubeConfigFile := data.KubeConfigPath()
183-
184-
client, err := data.ClientSetFromFile(kubeConfigFile)
180+
// gets access to the cluster using the identity defined in admin.conf
181+
client, err := data.ClientSet()
185182
if err != nil {
186183
return errors.Wrap(err, "couldn't create Kubernetes client")
187184
}

cmd/kubeadm/app/cmd/phases/join/data.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ import (
3030
type JoinData interface {
3131
CertificateKey() string
3232
Cfg() *kubeadmapi.JoinConfiguration
33-
KubeConfigPath() string
3433
TLSBootstrapCfg() (*clientcmdapi.Config, error)
3534
InitCfg() (*kubeadmapi.InitConfiguration, error)
36-
ClientSetFromFile(path string) (*clientset.Clientset, error)
35+
ClientSet() (*clientset.Clientset, error)
3736
IgnorePreflightErrors() sets.String
3837
OutputWriter() io.Writer
3938
}

cmd/kubeadm/app/cmd/phases/join/data_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ type testJoinData struct{}
3131
// testJoinData must satisfy JoinData.
3232
var _ JoinData = &testJoinData{}
3333

34-
func (j *testJoinData) CertificateKey() string { return "" }
35-
func (j *testJoinData) Cfg() *kubeadmapi.JoinConfiguration { return nil }
36-
func (j *testJoinData) KubeConfigPath() string { return "" }
37-
func (j *testJoinData) TLSBootstrapCfg() (*clientcmdapi.Config, error) { return nil, nil }
38-
func (j *testJoinData) InitCfg() (*kubeadmapi.InitConfiguration, error) { return nil, nil }
39-
func (j *testJoinData) ClientSetFromFile(path string) (*clientset.Clientset, error) { return nil, nil }
40-
func (j *testJoinData) IgnorePreflightErrors() sets.String { return nil }
41-
func (j *testJoinData) OutputWriter() io.Writer { return nil }
34+
func (j *testJoinData) CertificateKey() string { return "" }
35+
func (j *testJoinData) Cfg() *kubeadmapi.JoinConfiguration { return nil }
36+
func (j *testJoinData) TLSBootstrapCfg() (*clientcmdapi.Config, error) { return nil, nil }
37+
func (j *testJoinData) InitCfg() (*kubeadmapi.InitConfiguration, error) { return nil, nil }
38+
func (j *testJoinData) ClientSet() (*clientset.Clientset, error) { return nil, nil }
39+
func (j *testJoinData) IgnorePreflightErrors() sets.String { return nil }
40+
func (j *testJoinData) OutputWriter() io.Writer { return nil }

cmd/kubeadm/app/cmd/phases/join/kubelet.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,28 @@ func NewKubeletStartPhase() workflow.Phase {
7373
}
7474
}
7575

76-
func getKubeletStartJoinData(c workflow.RunData) (JoinData, *kubeadmapi.JoinConfiguration, *kubeadmapi.InitConfiguration, *clientcmdapi.Config, error) {
76+
func getKubeletStartJoinData(c workflow.RunData) (*kubeadmapi.JoinConfiguration, *kubeadmapi.InitConfiguration, *clientcmdapi.Config, error) {
7777
data, ok := c.(JoinData)
7878
if !ok {
79-
return nil, nil, nil, nil, errors.New("kubelet-start phase invoked with an invalid data struct")
79+
return nil, nil, nil, errors.New("kubelet-start phase invoked with an invalid data struct")
8080
}
8181
cfg := data.Cfg()
8282
initCfg, err := data.InitCfg()
8383
if err != nil {
84-
return nil, nil, nil, nil, err
84+
return nil, nil, nil, err
8585
}
8686
tlsBootstrapCfg, err := data.TLSBootstrapCfg()
8787
if err != nil {
88-
return nil, nil, nil, nil, err
88+
return nil, nil, nil, err
8989
}
90-
return data, cfg, initCfg, tlsBootstrapCfg, nil
90+
return cfg, initCfg, tlsBootstrapCfg, nil
9191
}
9292

9393
// runKubeletStartJoinPhase executes the kubelet TLS bootstrap process.
9494
// This process is executed by the kubelet and completes with the node joining the cluster
9595
// with a dedicates set of credentials as required by the node authorizer
9696
func runKubeletStartJoinPhase(c workflow.RunData) error {
97-
data, cfg, initCfg, tlsBootstrapCfg, err := getKubeletStartJoinData(c)
97+
cfg, initCfg, tlsBootstrapCfg, err := getKubeletStartJoinData(c)
9898
if err != nil {
9999
return err
100100
}
@@ -119,7 +119,7 @@ func runKubeletStartJoinPhase(c workflow.RunData) error {
119119
return err
120120
}
121121

122-
bootstrapClient, err := data.ClientSetFromFile(bootstrapKubeConfigFile)
122+
bootstrapClient, err := kubeconfigutil.ClientSetFromFile(bootstrapKubeConfigFile)
123123
if err != nil {
124124
return errors.Errorf("couldn't create client from kubeconfig file %q", bootstrapKubeConfigFile)
125125
}
@@ -156,7 +156,7 @@ func runKubeletStartJoinPhase(c workflow.RunData) error {
156156
}
157157

158158
// When we know the /etc/kubernetes/kubelet.conf file is available, get the client
159-
client, err := data.ClientSetFromFile(kubeadmconstants.GetKubeletKubeConfigPath())
159+
client, err := kubeconfigutil.ClientSetFromFile(kubeadmconstants.GetKubeletKubeConfigPath())
160160
if err != nil {
161161
return err
162162
}

0 commit comments

Comments
 (0)