Skip to content

Commit

Permalink
Merge pull request #6485 from ctripcloud/fix-deleteNodesFromCloudProv…
Browse files Browse the repository at this point in the history
…ider-panic

fix: panic in deleteNodesFromCloudProvider
  • Loading branch information
k8s-ci-robot authored Feb 6, 2024
2 parents 506c221 + bb8d2fe commit 00fbbe1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cluster-autoscaler/core/scaledown/actuation/delete_in_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package actuation

import (
"fmt"
"reflect"
"sync"
"time"

Expand Down Expand Up @@ -71,7 +72,7 @@ func NewNodeDeletionBatcher(ctx *context.AutoscalingContext, scaleStateNotifier
func (d *NodeDeletionBatcher) AddNodes(nodes []*apiv1.Node, nodeGroup cloudprovider.NodeGroup, drain bool) {
// If delete interval is 0, than instantly start node deletion.
if d.deleteInterval == 0 {
go d.deleteNodesAndRegisterStatus(nodes, drain)
go d.deleteNodesAndRegisterStatus(nodes, nodeGroup.Id(), drain)
return
}
first := d.addNodesToBucket(nodes, nodeGroup, drain)
Expand All @@ -84,12 +85,12 @@ func (d *NodeDeletionBatcher) AddNodes(nodes []*apiv1.Node, nodeGroup cloudprovi
}
}

func (d *NodeDeletionBatcher) deleteNodesAndRegisterStatus(nodes []*apiv1.Node, drain bool) {
func (d *NodeDeletionBatcher) deleteNodesAndRegisterStatus(nodes []*apiv1.Node, nodeGroupId string, drain bool) {
nodeGroup, err := deleteNodesFromCloudProvider(d.ctx, d.scaleStateNotifier, nodes)
for _, node := range nodes {
if err != nil {
result := status.NodeDeleteResult{ResultType: status.NodeDeleteErrorFailedToDelete, Err: err}
CleanUpAndRecordFailedScaleDownEvent(d.ctx, node, nodeGroup.Id(), drain, d.nodeDeletionTracker, "", result)
CleanUpAndRecordFailedScaleDownEvent(d.ctx, node, nodeGroupId, drain, d.nodeDeletionTracker, "", result)
} else {
RegisterAndRecordSuccessfulScaleDownEvent(d.ctx, d.scaleStateNotifier, node, nodeGroup, drain, d.nodeDeletionTracker)
}
Expand Down Expand Up @@ -150,6 +151,9 @@ func deleteNodesFromCloudProvider(ctx *context.AutoscalingContext, scaleStateNot
if err != nil {
return nodeGroup, errors.NewAutoscalerError(errors.CloudProviderError, "failed to find node group for %s: %v", nodes[0].Name, err)
}
if nodeGroup == nil || reflect.ValueOf(nodeGroup).IsNil() {
return nil, errors.NewAutoscalerError(errors.InternalError, "picked node that doesn't belong to a node group: %s", nodes[0].Name)
}
if err := nodeGroup.DeleteNodes(nodes); err != nil {
scaleStateNotifier.RegisterFailedScaleDown(nodeGroup,
string(errors.CloudProviderError),
Expand Down

0 comments on commit 00fbbe1

Please sign in to comment.