Skip to content

Commit

Permalink
Merge pull request #2220 from will4j/feature/scripts-role
Browse files Browse the repository at this point in the history
feat: add CustomScripts.Role property
  • Loading branch information
ks-ci-bot committed May 10, 2024
2 parents 86b4551 + fa35428 commit 093003e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/kk/apis/kubekey/v1alpha2/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type KubeVip struct {
type CustomScripts struct {
Name string `yaml:"name" json:"name,omitempty"`
Bash string `yaml:"bash" json:"bash,omitempty"`
Role string `yaml:"role" json:"role,omitempty"`
Materials []string `yaml:"materials" json:"materials,omitempty"`
}

Expand Down
11 changes: 10 additions & 1 deletion cmd/kk/pkg/bootstrap/customscripts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"

kubekeyapiv1alpha2 "github.com/kubesphere/kubekey/v3/cmd/kk/apis/kubekey/v1alpha2"
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/connector"
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/module"
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/task"
)
Expand All @@ -38,10 +39,18 @@ func (m *CustomScriptsModule) Init() {

taskName := fmt.Sprintf("Phase:%s(%d/%d) script:%s", m.Phase, idx, len(m.Scripts), script.Name)
taskDir := fmt.Sprintf("%s-%d-script", m.Phase, idx)

var hosts []connector.Host
if len(script.Role) > 0 {
hosts = m.Runtime.GetHostsByRole(script.Role)
} else {
hosts = m.Runtime.GetAllHosts()
}

task := &task.RemoteTask{
Name: taskName,
Desc: taskName,
Hosts: m.Runtime.GetAllHosts(),
Hosts: hosts,
Action: &CustomScriptTask{taskDir: taskDir, script: script},
Parallel: true,
Retry: 1,
Expand Down

0 comments on commit 093003e

Please sign in to comment.