Skip to content

Commit ff8cb13

Browse files
authored
✨ Add DefaultInstanceWarmup field to AWSMachineDeployment spec (#4760)
* Add `DefaultInstanceWarmup` field to `AWSMachineDeployment` spec * remove field from v1beta1
1 parent 9dfa0a3 commit ff8cb13

File tree

9 files changed

+57
-28
lines changed

9 files changed

+57
-28
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,12 @@ spec:
785785
completes before another scaling activity can start. If no value
786786
is supplied by user a default value of 300 seconds is set
787787
type: string
788+
defaultInstanceWarmup:
789+
description: The amount of time, in seconds, until a new instance
790+
is considered to have finished initializing and resource consumption
791+
to become stable after it enters the InService state. If no value
792+
is supplied by user a default value of 300 seconds is set
793+
type: string
788794
maxSize:
789795
default: 1
790796
description: MaxSize defines the maximum size of the group.

exp/api/v1beta1/conversion.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ package v1beta1
1818

1919
import (
2020
apiconversion "k8s.io/apimachinery/pkg/conversion"
21+
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
22+
"sigs.k8s.io/controller-runtime/pkg/conversion"
23+
2124
infrav1beta1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta1"
2225
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2326
infrav1exp "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
24-
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
25-
"sigs.k8s.io/controller-runtime/pkg/conversion"
2627
)
2728

2829
// ConvertTo converts the v1beta1 AWSMachinePool receiver to a v1beta2 AWSMachinePool.
@@ -55,6 +56,8 @@ func (src *AWSMachinePool) ConvertTo(dstRaw conversion.Hub) error {
5556
dst.Spec.AWSLaunchTemplate.PrivateDNSName = restored.Spec.AWSLaunchTemplate.PrivateDNSName
5657
}
5758

59+
dst.Spec.DefaultInstanceWarmup = restored.Spec.DefaultInstanceWarmup
60+
5861
return nil
5962
}
6063

exp/api/v1beta1/zz_generated.conversion.go

Lines changed: 2 additions & 0 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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ type AWSMachinePoolSpec struct {
8383
// +optional
8484
DefaultCoolDown metav1.Duration `json:"defaultCoolDown,omitempty"`
8585

86+
// The amount of time, in seconds, until a new instance is considered to
87+
// have finished initializing and resource consumption to become stable
88+
// after it enters the InService state.
89+
// If no value is supplied by user a default value of 300 seconds is set
90+
// +optional
91+
DefaultInstanceWarmup metav1.Duration `json:"defaultInstanceWarmup,omitempty"`
92+
8693
// RefreshPreferences describes set of preferences associated with the instance refresh request.
8794
// +optional
8895
RefreshPreferences *RefreshPreferences `json:"refreshPreferences,omitempty"`

exp/api/v1beta2/awsmachinepool_webhook.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,9 @@ func (r *AWSMachinePool) Default() {
172172
log.Info("DefaultCoolDown is zero, setting 300 seconds as default")
173173
r.Spec.DefaultCoolDown.Duration = 300 * time.Second
174174
}
175+
176+
if int(r.Spec.DefaultInstanceWarmup.Duration.Seconds()) == 0 {
177+
log.Info("DefaultInstanceWarmup is zero, setting 300 seconds as default")
178+
r.Spec.DefaultInstanceWarmup.Duration = 300 * time.Second
179+
}
175180
}

