Skip to content

Commit

Permalink
✨ Add DefaultInstanceWarmup field to AWSMachineDeployment spec (#…
Browse files Browse the repository at this point in the history
…4760)

* Add `DefaultInstanceWarmup` field to `AWSMachineDeployment` spec

* remove field from v1beta1
  • Loading branch information
mnitchev authored Feb 7, 2024
1 parent 9dfa0a3 commit ff8cb13
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,12 @@ spec:
completes before another scaling activity can start. If no value
is supplied by user a default value of 300 seconds is set
type: string
defaultInstanceWarmup:
description: The amount of time, in seconds, until a new instance
is considered to have finished initializing and resource consumption
to become stable after it enters the InService state. If no value
is supplied by user a default value of 300 seconds is set
type: string
maxSize:
default: 1
description: MaxSize defines the maximum size of the group.
Expand Down
7 changes: 5 additions & 2 deletions exp/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package v1beta1

import (
apiconversion "k8s.io/apimachinery/pkg/conversion"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"

infrav1beta1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta1"
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
infrav1exp "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

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

dst.Spec.DefaultInstanceWarmup = restored.Spec.DefaultInstanceWarmup

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions exp/api/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions exp/api/v1beta2/awsmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ type AWSMachinePoolSpec struct {
// +optional
DefaultCoolDown metav1.Duration `json:"defaultCoolDown,omitempty"`

// The amount of time, in seconds, until a new instance is considered to
// have finished initializing and resource consumption to become stable
// after it enters the InService state.
// If no value is supplied by user a default value of 300 seconds is set
// +optional
DefaultInstanceWarmup metav1.Duration `json:"defaultInstanceWarmup,omitempty"`

// RefreshPreferences describes set of preferences associated with the instance refresh request.
// +optional
RefreshPreferences *RefreshPreferences `json:"refreshPreferences,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions exp/api/v1beta2/awsmachinepool_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,9 @@ func (r *AWSMachinePool) Default() {
log.Info("DefaultCoolDown is zero, setting 300 seconds as default")
r.Spec.DefaultCoolDown.Duration = 300 * time.Second
}

if int(r.Spec.DefaultInstanceWarmup.Duration.Seconds()) == 0 {
log.Info("DefaultInstanceWarmup is zero, setting 300 seconds as default")
r.Spec.DefaultInstanceWarmup.Duration = 300 * time.Second
}
}
21 changes: 11 additions & 10 deletions exp/api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,17 @@ type Tags map[string]string
// AutoScalingGroup describes an AWS autoscaling group.
type AutoScalingGroup struct {
// The tags associated with the instance.
ID string `json:"id,omitempty"`
Tags infrav1.Tags `json:"tags,omitempty"`
Name string `json:"name,omitempty"`
DesiredCapacity *int32 `json:"desiredCapacity,omitempty"`
MaxSize int32 `json:"maxSize,omitempty"`
MinSize int32 `json:"minSize,omitempty"`
PlacementGroup string `json:"placementGroup,omitempty"`
Subnets []string `json:"subnets,omitempty"`
DefaultCoolDown metav1.Duration `json:"defaultCoolDown,omitempty"`
CapacityRebalance bool `json:"capacityRebalance,omitempty"`
ID string `json:"id,omitempty"`
Tags infrav1.Tags `json:"tags,omitempty"`
Name string `json:"name,omitempty"`
DesiredCapacity *int32 `json:"desiredCapacity,omitempty"`
MaxSize int32 `json:"maxSize,omitempty"`
MinSize int32 `json:"minSize,omitempty"`
PlacementGroup string `json:"placementGroup,omitempty"`
Subnets []string `json:"subnets,omitempty"`
DefaultCoolDown metav1.Duration `json:"defaultCoolDown,omitempty"`
DefaultInstanceWarmup metav1.Duration `json:"defaultInstanceWarmup,omitempty"`
CapacityRebalance bool `json:"capacityRebalance,omitempty"`

MixedInstancesPolicy *MixedInstancesPolicy `json:"mixedInstancesPolicy,omitempty"`
Status ASGStatus
Expand Down
2 changes: 2 additions & 0 deletions exp/api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions pkg/cloud/services/autoscaling/autoscalinggroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,14 @@ func (s *Service) CreateASG(machinePoolScope *scope.MachinePoolScope) (*expinfra
}

input := &expinfrav1.AutoScalingGroup{
Name: machinePoolScope.Name(),
MaxSize: machinePoolScope.AWSMachinePool.Spec.MaxSize,
MinSize: machinePoolScope.AWSMachinePool.Spec.MinSize,
Subnets: subnets,
DefaultCoolDown: machinePoolScope.AWSMachinePool.Spec.DefaultCoolDown,
CapacityRebalance: machinePoolScope.AWSMachinePool.Spec.CapacityRebalance,
MixedInstancesPolicy: machinePoolScope.AWSMachinePool.Spec.MixedInstancesPolicy,
Name: machinePoolScope.Name(),
MaxSize: machinePoolScope.AWSMachinePool.Spec.MaxSize,
MinSize: machinePoolScope.AWSMachinePool.Spec.MinSize,
Subnets: subnets,
DefaultCoolDown: machinePoolScope.AWSMachinePool.Spec.DefaultCoolDown,
DefaultInstanceWarmup: machinePoolScope.AWSMachinePool.Spec.DefaultInstanceWarmup,
CapacityRebalance: machinePoolScope.AWSMachinePool.Spec.CapacityRebalance,
MixedInstancesPolicy: machinePoolScope.AWSMachinePool.Spec.MixedInstancesPolicy,
}

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

func (s *Service) runPool(i *expinfrav1.AutoScalingGroup, launchTemplateID string) error {
input := &autoscaling.CreateAutoScalingGroupInput{
AutoScalingGroupName: aws.String(i.Name),
MaxSize: aws.Int64(int64(i.MaxSize)),
MinSize: aws.Int64(int64(i.MinSize)),
VPCZoneIdentifier: aws.String(strings.Join(i.Subnets, ", ")),
DefaultCooldown: aws.Int64(int64(i.DefaultCoolDown.Duration.Seconds())),
CapacityRebalance: aws.Bool(i.CapacityRebalance),
AutoScalingGroupName: aws.String(i.Name),
MaxSize: aws.Int64(int64(i.MaxSize)),
MinSize: aws.Int64(int64(i.MinSize)),
VPCZoneIdentifier: aws.String(strings.Join(i.Subnets, ", ")),
DefaultCooldown: aws.Int64(int64(i.DefaultCoolDown.Duration.Seconds())),
DefaultInstanceWarmup: aws.Int64(int64(i.DefaultInstanceWarmup.Duration.Seconds())),
CapacityRebalance: aws.Bool(i.CapacityRebalance),
}

if i.DesiredCapacity != nil {
Expand Down
7 changes: 4 additions & 3 deletions pkg/cloud/services/autoscaling/autoscalinggroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,10 @@ func TestServiceCreateASG(t *testing.T) {
wantASG: false,
expect: func(m *mock_autoscalingiface.MockAutoScalingAPIMockRecorder) {
expected := &autoscaling.CreateAutoScalingGroupInput{
AutoScalingGroupName: aws.String("create-asg-success"),
CapacityRebalance: aws.Bool(false),
DefaultCooldown: aws.Int64(0),
AutoScalingGroupName: aws.String("create-asg-success"),
CapacityRebalance: aws.Bool(false),
DefaultCooldown: aws.Int64(0),
DefaultInstanceWarmup: aws.Int64(0),
MixedInstancesPolicy: &autoscaling.MixedInstancesPolicy{
InstancesDistribution: &autoscaling.InstancesDistribution{
OnDemandAllocationStrategy: aws.String("prioritized"),
Expand Down

0 comments on commit ff8cb13

Please sign in to comment.