Commit 5851fd55 authored by yuexiao-wang's avatar yuexiao-wang

kubeadm: print the join command should happen after all the phases in init have finished

parent 8307fb2f
...@@ -153,6 +153,9 @@ func NewCmdInit(out io.Writer) *cobra.Command { ...@@ -153,6 +153,9 @@ func NewCmdInit(out io.Writer) *cobra.Command {
// via the subcommands automatically created by initRunner.BindToCommand // via the subcommands automatically created by initRunner.BindToCommand
err = runInit(&data, out) err = runInit(&data, out)
kubeadmutil.CheckErr(err) kubeadmutil.CheckErr(err)
err = showJoinCommand(&data, out)
kubeadmutil.CheckErr(err)
}, },
} }
...@@ -397,6 +400,9 @@ func (d initData) KubeConfigDir() string { ...@@ -397,6 +400,9 @@ func (d initData) KubeConfigDir() string {
// KubeConfigPath returns the path to the kubeconfig file to use for connecting to Kubernetes // KubeConfigPath returns the path to the kubeconfig file to use for connecting to Kubernetes
func (d initData) KubeConfigPath() string { func (d initData) KubeConfigPath() string {
if d.dryRun {
d.kubeconfigPath = filepath.Join(d.dryRunDir, kubeadmconstants.AdminKubeConfigFileName)
}
return d.kubeconfigPath return d.kubeconfigPath
} }
...@@ -458,10 +464,9 @@ func (d initData) Tokens() []string { ...@@ -458,10 +464,9 @@ func (d initData) Tokens() []string {
// runInit executes master node provisioning // runInit executes master node provisioning
func runInit(i *initData, out io.Writer) error { func runInit(i *initData, out io.Writer) error {
// Get directories to write files to; can be faked if we're dry-running // Get directories to write files to; can be faked if we're dry-running
klog.V(1).Infof("[init] Getting certificates directory from configuration") klog.V(1).Infof("[init] Getting certificates directory from configuration")
certsDirToWriteTo, kubeConfigDir, _, _, err := getDirectoriesToUse(i.dryRun, i.dryRunDir, i.cfg.CertificatesDir) certsDirToWriteTo, _, _, _, err := getDirectoriesToUse(i.dryRun, i.dryRunDir, i.cfg.CertificatesDir)
if err != nil { if err != nil {
return errors.Wrap(err, "error getting directories to use") return errors.Wrap(err, "error getting directories to use")
} }
...@@ -469,8 +474,6 @@ func runInit(i *initData, out io.Writer) error { ...@@ -469,8 +474,6 @@ func runInit(i *initData, out io.Writer) error {
// certsDirToWriteTo is gonna equal cfg.CertificatesDir in the normal case, but gonna be a temp directory if dryrunning // certsDirToWriteTo is gonna equal cfg.CertificatesDir in the normal case, but gonna be a temp directory if dryrunning
i.cfg.CertificatesDir = certsDirToWriteTo i.cfg.CertificatesDir = certsDirToWriteTo
adminKubeConfigPath := filepath.Join(kubeConfigDir, kubeadmconstants.AdminKubeConfigFileName)
// TODO: client and waiter are temporary until the rest of the phases that use them // TODO: client and waiter are temporary until the rest of the phases that use them
// are removed from this function. // are removed from this function.
client, err := i.Client() client, err := i.Client()
...@@ -526,12 +529,6 @@ func runInit(i *initData, out io.Writer) error { ...@@ -526,12 +529,6 @@ func runInit(i *initData, out io.Writer) error {
return nil return nil
} }
// Prints the join command, multiple times in case the user has multiple tokens
for _, token := range i.Tokens() {
if err := printJoinCommand(out, adminKubeConfigPath, token, i.skipTokenPrint); err != nil {
return errors.Wrap(err, "failed to print join command")
}
}
return nil return nil
} }
...@@ -559,3 +556,17 @@ func getDirectoriesToUse(dryRun bool, dryRunDir string, defaultPkiDir string) (s ...@@ -559,3 +556,17 @@ func getDirectoriesToUse(dryRun bool, dryRunDir string, defaultPkiDir string) (s
return defaultPkiDir, kubeadmconstants.KubernetesDir, kubeadmconstants.GetStaticPodDirectory(), kubeadmconstants.KubeletRunDirectory, nil return defaultPkiDir, kubeadmconstants.KubernetesDir, kubeadmconstants.GetStaticPodDirectory(), kubeadmconstants.KubeletRunDirectory, nil
} }
// showJoinCommand prints the join command after all the phases in init have finished
func showJoinCommand(i *initData, out io.Writer) error {
adminKubeConfigPath := i.KubeConfigPath()
// Prints the join command, multiple times in case the user has multiple tokens
for _, token := range i.Tokens() {
if err := printJoinCommand(out, adminKubeConfigPath, token, i.skipTokenPrint); err != nil {
return errors.Wrap(err, "failed to print join command")
}
}
return nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment