Skip to content

Commit

Permalink
Better highlight usage of skipPhases for devs
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Weiße <[email protected]>
  • Loading branch information
daniel-weisse committed Oct 26, 2023
1 parent cff5ad7 commit a7cee10
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions cli/internal/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import (
k8serrors "k8s.io/apimachinery/pkg/api/errors"
)

// phases that can be skipped during apply.
// New phases should also be added to [formatSkipPhases].
const (
// skipInfrastructurePhase skips the Terraform apply of the apply process.
skipInfrastructurePhase skipPhase = "infrastructure"
Expand All @@ -57,6 +59,19 @@ const (
skipK8sPhase skipPhase = "k8s"
)

// formatSkipPhases returns a formatted string of all phases that can be skipped.
func formatSkipPhases() string {
return fmt.Sprintf("{ %s }", strings.Join([]string{
string(skipInfrastructurePhase),
string(skipInitPhase),
string(skipAttestationConfigPhase),
string(skipCertSANsPhase),
string(skipHelmPhase),
string(skipImagePhase),
string(skipK8sPhase),
}, " | "))
}

// skipPhase is a phase of the upgrade process that can be skipped.
type skipPhase string

Expand All @@ -79,18 +94,6 @@ func (s *skipPhases) add(phases ...skipPhase) {
}
}

func printAllPhases() string {
return fmt.Sprintf("{ %s }", strings.Join([]string{
string(skipInfrastructurePhase),
string(skipInitPhase),
string(skipAttestationConfigPhase),
string(skipCertSANsPhase),
string(skipHelmPhase),
string(skipImagePhase),
string(skipK8sPhase),
}, " | "))
}

// NewApplyCmd creates the apply command.
func NewApplyCmd() *cobra.Command {
cmd := &cobra.Command{
Expand All @@ -109,7 +112,7 @@ func NewApplyCmd() *cobra.Command {
cmd.Flags().Duration("timeout", 5*time.Minute, "change helm upgrade timeout\n"+
"Might be useful for slow connections or big clusters.")
cmd.Flags().StringSlice("skip-phases", nil, "comma-separated list of upgrade phases to skip\n"+
fmt.Sprintf("one or multiple of %s", printAllPhases()))
fmt.Sprintf("one or multiple of %s", formatSkipPhases()))

must(cmd.Flags().MarkHidden("timeout"))

Expand Down

0 comments on commit a7cee10

Please sign in to comment.