Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set LaunchTemplate as default value for default-scaling-configuration #387

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/v1alpha1/instancegroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
35 changes: 26 additions & 9 deletions api/v1alpha1/instancegroup_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -485,15 +488,17 @@ func TestScalingConfigOverride(t *testing.T) {
scalingConfigurationOverride: &launchconfiguration,
},
},
want: LaunchConfiguration,
want: LaunchConfiguration,
expectedError: false,
},
{
name: "no default overrides",
args: args{
instancegroup: MockInstanceGroup("eks", "managed", MockEKSSpec(), nil, basicFargateSpec()),
overrides: &ValidationOverrides{},
},
want: LaunchTemplate,
want: LaunchTemplate,
expectedError: false,
},
{
name: "override default to launchtemplate",
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
Loading