Skip to content

Commit

Permalink
Caches should be updated after async PUT succeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
feiskyer committed Apr 6, 2020
1 parent 340c206 commit 1260ea7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cluster-autoscaler/cloudprovider/azure/azure_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/to"
)

var (
Expand Down Expand Up @@ -261,16 +262,19 @@ func (scaleSet *ScaleSet) SetScaleSetSize(size int64) error {
scaleSet.sizeMutex.Lock()
defer scaleSet.sizeMutex.Unlock()

// Proactively set the VMSS size so autoscaler makes better decisions.
scaleSet.curSize = size
scaleSet.lastSizeRefresh = time.Now()

vmssInfo, rerr := scaleSet.getVMSSInfo()
if rerr != nil {
klog.Errorf("Failed to get information for VMSS (%q): %v", scaleSet.Name, rerr)
return rerr.Error()
}

// Abort scaling to avoid concurrent VMSS scaling if the VMSS is still under updating.
// Note that the VMSS provisioning state would be updated per scaleSet.sizeRefreshPeriod.
if vmssInfo.VirtualMachineScaleSetProperties != nil && strings.EqualFold(to.String(vmssInfo.VirtualMachineScaleSetProperties.ProvisioningState), string(compute.ProvisioningStateUpdating)) {
klog.Errorf("VMSS %q is still under updating, waiting for it finishes before scaling", scaleSet.Name)
return fmt.Errorf("VMSS %q is still under updating", scaleSet.Name)
}

// Update the new capacity to cache.
vmssSizeMutex.Lock()
vmssInfo.Sku.Capacity = &size
Expand All @@ -291,6 +295,10 @@ func (scaleSet *ScaleSet) SetScaleSetSize(size int64) error {
return rerr.Error()
}

// Proactively set the VMSS size so autoscaler makes better decisions.
scaleSet.curSize = size
scaleSet.lastSizeRefresh = time.Now()

klog.V(3).Infof("create a goroutine to wait for the result of the virtualMachineScaleSetsClient.CreateOrUpdate request")
go scaleSet.updateVMSSCapacity(future)

Expand Down

0 comments on commit 1260ea7

Please sign in to comment.