溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

kubernetes及kubeadm工作流的Phase數(shù)據(jù)結(jié)構(gòu)是怎樣的

發(fā)布時間:2021-12-20 10:10:02 來源:億速云 閱讀:168 作者:柒染 欄目:云計算

kubernetes及kubeadm工作流的Phase數(shù)據(jù)結(jié)構(gòu)是怎樣的,針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

Phase即工作流中的階段或步驟。創(chuàng)建一個Phase只需要實例化一個Phase struct類型的變量即可。

Phase定義了某個步驟及該步驟下所采取的動作。

Phase數(shù)結(jié)結(jié)構(gòu)

Phase數(shù)據(jù)結(jié)構(gòu)定義位于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的回調(diào)函數(shù)

	RunIf func(data RunData) (bool, error) // 條件檢測回調(diào)函數(shù),在Run之前調(diào)用,決定是否要繼續(xù)調(diào)用Run,如果RunIf返回(true,nil),那么Run將會被執(zhí)行,否則不執(zhí)行

	// 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,這也意味著一旦創(chuàng)建它,其屬性一般就不會修改,可以動態(tài)的添加子Phase。

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

要點總結(jié)

phase可以包含子phase

通過phase的方法func (t *Phase) AppendPhase(phase Phase)可以把一個phase加入到另一個phase中,從而成為其子phase。

一個phase的子phase存放于Phase.Phases的切片中,而且是按照添加的順序排列的,這也是子phase被執(zhí)行的順序。

一個phase的子phase在其父phase執(zhí)行后會立即執(zhí)行。

關(guān)于kubernetes及kubeadm工作流的Phase數(shù)據(jù)結(jié)構(gòu)是怎樣的問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI