diff --git a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_controller.go b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_controller.go index 77f3ff96f40..c7469f10cd8 100644 --- a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_controller.go +++ b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_controller.go @@ -20,6 +20,7 @@ import ( "fmt" "os" "strings" + "sync" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -64,6 +65,7 @@ type machineController struct { machineSetResource *schema.GroupVersionResource machineResource *schema.GroupVersionResource machineDeploymentResource *schema.GroupVersionResource + accessLock sync.Mutex } type machineSetFilterFunc func(machineSet *MachineSet) error diff --git a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_nodegroup.go b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_nodegroup.go index 8c13da3cb29..2a5f9a35cf0 100644 --- a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_nodegroup.go +++ b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_nodegroup.go @@ -82,6 +82,9 @@ func (ng *nodegroup) IncreaseSize(delta int) error { // group. This function should wait until node group size is updated. // Implementation required. func (ng *nodegroup) DeleteNodes(nodes []*corev1.Node) error { + ng.machineController.accessLock.Lock() + defer ng.machineController.accessLock.Unlock() + // Step 1: Verify all nodes belong to this node group. for _, node := range nodes { actualNodeGroup, err := ng.machineController.nodeGroupForNode(node)