diff --git a/api/v1alpha1/instancegroup_types.go b/api/v1alpha1/instancegroup_types.go index b011921b..2419a000 100644 --- a/api/v1alpha1/instancegroup_types.go +++ b/api/v1alpha1/instancegroup_types.go @@ -430,6 +430,9 @@ func (s *EKSSpec) Validate(overrides *ValidationOverrides) error { if s.Type != LaunchConfiguration && s.Type != LaunchTemplate { s.Type = LaunchTemplate if overrides.scalingConfigurationOverride != nil { + if *overrides.scalingConfigurationOverride != LaunchTemplate && *overrides.scalingConfigurationOverride != LaunchConfiguration { + return errors.Errorf("validation failed, 'scaling-configuration-override' has invalid value: %v ", *overrides.scalingConfigurationOverride) + } s.Type = *overrides.scalingConfigurationOverride } } diff --git a/api/v1alpha1/instancegroup_types_test.go b/api/v1alpha1/instancegroup_types_test.go index 8021b6f3..1eee8c05 100644 --- a/api/v1alpha1/instancegroup_types_test.go +++ b/api/v1alpha1/instancegroup_types_test.go @@ -461,6 +461,8 @@ func TestInstanceGroupSpecValidate(t *testing.T) { func TestScalingConfigOverride(t *testing.T) { launchconfiguration := LaunchConfiguration launchtemplate := LaunchTemplate + var invalidScalingConfigType ScalingConfigurationType = "invalid-scaling-config-type" + type args struct { instancegroup *InstanceGroup overrides *ValidationOverrides @@ -473,9 +475,10 @@ func TestScalingConfigOverride(t *testing.T) { return testCase.Run(t) } tests := []struct { - name string - args args - want ScalingConfigurationType + name string + args args + want ScalingConfigurationType + expectedError bool }{ { name: "override default to launchconfig instead of launchtemplate", @@ -485,7 +488,8 @@ func TestScalingConfigOverride(t *testing.T) { scalingConfigurationOverride: &launchconfiguration, }, }, - want: LaunchConfiguration, + want: LaunchConfiguration, + expectedError: false, }, { name: "no default overrides", @@ -493,7 +497,8 @@ func TestScalingConfigOverride(t *testing.T) { instancegroup: MockInstanceGroup("eks", "managed", MockEKSSpec(), nil, basicFargateSpec()), overrides: &ValidationOverrides{}, }, - want: LaunchTemplate, + want: LaunchTemplate, + expectedError: false, }, { name: "override default to launchtemplate", @@ -503,15 +508,27 @@ func TestScalingConfigOverride(t *testing.T) { scalingConfigurationOverride: &launchtemplate, }, }, - want: LaunchTemplate, + want: LaunchTemplate, + expectedError: false, + }, + { + name: "override default to an invalid scaling config type", + args: args{ + instancegroup: MockInstanceGroup("eks", "managed", MockEKSSpec(), nil, basicFargateSpec()), + overrides: &ValidationOverrides{ + scalingConfigurationOverride: &invalidScalingConfigType, + }, + }, + want: LaunchTemplate, + expectedError: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { err := testFunction(t, tt.args) - if err != "" { - t.Errorf("error:%v", err) - } + if (!tt.expectedError && err != "") || (tt.expectedError && err == "") { + t.Errorf("%v: got: %v, expectedError: %v", tt.name, err, tt.expectedError) + } got := tt.args.instancegroup.Spec.EKSSpec.Type if got != tt.want { t.Errorf("%v: got %v, want %v", tt.name, got, tt.want) diff --git a/main.go b/main.go index caa606db..f85fbaf8 100644 --- a/main.go +++ b/main.go @@ -88,8 +88,7 @@ func main() { "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.") flag.BoolVar(&nodeRelabel, "node-relabel", true, "relabel nodes as they join with kubernetes.io/role label via controller") flag.BoolVar(&disableWinClusterInjection, "disable-windows-cluster-ca-injection", false, "Setting this to true will cause the ClusterCA and Endpoint to not be injected for Windows nodes") - flag.StringVar(&defaultScalingConfiguration, "", string(instancemgrv1alpha1.LaunchTemplate), "By default ASGs will have LaunchTemplate. Set this string to either 'LaunchConfiguration' or 'LaunchTemplate' to enforce defaults.") - + flag.StringVar(&defaultScalingConfiguration, "default-scaling-configuration", "LaunchTemplate", "By default ASGs will have LaunchTemplate. Set this string to either 'LaunchConfiguration' or 'LaunchTemplate' to enforce defaults.") flag.Parse() ctrl.SetLogger(zap.New(zap.UseDevMode(true)))