Skip to content

Commit

Permalink
fix(kwok): fix panic when scale down node group
Browse files Browse the repository at this point in the history
  • Loading branch information
qianlei90 committed Dec 2, 2023
1 parent 85b6058 commit ca0bb24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
17 changes: 7 additions & 10 deletions cluster-autoscaler/cloudprovider/kwok/kwok_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"log"
"strconv"
"strings"
"time"

apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -155,13 +154,19 @@ func createNodegroups(nodes []*apiv1.Node, kubeClient kubernetes.Interface, kc *
}

ngName := getNGName(nodes[i], kc)
if ngName == "" {
klog.Fatalf("%s '%s' for node '%s' not present in the manifest",
kc.status.groupNodesBy, kc.status.key,
nodes[i].GetName())
}

if ngs[ngName] != nil {
ngs[ngName].targetSize += 1
continue
}

ng := parseAnnotations(nodes[i], kc)
ng.name = getNGName(nodes[i], kc)
ng.name = ngName
sanitizeNode(nodes[i])
prepareNode(nodes[i], ng.name)
ng.nodeTemplate = nodes[i]
Expand Down Expand Up @@ -266,13 +271,5 @@ func getNGName(no *apiv1.Node, kc *KwokProviderConfig) string {
klog.Fatal("grouping criteria for nodes is not set (expected: 'annotation' or 'label')")
}

if ngName == "" {
klog.Fatalf("%s '%s' for node '%s' not present in the manifest",
kc.status.groupNodesBy, kc.status.key,
no.GetName())
}

ngName = fmt.Sprintf("%s-%v", ngName, time.Now().Unix())

return ngName
}
4 changes: 2 additions & 2 deletions cluster-autoscaler/cloudprovider/kwok/kwok_nodegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ func (nodeGroup *NodeGroup) IncreaseSize(delta int) error {
if err != nil {
return fmt.Errorf("couldn't create new node '%s': %v", node.Name, err)
}
nodeGroup.targetSize += 1
}

nodeGroup.targetSize = newSize

return nil
}

Expand All @@ -111,6 +110,7 @@ func (nodeGroup *NodeGroup) DeleteNodes(nodes []*apiv1.Node) error {
if err != nil {
return err
}
nodeGroup.targetSize -= 1
}
return nil
}
Expand Down

0 comments on commit ca0bb24

Please sign in to comment.