Merge pull request #3261 from marwanad/reduce-lock-scope

Reduce instance lock scope in scale sets
This commit is contained in:
Kubernetes Prow Robot 2020-07-01 20:40:00 -07:00 committed by GitHub
commit 385b73d70b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 11 deletions

View File

@ -228,14 +228,6 @@ func (scaleSet *ScaleSet) GetScaleSetSize() (int64, error) {
}
func (scaleSet *ScaleSet) waitForDeleteInstances(future *azure.Future, requiredIds *compute.VirtualMachineScaleSetVMInstanceRequiredIDs) {
var err error
defer func() {
if err != nil {
klog.Errorf("Failed to delete instances %v", requiredIds.InstanceIds)
}
}()
ctx, cancel := getContextWithCancel()
defer cancel()
@ -411,9 +403,6 @@ func (scaleSet *ScaleSet) DeleteInstances(instances []*azureRef) error {
return err
}
scaleSet.instanceMutex.Lock()
defer scaleSet.instanceMutex.Unlock()
instanceIDs := []string{}
for _, instance := range instances {
asg, err := scaleSet.manager.GetAsgForInstance(instance)
@ -425,10 +414,12 @@ func (scaleSet *ScaleSet) DeleteInstances(instances []*azureRef) error {
return fmt.Errorf("cannot delete instance (%s) which don't belong to the same Scale Set (%q)", instance.Name, commonAsg)
}
scaleSet.instanceMutex.Lock()
if cpi, found := scaleSet.getInstanceByProviderID(instance.Name); found && cpi.Status != nil && cpi.Status.State == cloudprovider.InstanceDeleting {
klog.V(3).Infof("Skipping deleting instance %s as its current state is deleting", instance.Name)
continue
}
scaleSet.instanceMutex.Unlock()
instanceID, err := getLastSegment(instance.Name)
if err != nil {