From 6c2c5c2614273e3322825de82cb817a13ab936de Mon Sep 17 00:00:00 2001 From: Pengfei Ni Date: Thu, 25 Jan 2018 16:14:48 +0800 Subject: [PATCH] Clean up unused functions and consts --- pkg/cloudprovider/providers/azure/azure.go | 5 -- .../azure/azure_blobDiskController.go | 18 ------- .../providers/azure/azure_controllerCommon.go | 11 +---- .../providers/azure/azure_instances.go | 6 --- .../providers/azure/azure_standard.go | 31 ------------ .../providers/azure/azure_test.go | 9 ++-- .../providers/azure/azure_wrap.go | 48 ------------------- 7 files changed, 7 insertions(+), 121 deletions(-) diff --git a/pkg/cloudprovider/providers/azure/azure.go b/pkg/cloudprovider/providers/azure/azure.go index 9070be894d..958c9d76b5 100644 --- a/pkg/cloudprovider/providers/azure/azure.go +++ b/pkg/cloudprovider/providers/azure/azure.go @@ -311,14 +311,9 @@ func initDiskControllers(az *Cloud) error { // needed by both blob disk and managed disk controllers common := &controllerCommon{ - aadResourceEndPoint: az.Environment.ServiceManagementEndpoint, - clientID: az.AADClientID, - clientSecret: az.AADClientSecret, location: az.Location, storageEndpointSuffix: az.Environment.StorageEndpointSuffix, - managementEndpoint: az.Environment.ResourceManagerEndpoint, resourceGroup: az.ResourceGroup, - tokenEndPoint: az.Environment.ActiveDirectoryEndpoint, subscriptionID: az.SubscriptionID, cloud: az, } diff --git a/pkg/cloudprovider/providers/azure/azure_blobDiskController.go b/pkg/cloudprovider/providers/azure/azure_blobDiskController.go index e68c23b896..f55c96d8b4 100644 --- a/pkg/cloudprovider/providers/azure/azure_blobDiskController.go +++ b/pkg/cloudprovider/providers/azure/azure_blobDiskController.go @@ -637,18 +637,6 @@ func (c *BlobDiskController) getNextAccountNum() int { return max + 1 } -func (c *BlobDiskController) deleteStorageAccount(storageAccountName string) error { - resp, err := c.common.cloud.StorageAccountClient.Delete(c.common.resourceGroup, storageAccountName) - if err != nil { - return fmt.Errorf("azureDisk - Delete of storage account '%s' failed with status %s...%v", storageAccountName, resp.Status, err) - } - - c.removeAccountState(storageAccountName) - - glog.Infof("azureDisk - Storage Account %s was deleted", storageAccountName) - return nil -} - //Gets storage account exist, provisionStatus, Error if any func (c *BlobDiskController) getStorageAccountState(storageAccountName string) (bool, storage.ProvisioningState, error) { account, err := c.common.cloud.StorageAccountClient.GetProperties(c.common.resourceGroup, storageAccountName) @@ -667,12 +655,6 @@ func (c *BlobDiskController) addAccountState(key string, state *storageAccountSt } } -func (c *BlobDiskController) removeAccountState(key string) { - accountsLock.Lock() - defer accountsLock.Unlock() - delete(c.accounts, key) -} - // pads account num with zeros as needed func getAccountNameForNum(num int) string { sNum := strconv.Itoa(num) diff --git a/pkg/cloudprovider/providers/azure/azure_controllerCommon.go b/pkg/cloudprovider/providers/azure/azure_controllerCommon.go index 8cef635c3b..bbb056afd4 100644 --- a/pkg/cloudprovider/providers/azure/azure_controllerCommon.go +++ b/pkg/cloudprovider/providers/azure/azure_controllerCommon.go @@ -30,14 +30,12 @@ import ( ) const ( - defaultDataDiskCount int = 16 // which will allow you to work with most medium size VMs (if not found in map) - storageAccountNameTemplate = "pvc%s" + storageAccountNameTemplate = "pvc%s" // for limits check https://docs.microsoft.com/en-us/azure/azure-subscription-service-limits#storage-limits maxStorageAccounts = 100 // max # is 200 (250 with special request). this allows 100 for everything else including stand alone disks maxDisksPerStorageAccounts = 60 storageAccountUtilizationBeforeGrowing = 0.5 - storageAccountsCountInit = 2 // When the plug-in is init-ed, 2 storage accounts will be created to allow fast pvc create/attach/mount maxLUN = 64 // max number of LUNs per VM errLeaseFailed = "AcquireDiskLeaseFailed" @@ -58,13 +56,6 @@ type controllerCommon struct { location string storageEndpointSuffix string resourceGroup string - clientID string - clientSecret string - managementEndpoint string - tokenEndPoint string - aadResourceEndPoint string - aadToken string - expiresOn time.Time cloud *Cloud } diff --git a/pkg/cloudprovider/providers/azure/azure_instances.go b/pkg/cloudprovider/providers/azure/azure_instances.go index 9f93c80750..ef7bd635c6 100644 --- a/pkg/cloudprovider/providers/azure/azure_instances.go +++ b/pkg/cloudprovider/providers/azure/azure_instances.go @@ -119,9 +119,3 @@ func (az *Cloud) CurrentNodeName(hostname string) (types.NodeName, error) { func mapNodeNameToVMName(nodeName types.NodeName) string { return string(nodeName) } - -// mapVMNameToNodeName maps an Azure VM Name to a k8s NodeName -// This is a simple string cast. -func mapVMNameToNodeName(vmName string) types.NodeName { - return types.NodeName(vmName) -} diff --git a/pkg/cloudprovider/providers/azure/azure_standard.go b/pkg/cloudprovider/providers/azure/azure_standard.go index 0ebcff0210..8667bc15d0 100644 --- a/pkg/cloudprovider/providers/azure/azure_standard.go +++ b/pkg/cloudprovider/providers/azure/azure_standard.go @@ -45,9 +45,7 @@ const ( availabilitySetIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/availabilitySets/%s" frontendIPConfigIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadBalancers/%s/frontendIPConfigurations/%s" backendPoolIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadBalancers/%s/backendAddressPools/%s" - loadBalancerRuleIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadBalancers/%s/loadBalancingRules/%s" loadBalancerProbeIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadBalancers/%s/probes/%s" - securityRuleIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s/securityRules/%s" // InternalLoadBalancerNameSuffix is load balancer posfix InternalLoadBalancerNameSuffix = "-internal" @@ -97,16 +95,6 @@ func (az *Cloud) getBackendPoolID(lbName, backendPoolName string) string { backendPoolName) } -// returns the full identifier of a loadbalancer rule. -func (az *Cloud) getLoadBalancerRuleID(lbName, lbRuleName string) string { - return fmt.Sprintf( - loadBalancerRuleIDTemplate, - az.SubscriptionID, - az.ResourceGroup, - lbName, - lbRuleName) -} - // returns the full identifier of a loadbalancer probe. func (az *Cloud) getLoadBalancerProbeID(lbName, lbRuleName string) string { return fmt.Sprintf( @@ -117,25 +105,6 @@ func (az *Cloud) getLoadBalancerProbeID(lbName, lbRuleName string) string { lbRuleName) } -// returns the full identifier of a network security group security rule. -func (az *Cloud) getSecurityRuleID(securityRuleName string) string { - return fmt.Sprintf( - securityRuleIDTemplate, - az.SubscriptionID, - az.ResourceGroup, - az.SecurityGroupName, - securityRuleName) -} - -// returns the full identifier of a publicIPAddress. -func (az *Cloud) getpublicIPAddressID(pipName string) string { - return fmt.Sprintf( - publicIPAddressIDTemplate, - az.SubscriptionID, - az.ResourceGroup, - pipName) -} - func (az *Cloud) mapLoadBalancerNameToVMSet(lbName string, clusterName string) (vmSetName string) { vmSetName = strings.TrimSuffix(lbName, InternalLoadBalancerNameSuffix) if strings.EqualFold(clusterName, lbName) { diff --git a/pkg/cloudprovider/providers/azure/azure_test.go b/pkg/cloudprovider/providers/azure/azure_test.go index c42b9be3d0..5fab9e965b 100644 --- a/pkg/cloudprovider/providers/azure/azure_test.go +++ b/pkg/cloudprovider/providers/azure/azure_test.go @@ -861,14 +861,17 @@ func getTestCloud() (az *Cloud) { MaximumLoadBalancerRuleCount: 250, }, } + az.DisksClient = newFakeDisksClient() + az.InterfacesClient = newFakeAzureInterfacesClient() az.LoadBalancerClient = newFakeAzureLBClient() az.PublicIPAddressesClient = newFakeAzurePIPClient(az.Config.SubscriptionID) - az.SubnetsClient = newFakeAzureSubnetsClient() + az.RoutesClient = newFakeRoutesClient() + az.RouteTablesClient = newFakeRouteTablesClient() az.SecurityGroupsClient = newFakeAzureNSGClient() - az.VirtualMachinesClient = newFakeAzureVirtualMachinesClient() - az.InterfacesClient = newFakeAzureInterfacesClient() + az.SubnetsClient = newFakeAzureSubnetsClient() az.VirtualMachineScaleSetsClient = newFakeVirtualMachineScaleSetsClient() az.VirtualMachineScaleSetVMsClient = newFakeVirtualMachineScaleSetVMsClient() + az.VirtualMachinesClient = newFakeAzureVirtualMachinesClient() az.vmSet = newAvailabilitySet(az) return az diff --git a/pkg/cloudprovider/providers/azure/azure_wrap.go b/pkg/cloudprovider/providers/azure/azure_wrap.go index 144cdc0aaa..d80ac4455c 100644 --- a/pkg/cloudprovider/providers/azure/azure_wrap.go +++ b/pkg/cloudprovider/providers/azure/azure_wrap.go @@ -131,54 +131,6 @@ func (az *Cloud) getRouteTable() (routeTable network.RouteTable, exists bool, er return routeTable, exists, err } -func (az *Cloud) getSecurityGroup() (sg network.SecurityGroup, exists bool, err error) { - var realErr error - - sg, err = az.SecurityGroupsClient.Get(az.ResourceGroup, az.SecurityGroupName, "") - exists, realErr = checkResourceExistsFromError(err) - if realErr != nil { - return sg, false, realErr - } - - if !exists { - return sg, false, nil - } - - return sg, exists, err -} - -func (az *Cloud) getAzureLoadBalancer(name string) (lb network.LoadBalancer, exists bool, err error) { - var realErr error - - lb, err = az.LoadBalancerClient.Get(az.ResourceGroup, name, "") - exists, realErr = checkResourceExistsFromError(err) - if realErr != nil { - return lb, false, realErr - } - - if !exists { - return lb, false, nil - } - - return lb, exists, err -} - -func (az *Cloud) listLoadBalancers() (lbListResult network.LoadBalancerListResult, exists bool, err error) { - var realErr error - - lbListResult, err = az.LoadBalancerClient.List(az.ResourceGroup) - exists, realErr = checkResourceExistsFromError(err) - if realErr != nil { - return lbListResult, false, realErr - } - - if !exists { - return lbListResult, false, nil - } - - return lbListResult, exists, err -} - func (az *Cloud) getPublicIPAddress(pipResourceGroup string, pipName string) (pip network.PublicIPAddress, exists bool, err error) { resourceGroup := az.ResourceGroup if pipResourceGroup != "" {