Skip to content

Commit 385b73d

Browse files
authored
Merge pull request kubernetes#3261 from marwanad/reduce-lock-scope
Reduce instance lock scope in scale sets
2 parents da47042 + 3969346 commit 385b73d

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

cluster-autoscaler/cloudprovider/azure/azure_scale_set.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,6 @@ func (scaleSet *ScaleSet) GetScaleSetSize() (int64, error) {
228228
}
229229

230230
func (scaleSet *ScaleSet) waitForDeleteInstances(future *azure.Future, requiredIds *compute.VirtualMachineScaleSetVMInstanceRequiredIDs) {
231-
var err error
232-
233-
defer func() {
234-
if err != nil {
235-
klog.Errorf("Failed to delete instances %v", requiredIds.InstanceIds)
236-
}
237-
}()
238-
239231
ctx, cancel := getContextWithCancel()
240232
defer cancel()
241233

@@ -411,9 +403,6 @@ func (scaleSet *ScaleSet) DeleteInstances(instances []*azureRef) error {
411403
return err
412404
}
413405

414-
scaleSet.instanceMutex.Lock()
415-
defer scaleSet.instanceMutex.Unlock()
416-
417406
instanceIDs := []string{}
418407
for _, instance := range instances {
419408
asg, err := scaleSet.manager.GetAsgForInstance(instance)
@@ -425,10 +414,12 @@ func (scaleSet *ScaleSet) DeleteInstances(instances []*azureRef) error {
425414
return fmt.Errorf("cannot delete instance (%s) which don't belong to the same Scale Set (%q)", instance.Name, commonAsg)
426415
}
427416

417+
scaleSet.instanceMutex.Lock()
428418
if cpi, found := scaleSet.getInstanceByProviderID(instance.Name); found && cpi.Status != nil && cpi.Status.State == cloudprovider.InstanceDeleting {
429419
klog.V(3).Infof("Skipping deleting instance %s as its current state is deleting", instance.Name)
430420
continue
431421
}
422+
scaleSet.instanceMutex.Unlock()
432423

433424
instanceID, err := getLastSegment(instance.Name)
434425
if err != nil {

0 commit comments

Comments
 (0)