Skip to content

Commit

Permalink
actual change to add feature aggressiveScaleDown
Browse files Browse the repository at this point in the history
  • Loading branch information
yehielnetapp committed Nov 4, 2024
1 parent 9e06e97 commit e9f0fc0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
9 changes: 9 additions & 0 deletions pkg/model/awsmodel/spotinst.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}

Expand Down
31 changes: 28 additions & 3 deletions upup/pkg/fi/cloudup/spotinsttasks/ocean.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Ocean struct {
SpreadNodesBy *string
AvailabilityVsCost *string
ResourceTagSpecificationVolumes *bool
AutoScalerAggressiveScaleDown *bool
}

var (
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e9f0fc0

Please sign in to comment.