workflow

package
v0.0.0-...-bc8dc58 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Phase

type Phase struct {
	// name of the phase.
	// Phase name should be unique among peer phases (phases belonging to
	// the same workflow or phases belonging to the same parent phase).
	Name string

	// Aliases returns the aliases for the phase.
	Aliases []string

	// Short description of the phase.
	Short string

	// Long returns the long description of the phase.
	Long string

	// Example returns the example for the phase.
	Example string

	// Hidden define if the phase should be hidden in the workflow help.
	// e.g. PrintFilesIfDryRunning phase in the kubeadm init workflow is candidate for being hidden to the users
	Hidden bool

	// Phases defines a nested, ordered sequence of phases.
	Phases []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 defines a function implementing the phase action.
	// It is recommended to implent type assertion, e.g. using golang type switch,
	// for validating the RunData type.
	Run func(data RunData) error

	// RunIf define a function that implements a condition that should be checked
	// before executing the phase action.
	// If this function return nil, the phase action is always executed.
	RunIf func(data RunData) (bool, error)

	// 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 provides an implementation of a workflow phase that allows creation of new phases by simply instantiating a variable of this type.

func (*Phase) AppendPhase

func (t *Phase) AppendPhase(phase Phase)

AppendPhase adds the given phase to the nested, ordered sequence of phases.

type RunData

type RunData = interface{}

RunData defines the data shared among all the phases included in the workflow, that is any type.

type Runner

type Runner struct {
	// Options that regulate the runner behavior.
	Options RunnerOptions

	// Phases composing the workflow to be managed by the runner.
	Phases []Phase
	// contains filtered or unexported fields
}

Runner implements management of composable kubeadm workflows.

func NewRunner

func NewRunner() *Runner

NewRunner return a new runner for composable kubeadm workflows.

func (*Runner) AppendPhase

func (e *Runner) AppendPhase(t Phase)

AppendPhase adds the given phase to the ordered sequence of phases managed by the runner.

func (*Runner) BindToCommand

func (e *Runner) BindToCommand(cmd *cobra.Command)

BindToCommand bind the Runner to a cobra command by altering command help, adding phase related flags and by adding phases subcommands Please note that this command needs to be done once all the phases are added to the Runner.

func (*Runner) Help

func (e *Runner) Help(cmdUse string) string

Help returns text with the list of phases included in the workflow.

func (*Runner) InitData

func (e *Runner) InitData(args []string) (RunData, error)

InitData triggers the creation of runtime data shared among all the phases included in the workflow. This action can be executed explicitly out, when it is necessary to get the RunData before actually executing Run, or implicitly when invoking Run.

func (*Runner) Run

func (e *Runner) Run(args []string) error

Run the kubeadm composable kubeadm workflows.

func (*Runner) SetAdditionalFlags

func (e *Runner) SetAdditionalFlags(fn func(*pflag.FlagSet))

SetAdditionalFlags allows to define flags to be added to the subcommands generated for each phase (but not existing in the parent command). Please note that this command needs to be done before BindToCommand. Nb. if a flag is used only by one phase, please consider using phase LocalFlags.

func (*Runner) SetDataInitializer

func (e *Runner) SetDataInitializer(builder func(cmd *cobra.Command, args []string) (RunData, error))

SetDataInitializer allows to setup a function that initialize the runtime data shared among all the phases included in the workflow. The method will receive in input the cmd that triggers the Runner (only if the runner is BindToCommand)

type RunnerOptions

type RunnerOptions struct {
	// FilterPhases defines the list of phases to be executed (if empty, all).
	FilterPhases []string

	// SkipPhases defines the list of phases to be excluded by execution (if empty, none).
	SkipPhases []string
}

RunnerOptions defines the options supported during the execution of a kubeadm composable workflows

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL