【kubernetes/kubeadm】工作流的Phase数据结构

Phase即工作流中的阶段或步骤。创建一个Phase只需要实例化一个Phase struct类型的变量即可。

Phase定义了某个步骤及该步骤下所采取的动作。

Phase数结结构

Phase数据结构定义位于kubernetes\cmd\kubeadm\app\cmd\phases\workflow\phase.go

type Phase struct {
	Name string // phase的名字,同一个workflow下的phase或同一个父phase下的子phase名字也必须唯一

	Aliases []string // phase的别名,可以有多个

	Short string // phase的简短介绍

	Long string // phase的介绍

	Example string // 使用示例,类似于help信息

	Hidden bool // 该phase是否需要在工作流帮助信息中隐藏

	Phases []Phase // 子phase,有序排列

	// RunAllSiblings allows to assign to a phase the responsibility to
	// run all the sibling phases
	// Nb. phase marked as RunAllSiblings can not have Run functions
	RunAllSiblings bool

	Run func(data RunData) error // phase的回调函数

	RunIf func(data RunData) (bool, error) // 条件检测回调函数,在Run之前调用,决定是否要继续调用Run,如果RunIf返回(true,nil),那么Run将会被执行,否则不执行

	// InheritFlags defines the list of flags that the cobra command generated for this phase should Inherit
	// from local flags defined in the parent command / or additional flags defined in the phase runner.
	// If the values is not set or empty, no flags will be assigned to the command
	// Nb. global flags are automatically inherited by nested cobra command
	InheritFlags []string

	// LocalFlags defines the list of flags that should be assigned to the cobra command generated
	// for this phase.
	// Nb. if two or phases have the same local flags, please consider using local flags in the parent command
	// or additional flags defined in the phase runner.
	LocalFlags *pflag.FlagSet

	// ArgsValidator defines the positional arg function to be used for validating args for this phase
	// If not set a phase will adopt the args of the top level command.
	ArgsValidator cobra.PositionalArgs
}

对外方法

Phase只提供一个方法用于添加子Phase,这也意味着一旦创建它,其属性一般就不会修改,可以动态的添加子Phase

func (t *Phase) AppendPhase(phase Phase) {
	t.Phases = append(t.Phases, phase)
}

要点总结

phase可以包含子phase

通过phase的方法func (t *Phase) AppendPhase(phase Phase)可以把一个phase加入到另一个phase中,从而成为其子phase。

一个phase的子phase存放于Phase.Phases的切片中,而且是按照添加的顺序排列的,这也是子phase被执行的顺序。

一个phase的子phase在其父phase执行后会立即执行。

phase的名字需要唯一

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值