diff --git a/pkg/model/awsmodel/spotinst.go b/pkg/model/awsmodel/spotinst.go index ccbfa9d9754f2..bb3344cc19887 100644 --- a/pkg/model/awsmodel/spotinst.go +++ b/pkg/model/awsmodel/spotinst.go @@ -143,6 +143,10 @@ const ( // SpotClusterLabelResourceTagSpecificationVolumes // Specify if Volume resources will be tagged with Virtual Node Group tags or Ocean tags. SpotClusterLabelResourceTagSpecificationVolumes = "spotinst.io/resource-tag-specification-volumes" + + // SpotClusterLabelAutoScalerAggressiveScaleDown + // configure the aggressive scale down feature, the default is false. cluster.autoScaler.down.aggressiveScaleDown.isEnabled + SpotClusterLabelAutoScalerAggressiveScaleDown = "spotinst.io/autoscaler-aggressive-scale-down" ) // SpotInstanceGroupModelBuilder configures SpotInstanceGroup objects @@ -406,6 +410,11 @@ func (b *SpotInstanceGroupModelBuilder) buildOcean(c *fi.CloudupModelBuilderCont if err != nil { return err } + case SpotClusterLabelAutoScalerAggressiveScaleDown: + ocean.AutoScalerAggressiveScaleDown, err = parseBool(v) + if err != nil { + return err + } } } diff --git a/upup/pkg/fi/cloudup/spotinsttasks/ocean.go b/upup/pkg/fi/cloudup/spotinsttasks/ocean.go index e66902a0ec909..e8a7b89feda34 100644 --- a/upup/pkg/fi/cloudup/spotinsttasks/ocean.go +++ b/upup/pkg/fi/cloudup/spotinsttasks/ocean.go @@ -67,6 +67,7 @@ type Ocean struct { SpreadNodesBy *string AvailabilityVsCost *string ResourceTagSpecificationVolumes *bool + AutoScalerAggressiveScaleDown *bool } var ( @@ -324,9 +325,14 @@ func (o *Ocean) Find(c *fi.CloudupContext) (*Ocean, error) { // Scale down. if down := ocean.AutoScaler.Down; down != nil { - actual.AutoScalerOpts.Down = &AutoScalerDownOpts{ - MaxPercentage: down.MaxScaleDownPercentage, - EvaluationPeriods: down.EvaluationPeriods, + if down.MaxScaleDownPercentage != nil || down.EvaluationPeriods != nil { + actual.AutoScalerOpts.Down = &AutoScalerDownOpts{ + MaxPercentage: down.MaxScaleDownPercentage, + EvaluationPeriods: down.EvaluationPeriods, + } + } + if down.AggressiveScaleDown != nil { + actual.AutoScalerAggressiveScaleDown = down.AggressiveScaleDown.IsEnabled } } @@ -585,6 +591,16 @@ func (_ *Ocean) create(cloud awsup.AWSCloud, a, e, changes *Ocean) error { MaxMemoryGiB: limits.MaxMemory, } } + // create AutoScalerAggressiveScaleDown + { + if e.AutoScalerAggressiveScaleDown != nil { + aggressiveScaleDown := new(aws.AggressiveScaleDown) + if down := autoScaler.Down; down == nil { + autoScaler.Down = new(aws.AutoScalerDown) + } + autoScaler.Down.SetAggressiveScaleDown(aggressiveScaleDown.SetIsEnabled(fi.PtrTo(*e.AutoScalerAggressiveScaleDown))) + } + } ocean.SetAutoScaler(autoScaler) } @@ -1084,6 +1100,15 @@ func (_ *Ocean) update(cloud awsup.AWSCloud, a, e, changes *Ocean) error { } else if a.AutoScalerOpts.ResourceLimits != nil { autoScaler.SetResourceLimits(nil) } + // AutoScaler aggressive scale down + if changes.AutoScalerAggressiveScaleDown != nil { + aggressiveScaleDown := new(aws.AggressiveScaleDown) + if down := autoScaler.Down; down == nil { + autoScaler.Down = new(aws.AutoScalerDown) + } + autoScaler.Down.SetAggressiveScaleDown(aggressiveScaleDown.SetIsEnabled(fi.PtrTo(*changes.AutoScalerAggressiveScaleDown))) + changes.AutoScalerAggressiveScaleDown = nil + } ocean.SetAutoScaler(autoScaler) changed = true