Communicate the result of RemoveUnneededNodeGroups to ScaleDownStatusProcessor

This commit is contained in:
Jakub Tużnik 2019-08-12 16:25:42 +02:00
parent 100e91ba75
commit 44ae89dd09
4 changed files with 15 additions and 7 deletions

View File

@ -129,10 +129,11 @@ func (p *mockAutoprovisioningNodeGroupManager) CreateNodeGroup(context *context.
return result, nil
}
func (p *mockAutoprovisioningNodeGroupManager) RemoveUnneededNodeGroups(context *context.AutoscalingContext) error {
func (p *mockAutoprovisioningNodeGroupManager) RemoveUnneededNodeGroups(context *context.AutoscalingContext) (removedNodeGroups []cloudprovider.NodeGroup, err error) {
if !context.AutoscalingOptions.NodeAutoprovisioningEnabled {
return nil
return nil, nil
}
removedNodeGroups = make([]cloudprovider.NodeGroup, 0)
nodeGroups := context.CloudProvider.NodeGroups()
for _, nodeGroup := range nodeGroups {
if !nodeGroup.Autoprovisioned() {
@ -150,8 +151,9 @@ func (p *mockAutoprovisioningNodeGroupManager) RemoveUnneededNodeGroups(context
}
err = nodeGroup.Delete()
assert.NoError(p.t, err)
removedNodeGroups = append(removedNodeGroups, nodeGroup)
}
return nil
return removedNodeGroups, nil
}
func (p *mockAutoprovisioningNodeGroupManager) CleanUp() {

View File

@ -418,13 +418,18 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) errors.AutoscalerError
// We want to delete unneeded Node Groups only if there was no recent scale up,
// and there is no current delete in progress and there was no recent errors.
a.processors.NodeGroupManager.RemoveUnneededNodeGroups(autoscalingContext)
removedNodeGroups, err := a.processors.NodeGroupManager.RemoveUnneededNodeGroups(autoscalingContext)
if err != nil {
klog.Errorf("Error while removing unneeded node groups: %v", err)
}
scaleDownStart := time.Now()
metrics.UpdateLastTime(metrics.ScaleDown, scaleDownStart)
scaleDownStatus, typedErr := scaleDown.TryToScaleDown(allNodes, originalScheduledPods, pdbs, currentTime)
metrics.UpdateDurationFromStart(metrics.ScaleDown, scaleDownStart)
scaleDownStatus.RemovedNodeGroups = removedNodeGroups
if scaleDownStatus.Result == status.ScaleDownNodeDeleted {
a.lastScaleDownDeleteTime = currentTime
a.clusterStateRegistry.Recalculate()

View File

@ -25,7 +25,7 @@ import (
// NodeGroupManager is responsible for creating/deleting node groups.
type NodeGroupManager interface {
CreateNodeGroup(context *context.AutoscalingContext, nodeGroup cloudprovider.NodeGroup) (CreateNodeGroupResult, errors.AutoscalerError)
RemoveUnneededNodeGroups(context *context.AutoscalingContext) error
RemoveUnneededNodeGroups(context *context.AutoscalingContext) (removedNodeGroups []cloudprovider.NodeGroup, err error)
CleanUp()
}
@ -52,8 +52,8 @@ func (*NoOpNodeGroupManager) CreateNodeGroup(context *context.AutoscalingContext
}
// RemoveUnneededNodeGroups does nothing in NoOpNodeGroupManager
func (*NoOpNodeGroupManager) RemoveUnneededNodeGroups(context *context.AutoscalingContext) error {
return nil
func (*NoOpNodeGroupManager) RemoveUnneededNodeGroups(context *context.AutoscalingContext) (removedNodeGroups []cloudprovider.NodeGroup, err error) {
return nil, nil
}
// CleanUp does nothing in NoOpNodeGroupManager

View File

@ -27,6 +27,7 @@ import (
type ScaleDownStatus struct {
Result ScaleDownResult
ScaledDownNodes []*ScaleDownNode
RemovedNodeGroups []cloudprovider.NodeGroup
NodeDeleteResults map[string]NodeDeleteResult
}