Repository: keikoproj/instance-manager
Pull request #387 (2023-09-12 18:17:00)

set LaunchTemplate as default value for default-scaling-configuration
PR https://github.com/keikoproj/instance-manager/pull/385 changed the ASG default from LaunchConfigurations to LaunchTemplates. 

There was a small mistake, where the `default-scaling-configuration` flag name was accidentally left empty.

This PR will fix the naming and also provide a default value.


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/keikoproj/instance-manager/pull/387?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj) Report
> Merging [#387](https://app.codecov.io/gh/keikoproj/instance-manager/pull/387?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj) (f8b363a) into [master](https://app.codecov.io/gh/keikoproj/instance-manager/commit/d1e5113d8db8ebfc022ac1f7e59c884ab7912433?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj) (d1e5113) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master     #387   +/-   ##
=======================================
  Coverage   51.43%   51.43%           
=======================================
  Files          33       33           
  Lines        4571     4571           
=======================================
  Hits         2351     2351           
  Misses       2075     2075           
  Partials      145      145           
```



:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=keikoproj)


Patch:
diff --git a/api/v1alpha1/instancegroup_types.go b/api/v1alpha1/instancegroup_types.go
index b011921..2419a00 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/main.go b/main.go
index caa606d..f85fbaf 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)))
 


Test patch:
diff --git a/api/v1alpha1/instancegroup_types_test.go b/api/v1alpha1/instancegroup_types_test.go
index 8021b6f..1eee8c0 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)