Skip to content

Commit b4894dc

Browse files
committed
add opt-in field for disabling instance refresh
1 parent ad99a1d commit b4894dc

File tree

6 files changed

+52
-15
lines changed

6 files changed

+52
-15
lines changed

cmd/clusterawsadm/credentials/credentials.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
// AWSCredentialsTemplate generates an AWS credentials file that can
3232
// be loaded by the various SDKs.
33+
//
3334
//nolint:gosec
3435
const AWSCredentialsTemplate = `[default]
3536
aws_access_key_id = {{ .AccessKeyID }}

config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachinepools.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,11 @@ spec:
789789
description: RefreshPreferences describes set of preferences associated
790790
with the instance refresh request.
791791
properties:
792+
disable:
793+
description: Disable, if true, disables instance refresh from
794+
triggering when new launch templates are detected. This is useful
795+
in scenarios where ASG nodes are externally managed.
796+
type: boolean
792797
instanceWarmup:
793798
description: The number of seconds until a newly launched instance
794799
is configured and ready to use. During this time, the next replacement

exp/api/v1beta1/conversion.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,22 @@ func (src *AWSMachinePool) ConvertTo(dstRaw conversion.Hub) error {
4141
if restored.Spec.SuspendProcesses != nil {
4242
dst.Spec.SuspendProcesses = restored.Spec.SuspendProcesses
4343
}
44+
if dst.Spec.RefreshPreferences != nil && restored.Spec.RefreshPreferences != nil {
45+
dst.Spec.RefreshPreferences.Disable = restored.Spec.RefreshPreferences.Disable
46+
}
4447

4548
return nil
4649
}
4750

4851
// ConvertFrom converts the v1beta2 AWSMachinePool receiver to v1beta1 AWSMachinePool.
49-
func (r *AWSMachinePool) ConvertFrom(srcRaw conversion.Hub) error {
52+
func (dst *AWSMachinePool) ConvertFrom(srcRaw conversion.Hub) error {
5053
src := srcRaw.(*infrav1exp.AWSMachinePool)
5154

52-
if err := Convert_v1beta2_AWSMachinePool_To_v1beta1_AWSMachinePool(src, r, nil); err != nil {
55+
if err := Convert_v1beta2_AWSMachinePool_To_v1beta1_AWSMachinePool(src, dst, nil); err != nil {
5356
return err
5457
}
5558

56-
return utilconversion.MarshalData(src, r)
59+
return utilconversion.MarshalData(src, dst)
5760
}
5861

5962
// ConvertTo converts the v1beta1 AWSMachinePoolList receiver to a v1beta2 AWSMachinePoolList.
@@ -175,3 +178,9 @@ func Convert_v1beta2_AutoScalingGroup_To_v1beta1_AutoScalingGroup(in *infrav1exp
175178
// explicitly ignore CurrentlySuspended.
176179
return autoConvert_v1beta2_AutoScalingGroup_To_v1beta1_AutoScalingGroup(in, out, s)
177180
}
181+
182+
// Convert_v1beta2_RefreshPreferences_To_v1beta1_RefreshPreferences converts the v1beta2 RefreshPreferences receiver to a v1beta1 RefreshPreferences.
183+
func Convert_v1beta2_RefreshPreferences_To_v1beta1_RefreshPreferences(in *infrav1exp.RefreshPreferences, out *RefreshPreferences, s apiconversion.Scope) error {
184+
// spec.refreshPreferences.disable has been added to v1beta2.
185+
return autoConvert_v1beta2_RefreshPreferences_To_v1beta1_RefreshPreferences(in, out, s)
186+
}

exp/api/v1beta1/zz_generated.conversion.go

Lines changed: 24 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exp/api/v1beta2/awsmachinepool_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ func (s *SuspendProcessesTypes) ConvertSetValuesToStringSlice() []string {
139139

140140
// RefreshPreferences defines the specs for instance refreshing.
141141
type RefreshPreferences struct {
142+
// Disable, if true, disables instance refresh from triggering when new launch templates are detected.
143+
// This is useful in scenarios where ASG nodes are externally managed.
144+
// +optional
145+
Disable bool `json:"disable,omitempty"`
146+
142147
// The strategy to use for the instance refresh. The only valid value is Rolling.
143148
// A rolling update is an update that is applied to all instances in an Auto
144149
// Scaling group until all instances have been updated.

exp/controllers/awsmachinepool_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ func (r *AWSMachinePoolReconciler) reconcileNormal(ctx context.Context, machineP
232232
return asgsvc.CanStartASGInstanceRefresh(machinePoolScope)
233233
}
234234
runPostLaunchTemplateUpdateOperation := func() error {
235+
// skip instance refresh if explicitly disabled
236+
if machinePoolScope.AWSMachinePool.Spec.RefreshPreferences != nil && machinePoolScope.AWSMachinePool.Spec.RefreshPreferences.Disable {
237+
machinePoolScope.V(4).Info("instance refresh disabled, skipping instance refresh")
238+
return nil
239+
}
235240
// After creating a new version of launch template, instance refresh is required
236241
// to trigger a rolling replacement of all previously launched instances.
237242
// If ONLY the userdata changed, previously launched instances continue to use the old launch

0 commit comments

Comments
 (0)