From d7650e582ec8da003f40442260a33d42a7173d31 Mon Sep 17 00:00:00 2001 From: Pengfei Ni Date: Sun, 26 Jan 2020 21:38:18 +0800 Subject: [PATCH] Cleanup unused Azure client interfaces --- .../k8s.io/legacy-cloud-providers/azure/BUILD | 1 - .../legacy-cloud-providers/azure/azure.go | 28 ++-- .../azure/azure_client.go | 142 ------------------ .../azure/azure_utils.go | 5 + .../azure/azure_vmss.go | 3 + 5 files changed, 22 insertions(+), 157 deletions(-) delete mode 100644 staging/src/k8s.io/legacy-cloud-providers/azure/azure_client.go diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/BUILD b/staging/src/k8s.io/legacy-cloud-providers/azure/BUILD index d37f3e462df..a2cc60d9389 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/BUILD +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/BUILD @@ -13,7 +13,6 @@ go_library( "azure_backoff.go", "azure_blobDiskController.go", "azure_cache.go", - "azure_client.go", "azure_config.go", "azure_controller_common.go", "azure_controller_standard.go", diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go index 9f046960ebf..466f06bfd33 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go @@ -227,21 +227,21 @@ type Cloud struct { Config Environment azure.Environment - RoutesClient RoutesClient - SubnetsClient SubnetsClient - InterfacesClient InterfacesClient - RouteTablesClient RouteTablesClient - LoadBalancerClient LoadBalancersClient - PublicIPAddressesClient PublicIPAddressesClient - SecurityGroupsClient SecurityGroupsClient - VirtualMachinesClient VirtualMachinesClient - StorageAccountClient StorageAccountClient - DisksClient DisksClient - SnapshotsClient SnapshotsClient + RoutesClient routeclient.Interface + SubnetsClient subnetclient.Interface + InterfacesClient interfaceclient.Interface + RouteTablesClient routetableclient.Interface + LoadBalancerClient loadbalancerclient.Interface + PublicIPAddressesClient publicipclient.Interface + SecurityGroupsClient securitygroupclient.Interface + VirtualMachinesClient vmclient.Interface + StorageAccountClient storageaccountclient.Interface + DisksClient diskclient.Interface + SnapshotsClient snapshotclient.Interface FileClient FileClient - VirtualMachineScaleSetsClient VirtualMachineScaleSetsClient - VirtualMachineScaleSetVMsClient VirtualMachineScaleSetVMsClient - VirtualMachineSizesClient VirtualMachineSizesClient + VirtualMachineScaleSetsClient vmssclient.Interface + VirtualMachineScaleSetVMsClient vmssvmclient.Interface + VirtualMachineSizesClient vmsizeclient.Interface ResourceRequestBackoff wait.Backoff metadata *InstanceMetadataService diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_client.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_client.go deleted file mode 100644 index cb5211a5399..00000000000 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_client.go +++ /dev/null @@ -1,142 +0,0 @@ -// +build !providerless - -/* -Copyright 2017 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package azure - -import ( - "context" - - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" - "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" - - "k8s.io/legacy-cloud-providers/azure/retry" -) - -const ( - // The version number is taken from "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network". - azureNetworkAPIVersion = "2019-06-01" - virtualMachineScaleSetsDeallocating = "Deallocating" -) - -// VirtualMachinesClient defines needed functions for azure compute.VirtualMachinesClient -type VirtualMachinesClient interface { - CreateOrUpdate(ctx context.Context, resourceGroupName string, VMName string, parameters compute.VirtualMachine, source string) *retry.Error - Update(ctx context.Context, resourceGroupName string, VMName string, parameters compute.VirtualMachineUpdate, source string) *retry.Error - Get(ctx context.Context, resourceGroupName string, VMName string, expand compute.InstanceViewTypes) (result compute.VirtualMachine, rerr *retry.Error) - List(ctx context.Context, resourceGroupName string) (result []compute.VirtualMachine, rerr *retry.Error) -} - -// InterfacesClient defines needed functions for azure network.InterfacesClient -type InterfacesClient interface { - CreateOrUpdate(ctx context.Context, resourceGroupName string, networkInterfaceName string, parameters network.Interface) *retry.Error - Get(ctx context.Context, resourceGroupName string, networkInterfaceName string, expand string) (result network.Interface, rerr *retry.Error) - GetVirtualMachineScaleSetNetworkInterface(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string, expand string) (result network.Interface, rerr *retry.Error) -} - -// LoadBalancersClient defines needed functions for azure network.LoadBalancersClient -type LoadBalancersClient interface { - CreateOrUpdate(ctx context.Context, resourceGroupName string, loadBalancerName string, parameters network.LoadBalancer, etag string) *retry.Error - Delete(ctx context.Context, resourceGroupName string, loadBalancerName string) *retry.Error - Get(ctx context.Context, resourceGroupName string, loadBalancerName string, expand string) (result network.LoadBalancer, rerr *retry.Error) - List(ctx context.Context, resourceGroupName string) (result []network.LoadBalancer, rerr *retry.Error) -} - -// PublicIPAddressesClient defines needed functions for azure network.PublicIPAddressesClient -type PublicIPAddressesClient interface { - CreateOrUpdate(ctx context.Context, resourceGroupName string, publicIPAddressName string, parameters network.PublicIPAddress) *retry.Error - Delete(ctx context.Context, resourceGroupName string, publicIPAddressName string) *retry.Error - Get(ctx context.Context, resourceGroupName string, publicIPAddressName string, expand string) (result network.PublicIPAddress, rerr *retry.Error) - GetVirtualMachineScaleSetPublicIPAddress(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string, IPConfigurationName string, publicIPAddressName string, expand string) (result network.PublicIPAddress, rerr *retry.Error) - List(ctx context.Context, resourceGroupName string) (result []network.PublicIPAddress, rerr *retry.Error) -} - -// SubnetsClient defines needed functions for azure network.SubnetsClient -type SubnetsClient interface { - CreateOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, subnetParameters network.Subnet) *retry.Error - Delete(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string) *retry.Error - Get(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, expand string) (result network.Subnet, rerr *retry.Error) - List(ctx context.Context, resourceGroupName string, virtualNetworkName string) (result []network.Subnet, rerr *retry.Error) -} - -// SecurityGroupsClient defines needed functions for azure network.SecurityGroupsClient -type SecurityGroupsClient interface { - CreateOrUpdate(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, parameters network.SecurityGroup, etag string) *retry.Error - Delete(ctx context.Context, resourceGroupName string, networkSecurityGroupName string) *retry.Error - Get(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, expand string) (result network.SecurityGroup, rerr *retry.Error) - List(ctx context.Context, resourceGroupName string) (result []network.SecurityGroup, rerr *retry.Error) -} - -// VirtualMachineScaleSetsClient defines needed functions for azure compute.VirtualMachineScaleSetsClient -type VirtualMachineScaleSetsClient interface { - Get(ctx context.Context, resourceGroupName string, VMScaleSetName string) (result compute.VirtualMachineScaleSet, rerr *retry.Error) - List(ctx context.Context, resourceGroupName string) (result []compute.VirtualMachineScaleSet, rerr *retry.Error) - CreateOrUpdate(ctx context.Context, resourceGroupName string, VMScaleSetName string, parameters compute.VirtualMachineScaleSet) *retry.Error -} - -// VirtualMachineScaleSetVMsClient defines needed functions for azure compute.VirtualMachineScaleSetVMsClient -type VirtualMachineScaleSetVMsClient interface { - Get(ctx context.Context, resourceGroupName string, VMScaleSetName string, instanceID string, expand compute.InstanceViewTypes) (result compute.VirtualMachineScaleSetVM, rerr *retry.Error) - List(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string, expand string) (result []compute.VirtualMachineScaleSetVM, rerr *retry.Error) - Update(ctx context.Context, resourceGroupName string, VMScaleSetName string, instanceID string, parameters compute.VirtualMachineScaleSetVM, source string) *retry.Error -} - -// RoutesClient defines needed functions for azure network.RoutesClient -type RoutesClient interface { - CreateOrUpdate(ctx context.Context, resourceGroupName string, routeTableName string, routeName string, routeParameters network.Route, etag string) *retry.Error - Delete(ctx context.Context, resourceGroupName string, routeTableName string, routeName string) *retry.Error -} - -// RouteTablesClient defines needed functions for azure network.RouteTablesClient -type RouteTablesClient interface { - CreateOrUpdate(ctx context.Context, resourceGroupName string, routeTableName string, parameters network.RouteTable, etag string) *retry.Error - Get(ctx context.Context, resourceGroupName string, routeTableName string, expand string) (result network.RouteTable, rerr *retry.Error) -} - -// StorageAccountClient defines needed functions for azure storage.AccountsClient -type StorageAccountClient interface { - Create(ctx context.Context, resourceGroupName string, accountName string, parameters storage.AccountCreateParameters) *retry.Error - Delete(ctx context.Context, resourceGroupName string, accountName string) *retry.Error - ListKeys(ctx context.Context, resourceGroupName string, accountName string) (result storage.AccountListKeysResult, rerr *retry.Error) - ListByResourceGroup(ctx context.Context, resourceGroupName string) (result []storage.Account, rerr *retry.Error) - GetProperties(ctx context.Context, resourceGroupName string, accountName string) (result storage.Account, rerr *retry.Error) -} - -// SnapshotsClient defines needed functions for azure compute.SnapshotsClient -type SnapshotsClient interface { - Get(ctx context.Context, resourceGroupName string, snapshotName string) (compute.Snapshot, *retry.Error) - Delete(ctx context.Context, resourceGroupName string, snapshotName string) *retry.Error - ListByResourceGroup(ctx context.Context, resourceGroupName string) ([]compute.Snapshot, *retry.Error) - CreateOrUpdate(ctx context.Context, resourceGroupName string, snapshotName string, snapshot compute.Snapshot) *retry.Error -} - -// DisksClient defines needed functions for azure compute.DisksClient -type DisksClient interface { - CreateOrUpdate(ctx context.Context, resourceGroupName string, diskName string, diskParameter compute.Disk) *retry.Error - Delete(ctx context.Context, resourceGroupName string, diskName string) *retry.Error - Get(ctx context.Context, resourceGroupName string, diskName string) (result compute.Disk, rerr *retry.Error) -} - -// VirtualMachineSizesClient defines needed functions for azure compute.VirtualMachineSizesClient -type VirtualMachineSizesClient interface { - List(ctx context.Context, location string) (result compute.VirtualMachineSizeListResult, rerr *retry.Error) -} - -func getContextWithCancel() (context.Context, context.CancelFunc) { - return context.WithCancel(context.Background()) -} diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_utils.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_utils.go index d4b5aba8015..78ca666bddd 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_utils.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_utils.go @@ -19,6 +19,7 @@ limitations under the License. package azure import ( + "context" "sync" ) @@ -69,3 +70,7 @@ func (lm *lockMap) lockEntry(entry string) { func (lm *lockMap) unlockEntry(entry string) { lm.mutexMap[entry].Unlock() } + +func getContextWithCancel() (context.Context, context.CancelFunc) { + return context.WithCancel(context.Background()) +} diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go index b7950a40d84..565aaac5ef4 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go @@ -40,6 +40,9 @@ import ( ) var ( + // virtualMachineScaleSetsDeallocating indicates VMSS instances are in Deallocating state. + virtualMachineScaleSetsDeallocating = "Deallocating" + // ErrorNotVmssInstance indicates an instance is not belongint to any vmss. ErrorNotVmssInstance = errors.New("not a vmss instance")