Skip to content

Commit

Permalink
Merge pull request #1832 from pixiake/custom-domain
Browse files Browse the repository at this point in the history
fix: Add worker label according to host role
  • Loading branch information
ks-ci-bot authored May 9, 2023
2 parents d42e1d2 + 45ea7d5 commit 2ce24ff
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 57 deletions.
15 changes: 0 additions & 15 deletions cmd/kk/pkg/k3s/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,28 +195,13 @@ func (i *InitClusterModule) Init() {
Retry: 5,
}

addWorkerLabel := &task.RemoteTask{
Name: "AddWorkerLabel",
Desc: "Add worker label",
Hosts: i.Runtime.GetHostsByRole(common.Master),
Prepare: &prepare.PrepareCollection{
new(common.OnlyFirstMaster),
&ClusterIsExist{Not: true},
new(common.IsWorker),
},
Action: new(AddWorkerLabel),
Parallel: true,
Retry: 5,
}

i.Tasks = []task.Interface{
k3sService,
k3sEnv,
k3sRegistryConfig,
enableK3s,
copyKubeConfig,
addMasterTaint,
addWorkerLabel,
}
}

Expand Down
13 changes: 9 additions & 4 deletions cmd/kk/pkg/k3s/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,16 @@ type AddWorkerLabel struct {
}

func (a *AddWorkerLabel) Execute(runtime connector.Runtime) error {
if _, err := runtime.GetRunner().SudoCmd(
"/usr/local/bin/kubectl label nodes --selector='!node-role.kubernetes.io/worker' node-role.kubernetes.io/worker=",
true); err != nil {
return errors.Wrap(errors.WithStack(err), "add worker label failed")
for _, host := range runtime.GetAllHosts() {
if host.IsRole(common.Worker) {
if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf(
"/usr/local/bin/kubectl label --overwrite node %s node-role.kubernetes.io/worker=",
host.GetName()), true); err != nil {
return errors.Wrap(errors.WithStack(err), "add worker label failed")
}
}
}

return nil
}

Expand Down
15 changes: 0 additions & 15 deletions cmd/kk/pkg/k8e/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,27 +182,12 @@ func (i *InitClusterModule) Init() {
Retry: 5,
}

addWorkerLabel := &task.RemoteTask{
Name: "AddWorkerLabel",
Desc: "Add worker label",
Hosts: i.Runtime.GetHostsByRole(common.Master),
Prepare: &prepare.PrepareCollection{
new(common.OnlyFirstMaster),
&ClusterIsExist{Not: true},
new(common.IsWorker),
},
Action: new(AddWorkerLabel),
Parallel: true,
Retry: 5,
}

i.Tasks = []task.Interface{
k8eService,
k8eEnv,
enableK8e,
copyKubeConfig,
addMasterTaint,
addWorkerLabel,
}
}

Expand Down
13 changes: 9 additions & 4 deletions cmd/kk/pkg/k8e/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,16 @@ type AddWorkerLabel struct {
}

func (a *AddWorkerLabel) Execute(runtime connector.Runtime) error {
if _, err := runtime.GetRunner().SudoCmd(
"/usr/local/bin/kubectl label nodes --selector='!node-role.kubernetes.io/worker' node-role.kubernetes.io/worker=",
true); err != nil {
return errors.Wrap(errors.WithStack(err), "add worker label failed")
for _, host := range runtime.GetAllHosts() {
if host.IsRole(common.Worker) {
if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf(
"/usr/local/bin/kubectl label --overwrite node %s node-role.kubernetes.io/worker=",
host.GetName()), true); err != nil {
return errors.Wrap(errors.WithStack(err), "add worker label failed")
}
}
}

return nil
}

Expand Down
15 changes: 0 additions & 15 deletions cmd/kk/pkg/kubernetes/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,26 +188,11 @@ func (i *InitKubernetesModule) Init() {
Retry: 5,
}

addWorkerLabel := &task.RemoteTask{
Name: "AddWorkerLabel",
Desc: "Add worker label",
Hosts: i.Runtime.GetHostsByRole(common.Master),
Prepare: &prepare.PrepareCollection{
new(common.OnlyFirstMaster),
&ClusterIsExist{Not: true},
new(common.IsWorker),
},
Action: new(AddWorkerLabel),
Parallel: true,
Retry: 5,
}

i.Tasks = []task.Interface{
generateKubeadmConfig,
kubeadmInit,
copyKubeConfig,
removeMasterTaint,
addWorkerLabel,
}
}

Expand Down
13 changes: 9 additions & 4 deletions cmd/kk/pkg/kubernetes/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,16 @@ type AddWorkerLabel struct {
}

func (a *AddWorkerLabel) Execute(runtime connector.Runtime) error {
if _, err := runtime.GetRunner().SudoCmd(
"/usr/local/bin/kubectl label nodes --selector='!node-role.kubernetes.io/worker' node-role.kubernetes.io/worker=",
true); err != nil {
return errors.Wrap(errors.WithStack(err), "add worker label failed")
for _, host := range runtime.GetAllHosts() {
if host.IsRole(common.Worker) {
if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf(
"/usr/local/bin/kubectl label --overwrite node %s node-role.kubernetes.io/worker=",
host.GetName()), true); err != nil {
return errors.Wrap(errors.WithStack(err), "add worker label failed")
}
}
}

return nil
}

Expand Down

0 comments on commit 2ce24ff

Please sign in to comment.