From 290a3f0fb17ce08fdbf9e36fd95e3c03ed037da0 Mon Sep 17 00:00:00 2001 From: "dom.bozzuto" Date: Wed, 10 Jul 2024 17:13:32 -0400 Subject: [PATCH] Revert "[local] Track previous deletions when cache is refreshed" This reverts commit 598e946f77ab6785d45dc2fb08136219d7921b8e. --- .../cloudprovider/azure/azure_scale_set.go | 45 ++++++------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go b/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go index dd43c3e7d1f7..08533776a58c 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go @@ -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 } @@ -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) { @@ -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) { @@ -621,7 +621,7 @@ 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 @@ -629,18 +629,9 @@ func (scaleSet *ScaleSet) buildScaleSetCacheForFlex(lastRefresh time.Time, lastI // 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 { @@ -648,7 +639,7 @@ func buildInstanceCache(vmList interface{}, lastInstanceCacheState []cloudprovid 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 { @@ -656,14 +647,14 @@ func buildInstanceCache(vmList interface{}, lastInstanceCacheState []cloudprovid 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 @@ -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) {