Skip to content

Commit f1407a1

Browse files
committed
Add mutex to DeleteNodes in cluster-autoscaler CAPI provider
This change adds a mutex to the MachineController structure which is used to gate access to the DeleteNodes function. This is one in a series of PRs to mitigate kubernetes#3104
1 parent bfee828 commit f1407a1

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

cluster-autoscaler/cloudprovider/clusterapi/clusterapi_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"os"
2323
"strings"
24+
"sync"
2425

2526
corev1 "k8s.io/api/core/v1"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -65,6 +66,7 @@ type machineController struct {
6566
machineSetResource *schema.GroupVersionResource
6667
machineResource *schema.GroupVersionResource
6768
machineDeploymentResource *schema.GroupVersionResource
69+
accessLock sync.Mutex
6870
}
6971

7072
type machineSetFilterFunc func(machineSet *MachineSet) error

cluster-autoscaler/cloudprovider/clusterapi/clusterapi_nodegroup.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func (ng *nodegroup) IncreaseSize(delta int) error {
8282
// group. This function should wait until node group size is updated.
8383
// Implementation required.
8484
func (ng *nodegroup) DeleteNodes(nodes []*corev1.Node) error {
85+
ng.machineController.accessLock.Lock()
86+
defer ng.machineController.accessLock.Unlock()
87+
8588
// Step 1: Verify all nodes belong to this node group.
8689
for _, node := range nodes {
8790
actualNodeGroup, err := ng.machineController.nodeGroupForNode(node)

0 commit comments

Comments
 (0)