Skip to content

Commit

Permalink
Updated NodeGroupAutoscalingOptions to now include all options (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfern authored Jul 4, 2024
1 parent 1be6cca commit 962e5dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
24 changes: 7 additions & 17 deletions cluster-autoscaler/cloudprovider/mcm/mcm_cloud_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,48 +478,38 @@ func (machinedeployment *MachineDeployment) Nodes() ([]cloudprovider.Instance, e
// NodeGroup. Returning a nil will result in using default options.
// Implementation optional.
func (machinedeployment *MachineDeployment) GetOptions(defaults config.NodeGroupAutoscalingOptions) (*config.NodeGroupAutoscalingOptions, error) {
options := defaults
mcdAnnotations, err := machinedeployment.mcmManager.GetMachineDeploymentAnnotations(machinedeployment.Name)
if err != nil {
return nil, err
}

scaleDownUtilThresholdValue := defaults.ScaleDownUtilizationThreshold
if _, ok := mcdAnnotations[ScaleDownUtilizationThresholdAnnotation]; ok {
if floatVal, err := strconv.ParseFloat(mcdAnnotations[ScaleDownUtilizationThresholdAnnotation], 64); err == nil {
scaleDownUtilThresholdValue = floatVal
options.ScaleDownUtilizationThreshold = floatVal
}
}
scaleDownGPUUtilThresholdValue := defaults.ScaleDownGpuUtilizationThreshold
if _, ok := mcdAnnotations[ScaleDownGpuUtilizationThresholdAnnotation]; ok {
if floatVal, err := strconv.ParseFloat(mcdAnnotations[ScaleDownGpuUtilizationThresholdAnnotation], 64); err == nil {
scaleDownGPUUtilThresholdValue = floatVal
options.ScaleDownGpuUtilizationThreshold = floatVal
}
}
scaleDownUnneededDuration := defaults.ScaleDownUnneededTime
if _, ok := mcdAnnotations[ScaleDownUnneededTimeAnnotation]; ok {
if durationVal, err := time.ParseDuration(mcdAnnotations[ScaleDownUnneededTimeAnnotation]); err == nil {
scaleDownUnneededDuration = durationVal
options.ScaleDownUnneededTime = durationVal
}
}
scaleDownUnreadyDuration := defaults.ScaleDownUnreadyTime
if _, ok := mcdAnnotations[ScaleDownUnreadyTimeAnnotation]; ok {
if durationVal, err := time.ParseDuration(mcdAnnotations[ScaleDownUnreadyTimeAnnotation]); err == nil {
scaleDownUnreadyDuration = durationVal
options.ScaleDownUnreadyTime = durationVal
}
}
maxNodeProvisionDuration := defaults.MaxNodeProvisionTime
if _, ok := mcdAnnotations[MaxNodeProvisionTimeAnnotation]; ok {
if durationVal, err := time.ParseDuration(mcdAnnotations[MaxNodeProvisionTimeAnnotation]); err == nil {
maxNodeProvisionDuration = durationVal
options.MaxNodeProvisionTime = durationVal
}
}
return &config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: scaleDownUtilThresholdValue,
ScaleDownGpuUtilizationThreshold: scaleDownGPUUtilThresholdValue,
ScaleDownUnneededTime: scaleDownUnneededDuration,
ScaleDownUnreadyTime: scaleDownUnreadyDuration,
MaxNodeProvisionTime: maxNodeProvisionDuration,
}, nil
return &options, nil
}

// TemplateNodeInfo returns a node template for this node group.
Expand Down
32 changes: 16 additions & 16 deletions cluster-autoscaler/cloudprovider/mcm/mcm_cloud_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,16 @@ func TestNodes(t *testing.T) {
}

func TestGetOptions(t *testing.T) {
ngAutoScalingOpDefaults := config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: 0.5,
ScaleDownGpuUtilizationThreshold: 0.5,
ScaleDownUnneededTime: 1 * time.Minute,
ScaleDownUnreadyTime: 1 * time.Minute,
MaxNodeProvisionTime: 1 * time.Minute,
IgnoreDaemonSetsUtilization: true,
ZeroOrMaxNodeScaling: true,
}

type expect struct {
ngOptions *config.NodeGroupAutoscalingOptions
err error
Expand All @@ -616,14 +626,8 @@ func TestGetOptions(t *testing.T) {
nodeGroups: []string{nodeGroup1},
},
expect{
ngOptions: &config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: 0.5,
ScaleDownGpuUtilizationThreshold: 0.5,
ScaleDownUnneededTime: 1 * time.Minute,
ScaleDownUnreadyTime: 1 * time.Minute,
MaxNodeProvisionTime: 1 * time.Minute,
},
err: nil,
ngOptions: &ngAutoScalingOpDefaults,
err: nil,
},
},
{
Expand Down Expand Up @@ -651,6 +655,8 @@ func TestGetOptions(t *testing.T) {
ScaleDownUnneededTime: 5 * time.Minute,
ScaleDownUnreadyTime: 5 * time.Minute,
MaxNodeProvisionTime: 5 * time.Minute,
IgnoreDaemonSetsUtilization: ngAutoScalingOpDefaults.IgnoreDaemonSetsUtilization,
ZeroOrMaxNodeScaling: ngAutoScalingOpDefaults.ZeroOrMaxNodeScaling,
},
err: nil,
},
Expand Down Expand Up @@ -678,6 +684,8 @@ func TestGetOptions(t *testing.T) {
ScaleDownUnneededTime: 5 * time.Minute,
ScaleDownUnreadyTime: 1 * time.Minute,
MaxNodeProvisionTime: 2 * time.Minute,
IgnoreDaemonSetsUtilization: ngAutoScalingOpDefaults.IgnoreDaemonSetsUtilization,
ZeroOrMaxNodeScaling: ngAutoScalingOpDefaults.ZeroOrMaxNodeScaling,
},
err: nil,
},
Expand All @@ -699,14 +707,6 @@ func TestGetOptions(t *testing.T) {
md, err := buildMachineDeploymentFromSpec(entry.setup.nodeGroups[0], m)
g.Expect(err).To(BeNil())

ngAutoScalingOpDefaults := config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: 0.5,
ScaleDownGpuUtilizationThreshold: 0.5,
ScaleDownUnneededTime: 1 * time.Minute,
ScaleDownUnreadyTime: 1 * time.Minute,
MaxNodeProvisionTime: 1 * time.Minute,
}

options, err := md.GetOptions(ngAutoScalingOpDefaults)

if entry.expect.err != nil {
Expand Down

0 comments on commit 962e5dd

Please sign in to comment.