phaseRunner
// phaseRunner provides a wrapper to a Phase with the addition of a set
// of contextual information derived by the workflow managed by the Runner.
// TODO: If we ever decide to get more sophisticated we can swap this type with a well defined dag or tree library.
type phaseRunner struct {
Phase
parent *phaseRunner // 父phaseRunner
level int // phase在工作流中的层级
// selfPath contains all the elements of the path that identify the phase into
// the workflow managed by the Runner.
selfPath []string
generatedName string // phase包含各级phase的全名
use string // 使用帮助信息,相当于工作流中的相对路径
}
Runner
type RunnerOptions struct {
FilterPhases []string // 需要执行的phase列表,如果列表为空,则全部执行
SkipPhases []string // 需要屏蔽的phase,如果列表为空,则不屏蔽
}
// Runner implements management of composable kubeadm workflows.
type Runner struct {
Options RunnerOptions // Runner执行选项
Phases []Phase // Runner管理的工作流中所有的phase
runDataInitializer func(*cobra.Command, []string) (RunData, error) // 构造工作流中所有phase共享数据的回调函数
runData RunData // 工作流中所有phase共享的数据
runCmd *cobra.Command // 触发Runner的命令
// cmdAdditionalFlags holds additional, shared flags that could be added to the subcommands generated
// for phases. Flags could be inherited from the parent command too or added directly to each phase
cmdAdditionalFlags *pflag.FlagSet
phaseRunners []*phaseRunner // 工作流的上下文信息
}
Runner对外方法
创建Runner
工作流workflow
包对外提供一个创建空Runner的方法NewRunner()
,该空Runner实际上也是一个空的工作流,它不包括任何phase
,后续可以使用添加phase
的接口来增加phase
。
func NewRunner() *Runner {
return &Runner{
Phases: []Phase{},
}
}
加入phase
当工作流创建完成后,就可以使用func (e *Runner) AppendPhase(t Phase)
接口来添加phase
了。
func (e *Runner) AppendPhase(t Phase) {
e.Phases = append(e.Phases, t)
}
此时添加phase,只是简单的把phase追加到runner的切片列表中,phase的执行顺序与加入顺序一致。