Skip to content

Commit

Permalink
set LaunchTemplate as default value for default-scaling-configuration (
Browse files Browse the repository at this point in the history
…#387)

* feat: support overriding default scaling configuration (#385)

* make launchtemplates default

Signed-off-by: sbadiger <[email protected]>

* remove additional new lint

Signed-off-by: sbadiger <[email protected]>

* indentation

Signed-off-by: sbadiger <[email protected]>

* update default config type

Signed-off-by: sbadiger <[email protected]>

* update spec

Signed-off-by: sbadiger <[email protected]>

* refactor the default scaling config code

Signed-off-by: sbadiger <[email protected]>

* add unit tests

Signed-off-by: sbadiger <[email protected]>

* fix unit tests

Signed-off-by: sbadiger <[email protected]>

* indent

Signed-off-by: sbadiger <[email protected]>

* update defaultScalingConfiguration flag description

Signed-off-by: sbadiger <[email protected]>

---------

Signed-off-by: sbadiger <[email protected]>

* set LaunchTemplate as default value for default-scaling-configuration

Signed-off-by: sbadiger <[email protected]>

* validate scaling-config-override flag

Signed-off-by: sbadiger <[email protected]>

* chore(deps): Bump gopkg.in/yaml.v3 (#386)

Bumps gopkg.in/yaml.v3 from 3.0.0-20210107192922-496545a6307b to 3.0.0.

---
updated-dependencies:
- dependency-name: gopkg.in/yaml.v3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Todd Ekenstam <[email protected]>
Signed-off-by: sbadiger <[email protected]>

---------

Signed-off-by: sbadiger <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Todd Ekenstam <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2023
1 parent 6d3fc21 commit b5c6488
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
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

0 comments on commit b5c6488

Please sign in to comment.