k0sproject / k0sctl

A bootstrapping and management tool for k0s clusters.
Other
378 stars 77 forks source link

Modifiable action.Apply for when using k0sctl as a library #769

Closed kke closed 6 days ago

kke commented 6 days ago

A bit crudelly crammed-in way to make the apply action's (can be replicated fro other actions if needed) phase list modifiable.

Before:

applyAction := &action.Apply{
   Force: false
}
err := applyAction.Run()

After:

applyAction := action.NewApply(action.ApplyOpts: {
   Force: false
})
validateFacts := &phase.ValidateFacts{} 
applyAction.Phases.InsertAfter(validateFacts.Title(), &myCustomPhase{})
err := applyAction.Run()

This allows adding custom phases or modifying/removing existing ones to the apply action without duplicating the action code.

While creating this it became obvious that there's plenty of room for improvement in the way the phase manager / actions are set up.