Skip to content

Commit

Permalink
Rename default options to NodeGroupDefaults
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciekPytel committed Jan 21, 2021
1 parent bca80ad commit f05df85
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 101 deletions.
4 changes: 2 additions & 2 deletions cluster-autoscaler/config/autoscaling_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ type NodeGroupAutoscalingOptions struct {

// AutoscalingOptions contain various options to customize how autoscaling works
type AutoscalingOptions struct {
// NodeGroupAutoscalingOptions are default values for per NodeGroup options.
// NodeGroupDefaults are default values for per NodeGroup options.
// They will be used any time a specific value is not provided for a given NodeGroup.
NodeGroupAutoscalingOptions
NodeGroupDefaults NodeGroupAutoscalingOptions
// MaxEmptyBulkDelete is a number of empty nodes that can be removed at the same time.
MaxEmptyBulkDelete int
// MaxNodesTotal sets the maximum number of nodes in the whole cluster
Expand Down
4 changes: 2 additions & 2 deletions cluster-autoscaler/core/scale_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func NewScaleDown(context *context.AutoscalingContext, processors *processors.Au
func (sd *ScaleDown) CleanUp(timestamp time.Time) {
// Use default ScaleDownUnneededTime as in this context the value
// doesn't apply to any specific NodeGroup.
sd.usageTracker.CleanUp(timestamp.Add(-sd.context.ScaleDownUnneededTime))
sd.usageTracker.CleanUp(timestamp.Add(-sd.context.NodeGroupDefaults.ScaleDownUnneededTime))
sd.clearUnremovableNodeReasons()
}

Expand Down Expand Up @@ -431,7 +431,7 @@ func (sd *ScaleDown) checkNodeUtilization(timestamp time.Time, node *apiv1.Node,
if nodeGroup == nil || reflect.ValueOf(nodeGroup).IsNil() {
// We should never get here as non-autoscaled nodes should not be included in scaleDownCandidates list
// (and the default PreFilteringScaleDownNodeProcessor would indeed filter them out).
klog.V(4).Infof("Skipped %s from delete considered - the node is not autoscaled", node.Name)
klog.Warningf("Skipped %s from delete consideration - the node is not autoscaled", node.Name)
return simulator.NotAutoscaled, nil
}

Expand Down
26 changes: 13 additions & 13 deletions cluster-autoscaler/core/scale_down_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestFindUnneededNodes(t *testing.T) {
provider.AddNode("ng1", n9)

options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: 0.35,
},
UnremovableNodeRecheckTimeout: 5 * time.Minute,
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestFindUnneededGPUNodes(t *testing.T) {
provider.AddNode("ng1", n3)

options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: 0.35,
ScaleDownGpuUtilizationThreshold: 0.3,
},
Expand Down Expand Up @@ -310,7 +310,7 @@ func TestFindUnneededWithPerNodeGroupThresholds(t *testing.T) {
}

globalOptions := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: 0.5,
ScaleDownGpuUtilizationThreshold: 0.5,
},
Expand Down Expand Up @@ -429,7 +429,7 @@ func TestPodsWithPreemptionsFindUnneededNodes(t *testing.T) {
provider.AddNode("ng1", n4)

options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: 0.35,
},
}
Expand Down Expand Up @@ -483,7 +483,7 @@ func TestFindUnneededMaxCandidates(t *testing.T) {
numCandidates := 30

options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: 0.35,
},
ScaleDownNonEmptyCandidatesCount: numCandidates,
Expand Down Expand Up @@ -558,7 +558,7 @@ func TestFindUnneededEmptyNodes(t *testing.T) {
numCandidates := 30

options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: 0.35,
},
ScaleDownNonEmptyCandidatesCount: numCandidates,
Expand Down Expand Up @@ -608,7 +608,7 @@ func TestFindUnneededNodePool(t *testing.T) {
numCandidates := 30

options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: 0.35,
},
ScaleDownNonEmptyCandidatesCount: numCandidates,
Expand Down Expand Up @@ -1135,7 +1135,7 @@ func TestScaleDown(t *testing.T) {
assert.NotNil(t, provider)

options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUnneededTime: time.Minute,
ScaleDownUtilizationThreshold: 0.5,
},
Expand Down Expand Up @@ -1194,7 +1194,7 @@ func assertSubset(t *testing.T, a []string, b []string) {
}

var defaultScaleDownOptions = config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUnneededTime: time.Minute,
ScaleDownUtilizationThreshold: 0.5,
ScaleDownGpuUtilizationThreshold: 0.5,
Expand Down Expand Up @@ -1479,7 +1479,7 @@ func TestNoScaleDownUnready(t *testing.T) {
provider.AddNode("ng1", n2)

options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUnneededTime: time.Minute,
ScaleDownUtilizationThreshold: 0.5,
ScaleDownUnreadyTime: time.Hour,
Expand Down Expand Up @@ -1589,7 +1589,7 @@ func TestScaleDownNoMove(t *testing.T) {
assert.NotNil(t, provider)

options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUnneededTime: time.Minute,
ScaleDownUnreadyTime: time.Hour,
ScaleDownUtilizationThreshold: 0.5,
Expand Down Expand Up @@ -1839,7 +1839,7 @@ func TestSoftTaint(t *testing.T) {
assert.NotNil(t, provider)

options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUnneededTime: 10 * time.Minute,
ScaleDownUtilizationThreshold: 0.5,
},
Expand Down Expand Up @@ -1960,7 +1960,7 @@ func TestSoftTaintTimeLimit(t *testing.T) {
assert.NotNil(t, provider)

options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUnneededTime: 10 * time.Minute,
ScaleDownUtilizationThreshold: 0.5,
},
Expand Down
14 changes: 7 additions & 7 deletions cluster-autoscaler/core/static_autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestStaticAutoscalerRunOnce(t *testing.T) {

// Create context with mocked lister registry.
options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUnneededTime: time.Minute,
ScaleDownUnreadyTime: time.Minute,
ScaleDownUtilizationThreshold: 0.5,
Expand Down Expand Up @@ -361,7 +361,7 @@ func TestStaticAutoscalerRunOnceWithAutoprovisionedEnabled(t *testing.T) {

// Create context with mocked lister registry.
options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUnneededTime: time.Minute,
ScaleDownUnreadyTime: time.Minute,
ScaleDownUtilizationThreshold: 0.5,
Expand Down Expand Up @@ -497,7 +497,7 @@ func TestStaticAutoscalerRunOnceWithALongUnregisteredNode(t *testing.T) {

// Create context with mocked lister registry.
options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUnneededTime: time.Minute,
ScaleDownUnreadyTime: time.Minute,
ScaleDownUtilizationThreshold: 0.5,
Expand Down Expand Up @@ -644,7 +644,7 @@ func TestStaticAutoscalerRunOncePodsWithPriorities(t *testing.T) {

// Create context with mocked lister registry.
options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUnneededTime: time.Minute,
ScaleDownUtilizationThreshold: 0.5,
ScaleDownUnreadyTime: time.Minute,
Expand Down Expand Up @@ -774,7 +774,7 @@ func TestStaticAutoscalerRunOnceWithFilteringOnBinPackingEstimator(t *testing.T)

// Create context with mocked lister registry.
options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: 0.5,
},
EstimatorName: estimator.BinpackingEstimatorName,
Expand Down Expand Up @@ -870,7 +870,7 @@ func TestStaticAutoscalerRunOnceWithFilteringOnUpcomingNodesEnabledNoScaleUp(t *

// Create context with mocked lister registry.
options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: 0.5,
},
EstimatorName: estimator.BinpackingEstimatorName,
Expand Down Expand Up @@ -930,7 +930,7 @@ func TestStaticAutoscalerInstaceCreationErrors(t *testing.T) {

// Create context with mocked lister registry.
options := config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUnneededTime: time.Minute,
ScaleDownUnreadyTime: time.Minute,
ScaleDownUtilizationThreshold: 0.5,
Expand Down
2 changes: 1 addition & 1 deletion cluster-autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func createAutoscalingOptions() config.AutoscalingOptions {
klog.Fatalf("Failed to parse flags: %v", err)
}
return config.AutoscalingOptions{
NodeGroupAutoscalingOptions: config.NodeGroupAutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUtilizationThreshold: *scaleDownUtilizationThreshold,
ScaleDownGpuUtilizationThreshold: *scaleDownGpuUtilizationThreshold,
ScaleDownUnneededTime: *scaleDownUnneededTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,48 +45,48 @@ type DelegatingNodeGroupConfigProcessor struct {

// GetScaleDownUnneededTime returns ScaleDownUnneededTime value that should be used for a given NodeGroup.
func (p *DelegatingNodeGroupConfigProcessor) GetScaleDownUnneededTime(context *context.AutoscalingContext, nodeGroup cloudprovider.NodeGroup) (time.Duration, error) {
ngConfig, err := nodeGroup.GetOptions(context.NodeGroupAutoscalingOptions)
ngConfig, err := nodeGroup.GetOptions(context.NodeGroupDefaults)
if err != nil && err != cloudprovider.ErrNotImplemented {
return time.Duration(0), err
}
if ngConfig == nil || err == cloudprovider.ErrNotImplemented {
return context.ScaleDownUnneededTime, nil
return context.NodeGroupDefaults.ScaleDownUnneededTime, nil
}
return ngConfig.ScaleDownUnneededTime, nil
}

// GetScaleDownUnreadyTime returns ScaleDownUnreadyTime value that should be used for a given NodeGroup.
func (p *DelegatingNodeGroupConfigProcessor) GetScaleDownUnreadyTime(context *context.AutoscalingContext, nodeGroup cloudprovider.NodeGroup) (time.Duration, error) {
ngConfig, err := nodeGroup.GetOptions(context.NodeGroupAutoscalingOptions)
ngConfig, err := nodeGroup.GetOptions(context.NodeGroupDefaults)
if err != nil && err != cloudprovider.ErrNotImplemented {
return time.Duration(0), err
}
if ngConfig == nil || err == cloudprovider.ErrNotImplemented {
return context.ScaleDownUnreadyTime, nil
return context.NodeGroupDefaults.ScaleDownUnreadyTime, nil
}
return ngConfig.ScaleDownUnreadyTime, nil
}

// GetScaleDownUtilizationThreshold returns ScaleDownUtilizationThreshold value that should be used for a given NodeGroup.
func (p *DelegatingNodeGroupConfigProcessor) GetScaleDownUtilizationThreshold(context *context.AutoscalingContext, nodeGroup cloudprovider.NodeGroup) (float64, error) {
ngConfig, err := nodeGroup.GetOptions(context.NodeGroupAutoscalingOptions)
ngConfig, err := nodeGroup.GetOptions(context.NodeGroupDefaults)
if err != nil && err != cloudprovider.ErrNotImplemented {
return 0.0, err
}
if ngConfig == nil || err == cloudprovider.ErrNotImplemented {
return context.ScaleDownUtilizationThreshold, nil
return context.NodeGroupDefaults.ScaleDownUtilizationThreshold, nil
}
return ngConfig.ScaleDownUtilizationThreshold, nil
}

// GetScaleDownGpuUtilizationThreshold returns ScaleDownGpuUtilizationThreshold value that should be used for a given NodeGroup.
func (p *DelegatingNodeGroupConfigProcessor) GetScaleDownGpuUtilizationThreshold(context *context.AutoscalingContext, nodeGroup cloudprovider.NodeGroup) (float64, error) {
ngConfig, err := nodeGroup.GetOptions(context.NodeGroupAutoscalingOptions)
ngConfig, err := nodeGroup.GetOptions(context.NodeGroupDefaults)
if err != nil && err != cloudprovider.ErrNotImplemented {
return 0.0, err
}
if ngConfig == nil || err == cloudprovider.ErrNotImplemented {
return context.ScaleDownGpuUtilizationThreshold, nil
return context.NodeGroupDefaults.ScaleDownGpuUtilizationThreshold, nil
}
return ngConfig.ScaleDownGpuUtilizationThreshold, nil
}
Expand Down
Loading

0 comments on commit f05df85

Please sign in to comment.