Skip to content

Commit

Permalink
Revert "[local] Track previous deletions when cache is refreshed"
Browse files Browse the repository at this point in the history
This reverts commit 598e946.
  • Loading branch information
domenicbozzuto committed Jul 10, 2024
1 parent 0c2f44f commit 290a3f0
Showing 1 changed file with 14 additions and 31 deletions.
45 changes: 14 additions & 31 deletions cluster-autoscaler/cloudprovider/azure/azure_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,14 @@ func (scaleSet *ScaleSet) Nodes() ([]cloudprovider.Instance, error) {
klog.V(4).Infof("VMSS: orchestration Mode %s", orchestrationMode)

if orchestrationMode == compute.Uniform {
err := scaleSet.buildScaleSetCache(lastRefresh, scaleSet.instanceCache)
err := scaleSet.buildScaleSetCache(lastRefresh)
if err != nil {
return nil, err
}

} else if orchestrationMode == compute.Flexible {
if scaleSet.manager.config.EnableVmssFlex {
err := scaleSet.buildScaleSetCacheForFlex(lastRefresh, scaleSet.instanceCache)
err := scaleSet.buildScaleSetCacheForFlex(lastRefresh)
if err != nil {
return nil, err
}
Expand All @@ -591,7 +591,7 @@ func (scaleSet *ScaleSet) Nodes() ([]cloudprovider.Instance, error) {
return scaleSet.instanceCache, nil
}

func (scaleSet *ScaleSet) buildScaleSetCache(lastRefresh time.Time, lastInstanceCacheState []cloudprovider.Instance) error {
func (scaleSet *ScaleSet) buildScaleSetCache(lastRefresh time.Time) error {
vms, rerr := scaleSet.GetScaleSetVms()
if rerr != nil {
if isAzureRequestsThrottled(rerr) {
Expand All @@ -603,13 +603,13 @@ func (scaleSet *ScaleSet) buildScaleSetCache(lastRefresh time.Time, lastInstance
return rerr.Error()
}

scaleSet.instanceCache = buildInstanceCache(vms, lastInstanceCacheState)
scaleSet.instanceCache = buildInstanceCache(vms)
scaleSet.lastInstanceRefresh = lastRefresh

return nil
}

func (scaleSet *ScaleSet) buildScaleSetCacheForFlex(lastRefresh time.Time, lastInstanceCacheState []cloudprovider.Instance) error {
func (scaleSet *ScaleSet) buildScaleSetCacheForFlex(lastRefresh time.Time) error {
vms, rerr := scaleSet.GetFlexibleScaleSetVms()
if rerr != nil {
if isAzureRequestsThrottled(rerr) {
Expand All @@ -621,49 +621,40 @@ func (scaleSet *ScaleSet) buildScaleSetCacheForFlex(lastRefresh time.Time, lastI
return rerr.Error()
}

scaleSet.instanceCache = buildInstanceCache(vms, lastInstanceCacheState)
scaleSet.instanceCache = buildInstanceCache(vms)
scaleSet.lastInstanceRefresh = lastRefresh

return nil
}

// Note that the GetScaleSetVms() results is not used directly because for the List endpoint,
// their resource ID format is not consistent with Get endpoint
func buildInstanceCache(vmList interface{}, lastInstanceCacheState []cloudprovider.Instance) []cloudprovider.Instance {
func buildInstanceCache(vmList interface{}) []cloudprovider.Instance {
instances := []cloudprovider.Instance{}

// Find the instances that are already being deleted, so that status is not
// lost when the cache is rebuilt
var instancesBeingDeleted []cloudprovider.Instance
for _, instance := range lastInstanceCacheState {
if instance.Status != nil && instance.Status.State == cloudprovider.InstanceDeleting {
instancesBeingDeleted = append(instancesBeingDeleted, instance)
}
}

switch vms := vmList.(type) {
case []compute.VirtualMachineScaleSetVM:
for _, vm := range vms {
powerState := vmPowerStateRunning
if vm.InstanceView != nil && vm.InstanceView.Statuses != nil {
powerState = vmPowerStateFromStatuses(*vm.InstanceView.Statuses)
}
addInstanceToCache(&instances, instancesBeingDeleted, vm.ID, vm.ProvisioningState, powerState)
addInstanceToCache(&instances, vm.ID, vm.ProvisioningState, powerState)
}
case []compute.VirtualMachine:
for _, vm := range vms {
powerState := vmPowerStateRunning
if vm.InstanceView != nil && vm.InstanceView.Statuses != nil {
powerState = vmPowerStateFromStatuses(*vm.InstanceView.Statuses)
}
addInstanceToCache(&instances, instancesBeingDeleted, vm.ID, vm.ProvisioningState, powerState)
addInstanceToCache(&instances, vm.ID, vm.ProvisioningState, powerState)
}
}

return instances
}

func addInstanceToCache(instances *[]cloudprovider.Instance, instancesBeingDeleted []cloudprovider.Instance, id *string, provisioningState *string, powerState string) {
func addInstanceToCache(instances *[]cloudprovider.Instance, id *string, provisioningState *string, powerState string) {
// The resource ID is empty string, which indicates the instance may be in deleting state.
if len(*id) == 0 {
return
Expand All @@ -676,18 +667,10 @@ func addInstanceToCache(instances *[]cloudprovider.Instance, instancesBeingDelet
return
}

// Ensure that instances that had the deleting state prior to the last cache refresh
// still maintain the deleting state
newId := "azure://" + resourceID
newStatus := instanceStatusFromProvisioningStateAndPowerState(resourceID, provisioningState, powerState)
for _, instance := range instancesBeingDeleted {
if newId == instance.Id {
newStatus = &cloudprovider.InstanceStatus{State: cloudprovider.InstanceDeleting}
klog.V(4).Infof("VM %s was previously identified as undergoing deletion, persisting InstanceDeleting state", resourceID)
break
}
}
*instances = append(*instances, cloudprovider.Instance{Id: newId, Status: newStatus})
*instances = append(*instances, cloudprovider.Instance{
Id: "azure://" + resourceID,
Status: instanceStatusFromProvisioningStateAndPowerState(resourceID, provisioningState, powerState),
})
}

func (scaleSet *ScaleSet) getInstanceByProviderID(providerID string) (cloudprovider.Instance, bool) {
Expand Down

0 comments on commit 290a3f0

Please sign in to comment.