【kubernetes/kubeadm】工作流之Runner数据结构

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的执行顺序与加入顺序一致。

转载于:https://my.oschina.net/renhc/blog/3062010

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值