Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cherry-pick v1.29] Updated NodeGroupAutoscalingOptions to now include all options (#310) #313

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading