Skip to content

Commit

Permalink
OCM-3366 | fix: force --enable-autoscaling flag when autoscaling flag…
Browse files Browse the repository at this point in the history
…s are used
  • Loading branch information
davidleerh authored and ciaranRoche committed Oct 12, 2023
1 parent f9fa8a1 commit 2700910
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/create/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ var args struct {
}

var autoscalerArgs *clusterautoscaler.AutoscalerArgs
var userSpecifiedAutoscalerValues []*pflag.Flag

var Cmd = &cobra.Command{
Use: "cluster",
Expand Down Expand Up @@ -513,10 +514,10 @@ func init() {
)

autoscalerArgs = clusterautoscaler.AddClusterAutoscalerFlags(Cmd, clusterAutoscalerFlagsPrefix)

// iterates through all autoscaling flags and stores them in slice to track user input
flags.VisitAll(func(f *pflag.Flag) {
if strings.HasPrefix(f.Name, clusterAutoscalerFlagsPrefix) {
Cmd.MarkFlagsRequiredTogether("enable-autoscaling", f.Name)
userSpecifiedAutoscalerValues = append(userSpecifiedAutoscalerValues, f)
}
})

Expand Down Expand Up @@ -776,6 +777,14 @@ func run(cmd *cobra.Command, _ []string) {
os.Exit(1)
}

for _, val := range userSpecifiedAutoscalerValues {
if val.Changed && !args.autoscalingEnabled {
r.Reporter.Errorf("Using autoscaling flag '%s', requires flag '--enable-autoscaling'. "+
"Please try again with flag", val.Name)
os.Exit(1)
}
}

// validate flags for cluster admin
isHostedCP := args.hostedClusterEnabled
clusterAdminUser := strings.Trim(args.clusterAdminUser, " \t")
Expand Down

0 comments on commit 2700910

Please sign in to comment.