Skip to content

Commit f48b26e

Browse files
committed
move lock to the get method
1 parent ca6bbc9 commit f48b26e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cluster-autoscaler/cloudprovider/azure/azure_scale_set.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,10 @@ func (scaleSet *ScaleSet) DeleteInstances(instances []*azureRef) error {
414414
return fmt.Errorf("cannot delete instance (%s) which don't belong to the same Scale Set (%q)", instance.Name, commonAsg)
415415
}
416416

417-
scaleSet.instanceMutex.Lock()
418417
if cpi, found := scaleSet.getInstanceByProviderID(instance.Name); found && cpi.Status != nil && cpi.Status.State == cloudprovider.InstanceDeleting {
419418
klog.V(3).Infof("Skipping deleting instance %s as its current state is deleting", instance.Name)
420419
continue
421420
}
422-
scaleSet.instanceMutex.Unlock()
423421

424422
instanceID, err := getLastSegment(instance.Name)
425423
if err != nil {
@@ -730,6 +728,8 @@ func buildInstanceCache(vms []compute.VirtualMachineScaleSetVM) []cloudprovider.
730728
}
731729

732730
func (scaleSet *ScaleSet) getInstanceByProviderID(providerID string) (cloudprovider.Instance, bool) {
731+
scaleSet.instanceMutex.Lock()
732+
defer scaleSet.instanceMutex.Unlock()
733733
for _, instance := range scaleSet.instanceCache {
734734
if instance.Id == providerID {
735735
return instance, true

0 commit comments

Comments
 (0)