Skip to content

Commit 7c783fa

Browse files
committed
kubeadm: make the CP join handling of kubeconfig similar to "init"
The kubeconfig phase of "kubeadm init" detects external CA mode and skips the generation of kubeconfig files. The kubeconfig handling during control-plane join executes CreateJoinControlPlaneKubeConfigFiles() which requires the presence of ca.key when preparing the spec of a kubeconfig file and prevents usage of external CA mode. Modify CreateJoinControlPlaneKubeConfigFiles() to skip generating the kubeconfig files if external CA mode is detected.
1 parent 05b77fe commit 7c783fa

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

cmd/kubeadm/app/phases/kubeconfig/kubeconfig.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,31 @@ type kubeConfigSpec struct {
6767
// CreateJoinControlPlaneKubeConfigFiles will create and write to disk the kubeconfig files required by kubeadm
6868
// join --control-plane workflow, plus the admin kubeconfig file used by the administrator and kubeadm itself; the
6969
// kubelet.conf file must not be created because it will be created and signed by the kubelet TLS bootstrap process.
70-
// If any kubeconfig files already exists, it used only if evaluated equal; otherwise an error is returned.
70+
// When not using external CA mode, if a kubeconfig file already exists it is used only if evaluated equal,
71+
// otherwise an error is returned. For external CA mode, the creation of kubeconfig files is skipped.
7172
func CreateJoinControlPlaneKubeConfigFiles(outDir string, cfg *kubeadmapi.InitConfiguration) error {
72-
return createKubeConfigFiles(
73-
outDir,
74-
cfg,
73+
var externaCA bool
74+
caKeyPath := filepath.Join(cfg.CertificatesDir, kubeadmconstants.CAKeyName)
75+
if _, err := os.Stat(caKeyPath); os.IsNotExist(err) {
76+
externaCA = true
77+
}
78+
79+
files := []string{
7580
kubeadmconstants.AdminKubeConfigFileName,
7681
kubeadmconstants.ControllerManagerKubeConfigFileName,
7782
kubeadmconstants.SchedulerKubeConfigFileName,
78-
)
83+
}
84+
85+
for _, file := range files {
86+
if externaCA {
87+
fmt.Printf("[kubeconfig] External CA mode: Using user provided %s\n", file)
88+
continue
89+
}
90+
if err := createKubeConfigFiles(outDir, cfg, file); err != nil {
91+
return err
92+
}
93+
}
94+
return nil
7995
}
8096

8197
// CreateKubeConfigFile creates a kubeconfig file.

0 commit comments

Comments
 (0)