kubekey/pkg/core/module/task_module.go
24sama be2947ff9b dev-v2.0.0: fix import cycle
Signed-off-by: 24sama <leo@kubesphere.io>
2021-11-01 18:15:33 +08:00

45 lines
1003 B
Go

package module
import (
"github.com/kubesphere/kubekey/pkg/core/connector"
"github.com/kubesphere/kubekey/pkg/core/ending"
"github.com/kubesphere/kubekey/pkg/core/logger"
"github.com/pkg/errors"
)
type BaseTaskModule struct {
BaseModule
Tasks []Task
}
func (b *BaseTaskModule) Init() {
if b.Name == "" {
b.Name = DefaultTaskModuleName
}
}
func (b *BaseTaskModule) Is() string {
return TaskModuleType
}
func (b *BaseTaskModule) Run(result *ending.ModuleResult) {
for i := range b.Tasks {
task := b.Tasks[i]
task.Init(b.Runtime.(connector.Runtime), b.ModuleCache, b.PipelineCache)
logger.Log.Infof("[%s] %s", b.Name, task.GetDesc())
res := task.Execute()
for j := range res.ActionResults {
ac := res.ActionResults[j]
logger.Log.Infof("%s: [%s]", ac.Status.String(), ac.Host.GetName())
result.AppendHostResult(ac)
}
if res.IsFailed() {
result.ErrResult(errors.Wrapf(res.CombineErr(), "Module[%s] exec failed", b.Name))
return
}
}
result.NormalResult()
}