Skip to content

Commit

Permalink
Update node name for k3s,rke2,kubeadm
Browse files Browse the repository at this point in the history
  • Loading branch information
innobead committed Jun 21, 2022
1 parent 5b7f6c0 commit 5ab8cc8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
6 changes: 4 additions & 2 deletions pkg/bootstrap/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (k *K3sBootstrapper) bootstrap(node *data.Node, isSingleNode bool, extraOpt
defer sshClient.Close()

deployCmdOpts := []string{
fmt.Sprintf(`--node-name=%s`, node.Status.IPAddresses),
fmt.Sprintf(`--node-name="%s"`, node.Name),
}
tokenBuf := bytes.Buffer{}

Expand Down Expand Up @@ -187,7 +187,9 @@ func (k *K3sBootstrapper) join(node *data.Node, apiServerAddress string, joinTok
}
defer sshClient.Close()

var deployCmdOpts []string
deployCmdOpts := []string{
fmt.Sprintf(`--node-name="%s"`, node.Name),
}
cmd := fmt.Sprintf(
"%s K3S_URL=https://%s:6443 K3S_TOKEN=%s k3s-install.sh",
config.K3sVersionsEnvVars(node.Spec.Cluster.Version).String(),
Expand Down
14 changes: 3 additions & 11 deletions pkg/bootstrap/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,11 @@ func (k *KubeadmBootstrapper) bootstrap(node *data.Node, isSingleNode bool, opti
}{
{
cmdline: fmt.Sprintf(
`kubeadm init phase control-plane all -v 5 --apiserver-extra-args="%s" --controller-manager-extra-args="%s" --scheduler-extra-args="%s"`,
`kubeadm init -v 5 --node-name="%s" --apiserver-extra-args="%s" --controller-manager-extra-args="%s" --scheduler-extra-args="%s" --ignore-preflight-errors='%s' %s`,
node.Name,
strings.Join(options.generateControlPlaneComponentOptions(&options.ApiServerOptions), ","),
strings.Join(options.generateControlPlaneComponentOptions(&options.ControllerManagerOptions), ","),
strings.Join(options.generateControlPlaneComponentOptions(&options.SchedulerOptions), ","),
),
before: func(session *ssh.Session) bool {
logrus.Info("running kubeadm init")
return true
},
},
{
cmdline: fmt.Sprintf(
"kubeadm init -v 5 --skip-phases='control-plane' --ignore-preflight-errors='%s' %s",
strings.Join(ignoreErrors, ","),
strings.Join(options.generateKubeadmInitOptions(), " "),
),
Expand Down Expand Up @@ -331,7 +323,7 @@ func (k *KubeadmBootstrapper) join(node *data.Node, joinCmd string) error {

logrus.Infof("running join command (%s)", joinCmd)

if err := sshClient.Run(nil, nil, fmt.Sprintf("%s -v 5", joinCmd)); err != nil {
if err := sshClient.Run(nil, nil, fmt.Sprintf(`%s -v 5 --node-name="%s"`, joinCmd, node.Name)); err != nil {
return errors.WithStack(err)
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/bootstrap/rke2.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (r *RKE2Bootstrapper) bootstrap(node *data.Node, isSingleNode bool, extraOp

joinToken := util.GenerateRandomStr(8)
deployCmdOpts := []string{
fmt.Sprintf(`--node-name="%s"`, node.Name),
fmt.Sprintf("--bind-address=%s", node.Status.IPAddresses),
fmt.Sprintf("--token=%s", joinToken),
}
Expand Down Expand Up @@ -195,6 +196,7 @@ func (r *RKE2Bootstrapper) join(node *data.Node, apiServerAddress string, joinTo
defer sshClient.Close()

deployCmdOpts := []string{
fmt.Sprintf(`--node-name="%s"`, node.Name),
fmt.Sprintf("--server=https://%s:9345", apiServerAddress),
fmt.Sprintf("--token=%s", joinToken),
}
Expand Down

0 comments on commit 5ab8cc8

Please sign in to comment.