From d07dbf2ed5fec5ae9a01dcd5174d5d8796ec1470 Mon Sep 17 00:00:00 2001 From: Robin Deeboonchai Date: Wed, 19 Jun 2024 21:52:45 -0700 Subject: [PATCH] chore: undo azClient rename for now --- .../cloudprovider/azure/azure_agent_pool.go | 18 +++++++++--------- .../cloudprovider/azure/azure_cache.go | 12 ++++++------ .../cloudprovider/azure/azure_client.go | 6 +++--- .../cloudprovider/azure/azure_manager.go | 18 +++++++++--------- .../cloudprovider/azure/azure_scale_set.go | 14 +++++++------- .../cloudprovider/azure/azure_util.go | 10 +++++----- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/cluster-autoscaler/cloudprovider/azure/azure_agent_pool.go b/cluster-autoscaler/cloudprovider/azure/azure_agent_pool.go index 67efc7377239..e3f404f685a1 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_agent_pool.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_agent_pool.go @@ -82,7 +82,7 @@ func (as *AgentPool) initialize() error { ctx, cancel := getContextWithCancel() defer cancel() - template, err := as.manager.azureClients.deploymentClient.ExportTemplate(ctx, as.manager.config.ResourceGroup, as.manager.config.Deployment) + template, err := as.manager.azClient.deploymentClient.ExportTemplate(ctx, as.manager.config.ResourceGroup, as.manager.config.Deployment) if err != nil { klog.Errorf("deploymentClient.ExportTemplate(%s, %s) failed: %v", as.manager.config.ResourceGroup, as.manager.config.Deployment, err) return err.Error() @@ -215,7 +215,7 @@ func (as *AgentPool) getAllSucceededAndFailedDeployments() ([]resources.Deployme ctx, cancel := getContextWithCancel() defer cancel() - allDeployments, err := as.manager.azureClients.deploymentClient.List(ctx, as.manager.config.ResourceGroup) + allDeployments, err := as.manager.azClient.deploymentClient.List(ctx, as.manager.config.ResourceGroup) if err != nil { klog.Errorf("getAllSucceededAndFailedDeployments: failed to list deployments with error: %v", err) return nil, err.Error() @@ -264,7 +264,7 @@ func (as *AgentPool) deleteOutdatedDeployments() (err error) { errList := make([]error, 0) for _, deployment := range toBeDeleted { klog.V(4).Infof("deleteOutdatedDeployments: starts deleting outdated deployment (%s)", *deployment.Name) - err := as.manager.azureClients.deploymentClient.Delete(ctx, as.manager.config.ResourceGroup, *deployment.Name) + err := as.manager.azClient.deploymentClient.Delete(ctx, as.manager.config.ResourceGroup, *deployment.Name) if err != nil { errList = append(errList, err.Error()) } @@ -324,7 +324,7 @@ func (as *AgentPool) IncreaseSize(delta int) error { ctx, cancel := getContextWithCancel() defer cancel() klog.V(3).Infof("Waiting for deploymentClient.CreateOrUpdate(%s, %s, %v)", as.manager.config.ResourceGroup, newDeploymentName, newDeployment) - retryErr := as.manager.azureClients.deploymentClient.CreateOrUpdate(ctx, as.manager.config.ResourceGroup, newDeploymentName, newDeployment, "") + retryErr := as.manager.azClient.deploymentClient.CreateOrUpdate(ctx, as.manager.config.ResourceGroup, newDeploymentName, newDeployment, "") if err != nil { klog.Errorf("deploymentClient.CreateOrUpdate for deployment %q failed: %v", newDeploymentName, retryErr) return retryErr.Error() @@ -507,7 +507,7 @@ func (as *AgentPool) deleteBlob(accountName, vhdContainer, vhdBlob string) error ctx, cancel := getContextWithCancel() defer cancel() - storageKeysResult, rerr := as.manager.azureClients.storageAccountsClient.ListKeys(ctx, as.manager.config.SubscriptionID, as.manager.config.ResourceGroup, accountName) + storageKeysResult, rerr := as.manager.azClient.storageAccountsClient.ListKeys(ctx, as.manager.config.SubscriptionID, as.manager.config.ResourceGroup, accountName) if rerr != nil { return rerr.Error() } @@ -530,7 +530,7 @@ func (as *AgentPool) deleteVirtualMachine(name string) error { ctx, cancel := getContextWithCancel() defer cancel() - vm, rerr := as.manager.azureClients.virtualMachinesClient.Get(ctx, as.manager.config.ResourceGroup, name, "") + vm, rerr := as.manager.azClient.virtualMachinesClient.Get(ctx, as.manager.config.ResourceGroup, name, "") if rerr != nil { if exists, _ := checkResourceExistsFromRetryError(rerr); !exists { klog.V(2).Infof("VirtualMachine %s/%s has already been removed", as.manager.config.ResourceGroup, name) @@ -566,7 +566,7 @@ func (as *AgentPool) deleteVirtualMachine(name string) error { defer deleteCancel() klog.Infof("waiting for VirtualMachine deletion: %s/%s", as.manager.config.ResourceGroup, name) - rerr = as.manager.azureClients.virtualMachinesClient.Delete(deleteCtx, as.manager.config.ResourceGroup, name) + rerr = as.manager.azClient.virtualMachinesClient.Delete(deleteCtx, as.manager.config.ResourceGroup, name) _, realErr := checkResourceExistsFromRetryError(rerr) if realErr != nil { return realErr @@ -577,7 +577,7 @@ func (as *AgentPool) deleteVirtualMachine(name string) error { klog.Infof("deleting nic: %s/%s", as.manager.config.ResourceGroup, nicName) interfaceCtx, interfaceCancel := getContextWithCancel() defer interfaceCancel() - rerr := as.manager.azureClients.interfacesClient.Delete(interfaceCtx, as.manager.config.ResourceGroup, nicName) + rerr := as.manager.azClient.interfacesClient.Delete(interfaceCtx, as.manager.config.ResourceGroup, nicName) klog.Infof("waiting for nic deletion: %s/%s", as.manager.config.ResourceGroup, nicName) _, realErr := checkResourceExistsFromRetryError(rerr) if realErr != nil { @@ -609,7 +609,7 @@ func (as *AgentPool) deleteVirtualMachine(name string) error { klog.Infof("deleting managed disk: %s/%s", as.manager.config.ResourceGroup, *osDiskName) disksCtx, disksCancel := getContextWithCancel() defer disksCancel() - rerr := as.manager.azureClients.disksClient.Delete(disksCtx, as.manager.config.SubscriptionID, as.manager.config.ResourceGroup, *osDiskName) + rerr := as.manager.azClient.disksClient.Delete(disksCtx, as.manager.config.SubscriptionID, as.manager.config.ResourceGroup, *osDiskName) _, realErr := checkResourceExistsFromRetryError(rerr) if realErr != nil { return realErr diff --git a/cluster-autoscaler/cloudprovider/azure/azure_cache.go b/cluster-autoscaler/cloudprovider/azure/azure_cache.go index 911c42c5d0ba..eb8b4a81e475 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_cache.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_cache.go @@ -46,7 +46,7 @@ var ( type azureCache struct { mutex sync.Mutex interrupt chan struct{} - azureClients *azureClients + azClient *azClient refreshInterval time.Duration // Cache content. @@ -62,10 +62,10 @@ type azureCache struct { skus map[string]*skewer.Cache } -func newAzureCache(client *azureClients, cacheTTL time.Duration, resourceGroup, vmType string, enableDynamicInstanceList bool, defaultLocation string) (*azureCache, error) { +func newAzureCache(client *azClient, cacheTTL time.Duration, resourceGroup, vmType string, enableDynamicInstanceList bool, defaultLocation string) (*azureCache, error) { cache := &azureCache{ interrupt: make(chan struct{}), - azureClients: client, + azClient: client, refreshInterval: cacheTTL, resourceGroup: resourceGroup, vmType: vmType, @@ -207,7 +207,7 @@ func (m *azureCache) fetchVirtualMachines() (map[string][]compute.VirtualMachine ctx, cancel := getContextWithCancel() defer cancel() - result, err := m.azureClients.virtualMachinesClient.List(ctx, m.resourceGroup) + result, err := m.azClient.virtualMachinesClient.List(ctx, m.resourceGroup) if err != nil { klog.Errorf("VirtualMachinesClient.List in resource group %q failed: %v", m.resourceGroup, err) return nil, nil, err.Error() @@ -253,7 +253,7 @@ func (m *azureCache) fetchScaleSets() (map[string]compute.VirtualMachineScaleSet ctx, cancel := getContextWithTimeout(vmssContextTimeout) defer cancel() - result, err := m.azureClients.virtualMachineScaleSetsClient.List(ctx, m.resourceGroup) + result, err := m.azClient.virtualMachineScaleSetsClient.List(ctx, m.resourceGroup) if err != nil { klog.Errorf("VirtualMachineScaleSetsClient.List in resource group %q failed: %v", m.resourceGroup, err) return nil, err.Error() @@ -318,7 +318,7 @@ func (m *azureCache) Unregister(nodeGroup cloudprovider.NodeGroup) bool { func (m *azureCache) fetchSKUs(ctx context.Context, location string) (*skewer.Cache, error) { return skewer.NewCache(ctx, skewer.WithLocation(location), - skewer.WithResourceClient(m.azureClients.skuClient), + skewer.WithResourceClient(m.azClient.skuClient), ) } diff --git a/cluster-autoscaler/cloudprovider/azure/azure_client.go b/cluster-autoscaler/cloudprovider/azure/azure_client.go index 6710ca307645..3c9e25453396 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_client.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_client.go @@ -36,7 +36,7 @@ import ( providerazureconfig "sigs.k8s.io/cloud-provider-azure/pkg/provider/config" ) -type azureClients struct { +type azClient struct { virtualMachineScaleSetsClient vmssclient.Interface virtualMachineScaleSetVMsClient vmssvmclient.Interface virtualMachinesClient vmclient.Interface @@ -62,7 +62,7 @@ func newAuthorizer(config *Config, env *azure.Environment) (autorest.Authorizer, } } -func newAzureClients(cfg *Config, env *azure.Environment) (*azureClients, error) { +func newAzClient(cfg *Config, env *azure.Environment) (*azClient, error) { authorizer, err := newAuthorizer(cfg, env) if err != nil { return nil, err @@ -105,7 +105,7 @@ func newAzureClients(cfg *Config, env *azure.Environment) (*azureClients, error) skuClient.Authorizer = azClientConfig.Authorizer klog.V(5).Infof("Created sku client with authorizer: %v", skuClient) - return &azureClients{ + return &azClient{ disksClient: disksClient, interfacesClient: interfacesClient, virtualMachineScaleSetsClient: scaleSetsClient, diff --git a/cluster-autoscaler/cloudprovider/azure/azure_manager.go b/cluster-autoscaler/cloudprovider/azure/azure_manager.go index eeb4268f9e2d..c53c53a7169c 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_manager.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_manager.go @@ -44,9 +44,9 @@ const ( // AzureManager handles Azure communication and data caching. type AzureManager struct { - config *Config - azureClients *azureClients - env azure.Environment + config *Config + azClient *azClient + env azure.Environment azureCache *azureCache lastRefresh time.Time @@ -54,8 +54,8 @@ type AzureManager struct { explicitlyConfigured map[string]bool } -// createAzureManagerInternal allows for a custom azureClients to be passed in by tests. -func createAzureManagerInternal(configReader io.Reader, discoveryOpts cloudprovider.NodeGroupDiscoveryOptions, azureClients *azureClients) (*AzureManager, error) { +// createAzureManagerInternal allows for a custom azClient to be passed in by tests. +func createAzureManagerInternal(configReader io.Reader, discoveryOpts cloudprovider.NodeGroupDiscoveryOptions, azClient *azClient) (*AzureManager, error) { cfg, err := BuildAzureConfig(configReader) if err != nil { return nil, err @@ -72,8 +72,8 @@ func createAzureManagerInternal(configReader io.Reader, discoveryOpts cloudprovi klog.Infof("Starting azure manager with subscription ID %q", cfg.SubscriptionID) - if azureClients == nil { - azureClients, err = newAzureClients(cfg, &env) + if azClient == nil { + azClient, err = newAzClient(cfg, &env) if err != nil { return nil, err } @@ -83,7 +83,7 @@ func createAzureManagerInternal(configReader io.Reader, discoveryOpts cloudprovi manager := &AzureManager{ config: cfg, env: env, - azureClients: azureClients, + azClient: azClient, explicitlyConfigured: make(map[string]bool), } @@ -91,7 +91,7 @@ func createAzureManagerInternal(configReader io.Reader, discoveryOpts cloudprovi if cfg.VmssCacheTTLInSeconds != 0 { cacheTTL = time.Duration(cfg.VmssCacheTTLInSeconds) * time.Second } - cache, err := newAzureCache(azureClients, cacheTTL, cfg.ResourceGroup, cfg.VMType, cfg.EnableDynamicInstanceList, cfg.Location) + cache, err := newAzureCache(azClient, cacheTTL, cfg.ResourceGroup, cfg.VMType, cfg.EnableDynamicInstanceList, cfg.Location) if err != nil { return nil, err } diff --git a/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go b/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go index e9d603d59ac8..e825f252fb18 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_scale_set.go @@ -194,7 +194,7 @@ func (scaleSet *ScaleSet) waitForDeleteInstances(future *azure.Future, requiredI defer cancel() klog.V(3).Infof("Calling virtualMachineScaleSetsClient.WaitForDeleteInstancesResult(%v) for %s", requiredIds.InstanceIds, scaleSet.Name) - httpResponse, err := scaleSet.manager.azureClients.virtualMachineScaleSetsClient.WaitForDeleteInstancesResult(ctx, future, scaleSet.manager.config.ResourceGroup) + httpResponse, err := scaleSet.manager.azClient.virtualMachineScaleSetsClient.WaitForDeleteInstancesResult(ctx, future, scaleSet.manager.config.ResourceGroup) isSuccess, err := isSuccessHTTPResponse(httpResponse, err) if isSuccess { klog.V(3).Infof("virtualMachineScaleSetsClient.WaitForDeleteInstancesResult(%v) for %s success", requiredIds.InstanceIds, scaleSet.Name) @@ -220,7 +220,7 @@ func (scaleSet *ScaleSet) updateVMSSCapacity(future *azure.Future) { defer cancel() klog.V(3).Infof("Calling virtualMachineScaleSetsClient.WaitForCreateOrUpdateResult(%s)", scaleSet.Name) - httpResponse, err := scaleSet.manager.azureClients.virtualMachineScaleSetsClient.WaitForCreateOrUpdateResult(ctx, future, scaleSet.manager.config.ResourceGroup) + httpResponse, err := scaleSet.manager.azClient.virtualMachineScaleSetsClient.WaitForCreateOrUpdateResult(ctx, future, scaleSet.manager.config.ResourceGroup) isSuccess, err := isSuccessHTTPResponse(httpResponse, err) if isSuccess { @@ -267,7 +267,7 @@ func (scaleSet *ScaleSet) SetScaleSetSize(size int64) error { ctx, cancel := getContextWithTimeout(vmssContextTimeout) defer cancel() klog.V(3).Infof("Waiting for virtualMachineScaleSetsClient.CreateOrUpdateAsync(%s)", scaleSet.Name) - future, rerr := scaleSet.manager.azureClients.virtualMachineScaleSetsClient.CreateOrUpdateAsync(ctx, scaleSet.manager.config.ResourceGroup, scaleSet.Name, op) + future, rerr := scaleSet.manager.azClient.virtualMachineScaleSetsClient.CreateOrUpdateAsync(ctx, scaleSet.manager.config.ResourceGroup, scaleSet.Name, op) if rerr != nil { klog.Errorf("virtualMachineScaleSetsClient.CreateOrUpdate for scale set %q failed: %v", scaleSet.Name, rerr) return rerr.Error() @@ -322,7 +322,7 @@ func (scaleSet *ScaleSet) GetScaleSetVms() ([]compute.VirtualMachineScaleSetVM, defer cancel() resourceGroup := scaleSet.manager.config.ResourceGroup - vmList, rerr := scaleSet.manager.azureClients.virtualMachineScaleSetVMsClient.List(ctx, resourceGroup, scaleSet.Name, "instanceView") + vmList, rerr := scaleSet.manager.azClient.virtualMachineScaleSetVMsClient.List(ctx, resourceGroup, scaleSet.Name, "instanceView") klog.V(4).Infof("GetScaleSetVms: scaleSet.Name: %s, vmList: %v", scaleSet.Name, vmList) if rerr != nil { klog.Errorf("VirtualMachineScaleSetVMsClient.List failed for %s: %v", scaleSet.Name, rerr) @@ -348,7 +348,7 @@ func (scaleSet *ScaleSet) GetFlexibleScaleSetVms() ([]compute.VirtualMachine, *r } return nil, rerr } - vmList, rerr := scaleSet.manager.azureClients.virtualMachinesClient.ListVmssFlexVMsWithoutInstanceView(ctx, *vmssInfo.ID) + vmList, rerr := scaleSet.manager.azClient.virtualMachinesClient.ListVmssFlexVMsWithoutInstanceView(ctx, *vmssInfo.ID) if rerr != nil { klog.Errorf("VirtualMachineScaleSetVMsClient.List failed for %s: %v", scaleSet.Name, rerr) return nil, rerr @@ -451,11 +451,11 @@ func (scaleSet *ScaleSet) DeleteInstances(instances []*azureRef, hasUnregistered scaleSet.instanceMutex.Lock() klog.V(3).Infof("Calling virtualMachineScaleSetsClient.DeleteInstancesAsync(%v), force delete set to %v", requiredIds.InstanceIds, scaleSet.enableForceDelete) - future, rerr := scaleSet.manager.azureClients.virtualMachineScaleSetsClient.DeleteInstancesAsync(ctx, resourceGroup, commonAsg.Id(), *requiredIds, scaleSet.enableForceDelete) + future, rerr := scaleSet.manager.azClient.virtualMachineScaleSetsClient.DeleteInstancesAsync(ctx, resourceGroup, commonAsg.Id(), *requiredIds, scaleSet.enableForceDelete) if scaleSet.enableForceDelete && isOperationNotAllowed(rerr) { klog.Infof("falling back to normal delete for instances %v for %s", requiredIds.InstanceIds, scaleSet.Name) - future, rerr = scaleSet.manager.azureClients.virtualMachineScaleSetsClient.DeleteInstancesAsync(ctx, resourceGroup, + future, rerr = scaleSet.manager.azClient.virtualMachineScaleSetsClient.DeleteInstancesAsync(ctx, resourceGroup, commonAsg.Id(), *requiredIds, false) } diff --git a/cluster-autoscaler/cloudprovider/azure/azure_util.go b/cluster-autoscaler/cloudprovider/azure/azure_util.go index 80dfe767b4c2..96de93d9cee4 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_util.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_util.go @@ -113,7 +113,7 @@ func (util *AzUtil) DeleteBlob(accountName, vhdContainer, vhdBlob string) error ctx, cancel := getContextWithCancel() defer cancel() - storageKeysResult, rerr := util.manager.azureClients.storageAccountsClient.ListKeys(ctx, util.manager.config.SubscriptionID, util.manager.config.ResourceGroup, accountName) + storageKeysResult, rerr := util.manager.azClient.storageAccountsClient.ListKeys(ctx, util.manager.config.SubscriptionID, util.manager.config.ResourceGroup, accountName) if rerr != nil { return rerr.Error() } @@ -136,7 +136,7 @@ func (util *AzUtil) DeleteVirtualMachine(rg string, name string) error { ctx, cancel := getContextWithCancel() defer cancel() - vm, rerr := util.manager.azureClients.virtualMachinesClient.Get(ctx, rg, name, "") + vm, rerr := util.manager.azClient.virtualMachinesClient.Get(ctx, rg, name, "") if rerr != nil { if exists, _ := checkResourceExistsFromRetryError(rerr); !exists { klog.V(2).Infof("VirtualMachine %s/%s has already been removed", rg, name) @@ -173,7 +173,7 @@ func (util *AzUtil) DeleteVirtualMachine(rg string, name string) error { defer deleteCancel() klog.Infof("waiting for VirtualMachine deletion: %s/%s", rg, name) - rerr = util.manager.azureClients.virtualMachinesClient.Delete(deleteCtx, rg, name) + rerr = util.manager.azClient.virtualMachinesClient.Delete(deleteCtx, rg, name) _, realErr := checkResourceExistsFromRetryError(rerr) if realErr != nil { return realErr @@ -185,7 +185,7 @@ func (util *AzUtil) DeleteVirtualMachine(rg string, name string) error { interfaceCtx, interfaceCancel := getContextWithCancel() defer interfaceCancel() klog.Infof("waiting for nic deletion: %s/%s", rg, nicName) - nicErr := util.manager.azureClients.interfacesClient.Delete(interfaceCtx, rg, nicName) + nicErr := util.manager.azClient.interfacesClient.Delete(interfaceCtx, rg, nicName) _, realErr := checkResourceExistsFromRetryError(nicErr) if realErr != nil { return realErr @@ -216,7 +216,7 @@ func (util *AzUtil) DeleteVirtualMachine(rg string, name string) error { klog.Infof("deleting managed disk: %s/%s", rg, *osDiskName) disksCtx, disksCancel := getContextWithCancel() defer disksCancel() - diskErr := util.manager.azureClients.disksClient.Delete(disksCtx, util.manager.config.SubscriptionID, rg, *osDiskName) + diskErr := util.manager.azClient.disksClient.Delete(disksCtx, util.manager.config.SubscriptionID, rg, *osDiskName) _, realErr := checkResourceExistsFromRetryError(diskErr) if realErr != nil { return realErr