diff --git a/cmd/kubeadm/app/cmd/phases/kubeconfig.go b/cmd/kubeadm/app/cmd/phases/kubeconfig.go index aa8a8428ed5..ad287301395 100644 --- a/cmd/kubeadm/app/cmd/phases/kubeconfig.go +++ b/cmd/kubeadm/app/cmd/phases/kubeconfig.go @@ -124,6 +124,7 @@ func getKubeConfigSubCommands(out io.Writer, outDir, defaultKubernetesVersion st cmd.Flags().StringVar(&cfg.CertificatesDir, "cert-dir", cfg.CertificatesDir, "The path where certificates are stored.") cmd.Flags().StringVar(&cfg.API.AdvertiseAddress, "apiserver-advertise-address", cfg.API.AdvertiseAddress, "The IP address or DNS name the API Server is accessible on.") cmd.Flags().Int32Var(&cfg.API.BindPort, "apiserver-bind-port", cfg.API.BindPort, "The port the API Server is accessible on.") + cmd.Flags().StringVar(&outDir, "kubeconfig-dir", outDir, "The path where to save and store the kubeconfig file.") if properties.use == "all" || properties.use == "kubelet" { cmd.Flags().StringVar(&cfg.NodeName, "node-name", cfg.NodeName, `The node name that the kubelet client cert should use.`) } diff --git a/cmd/kubeadm/app/cmd/phases/kubeconfig_test.go b/cmd/kubeadm/app/cmd/phases/kubeconfig_test.go index f3d86eff9bb..d3a4d93b0c0 100644 --- a/cmd/kubeadm/app/cmd/phases/kubeconfig_test.go +++ b/cmd/kubeadm/app/cmd/phases/kubeconfig_test.go @@ -44,6 +44,7 @@ func TestKubeConfigCSubCommandsHasFlags(t *testing.T) { "cert-dir", "apiserver-advertise-address", "apiserver-bind-port", + "kubeconfig-dir", } var tests = []struct { @@ -167,6 +168,8 @@ func TestKubeConfigSubCommandsThatCreateFilesWithFlags(t *testing.T) { // Adds a pki folder with a ca certs to the temp folder pkidir := testutil.SetupPkiDirWithCertificateAuthorithy(t, tmpdir) + outputdir := tmpdir + // Retrives ca cert for assertions caCert, _, err := pkiutil.TryLoadCertAndKeyFromDisk(pkidir, kubeadmconstants.CACertAndKeyBaseName) if err != nil { @@ -178,7 +181,9 @@ func TestKubeConfigSubCommandsThatCreateFilesWithFlags(t *testing.T) { // Execute the subcommand certDirFlag := fmt.Sprintf("--cert-dir=%s", pkidir) + outputDirFlag := fmt.Sprintf("--kubeconfig-dir=%s", outputdir) allFlags := append(commonFlags, certDirFlag) + allFlags = append(allFlags, outputDirFlag) allFlags = append(allFlags, test.additionalFlags...) cmdtestutil.RunSubCommand(t, subCmds, test.command, allFlags...) @@ -320,6 +325,8 @@ func TestKubeConfigSubCommandsThatWritesToOut(t *testing.T) { // Adds a pki folder with a ca cert to the temp folder pkidir := testutil.SetupPkiDirWithCertificateAuthorithy(t, tmpdir) + outputdir := tmpdir + // Retrives ca cert for assertions caCert, _, err := pkiutil.TryLoadCertAndKeyFromDisk(pkidir, kubeadmconstants.CACertAndKeyBaseName) if err != nil { @@ -331,6 +338,7 @@ func TestKubeConfigSubCommandsThatWritesToOut(t *testing.T) { "--apiserver-bind-port=1234", "--client-name=myUser", fmt.Sprintf("--cert-dir=%s", pkidir), + fmt.Sprintf("--kubeconfig-dir=%s", outputdir), } var tests = []struct {