exp/api/v1beta2/types.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,17 @@ type Tags map[string]string
199199
// AutoScalingGroup describes an AWS autoscaling group.
200200
type AutoScalingGroup struct {
201201
// The tags associated with the instance.
202-
ID string `json:"id,omitempty"`
203-
Tags infrav1.Tags `json:"tags,omitempty"`
204-
Name string `json:"name,omitempty"`
205-
DesiredCapacity *int32 `json:"desiredCapacity,omitempty"`
206-
MaxSize int32 `json:"maxSize,omitempty"`
207-
MinSize int32 `json:"minSize,omitempty"`
208-
PlacementGroup string `json:"placementGroup,omitempty"`
209-
Subnets []string `json:"subnets,omitempty"`
210-
DefaultCoolDown metav1.Duration `json:"defaultCoolDown,omitempty"`
211-
CapacityRebalance bool `json:"capacityRebalance,omitempty"`
202+
ID string `json:"id,omitempty"`
203+
Tags infrav1.Tags `json:"tags,omitempty"`
204+
Name string `json:"name,omitempty"`
205+
DesiredCapacity *int32 `json:"desiredCapacity,omitempty"`
206+
MaxSize int32 `json:"maxSize,omitempty"`
207+
MinSize int32 `json:"minSize,omitempty"`
208+
PlacementGroup string `json:"placementGroup,omitempty"`
209+
Subnets []string `json:"subnets,omitempty"`
210+
DefaultCoolDown metav1.Duration `json:"defaultCoolDown,omitempty"`
211+
DefaultInstanceWarmup metav1.Duration `json:"defaultInstanceWarmup,omitempty"`
212+
CapacityRebalance bool `json:"capacityRebalance,omitempty"`
212213

213214
MixedInstancesPolicy *MixedInstancesPolicy `json:"mixedInstancesPolicy,omitempty"`
214215
Status ASGStatus

exp/api/v1beta2/zz_generated.deepcopy.go

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

pkg/cloud/services/autoscaling/autoscalinggroup.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,14 @@ func (s *Service) CreateASG(machinePoolScope *scope.MachinePoolScope) (*expinfra
162162
}
163163

164164
input := &expinfrav1.AutoScalingGroup{
165-
Name: machinePoolScope.Name(),
166-
MaxSize: machinePoolScope.AWSMachinePool.Spec.MaxSize,
167-
MinSize: machinePoolScope.AWSMachinePool.Spec.MinSize,
168-
Subnets: subnets,
169-
DefaultCoolDown: machinePoolScope.AWSMachinePool.Spec.DefaultCoolDown,
170-
CapacityRebalance: machinePoolScope.AWSMachinePool.Spec.CapacityRebalance,
171-
MixedInstancesPolicy: machinePoolScope.AWSMachinePool.Spec.MixedInstancesPolicy,
165+
Name: machinePoolScope.Name(),
166+
MaxSize: machinePoolScope.AWSMachinePool.Spec.MaxSize,
167+
MinSize: machinePoolScope.AWSMachinePool.Spec.MinSize,
168+
Subnets: subnets,
169+
DefaultCoolDown: machinePoolScope.AWSMachinePool.Spec.DefaultCoolDown,
170+
DefaultInstanceWarmup: machinePoolScope.AWSMachinePool.Spec.DefaultInstanceWarmup,
171+
CapacityRebalance: machinePoolScope.AWSMachinePool.Spec.CapacityRebalance,
172+
MixedInstancesPolicy: machinePoolScope.AWSMachinePool.Spec.MixedInstancesPolicy,
172173
}
173174

174175
// Default value of MachinePool replicas set by CAPI is 1.
@@ -216,12 +217,13 @@ func (s *Service) CreateASG(machinePoolScope *scope.MachinePoolScope) (*expinfra
216217

217218
func (s *Service) runPool(i *expinfrav1.AutoScalingGroup, launchTemplateID string) error {
218219
input := &autoscaling.CreateAutoScalingGroupInput{
219-
AutoScalingGroupName: aws.String(i.Name),
220-
MaxSize: aws.Int64(int64(i.MaxSize)),
221-
MinSize: aws.Int64(int64(i.MinSize)),
222-
VPCZoneIdentifier: aws.String(strings.Join(i.Subnets, ", ")),
223-
DefaultCooldown: aws.Int64(int64(i.DefaultCoolDown.Duration.Seconds())),
224-
CapacityRebalance: aws.Bool(i.CapacityRebalance),
220+
AutoScalingGroupName: aws.String(i.Name),
221+
MaxSize: aws.Int64(int64(i.MaxSize)),
222+
MinSize: aws.Int64(int64(i.MinSize)),
223+
VPCZoneIdentifier: aws.String(strings.Join(i.Subnets, ", ")),
224+
DefaultCooldown: aws.Int64(int64(i.DefaultCoolDown.Duration.Seconds())),
225+
DefaultInstanceWarmup: aws.Int64(int64(i.DefaultInstanceWarmup.Duration.Seconds())),
226+
CapacityRebalance: aws.Bool(i.CapacityRebalance),
225227
}
226228

227229
if i.DesiredCapacity != nil {

pkg/cloud/services/autoscaling/autoscalinggroup_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,10 @@ func TestServiceCreateASG(t *testing.T) {
488488
wantASG: false,
489489
expect: func(m *mock_autoscalingiface.MockAutoScalingAPIMockRecorder) {
490490
expected := &autoscaling.CreateAutoScalingGroupInput{
491-
AutoScalingGroupName: aws.String("create-asg-success"),
492-
CapacityRebalance: aws.Bool(false),
493-
DefaultCooldown: aws.Int64(0),
491+
AutoScalingGroupName: aws.String("create-asg-success"),
492+
CapacityRebalance: aws.Bool(false),
493+
DefaultCooldown: aws.Int64(0),
494+
DefaultInstanceWarmup: aws.Int64(0),
494495
MixedInstancesPolicy: &autoscaling.MixedInstancesPolicy{
495496
InstancesDistribution: &autoscaling.InstancesDistribution{
496497
OnDemandAllocationStrategy: aws.String("prioritized"),

0 commit comments

Comments
 (0)