@@ -23,32 +23,22 @@ import (
2323 "net/http"
2424 "time"
2525
26- "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
2726 "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2018-03-31/containerservice"
28- "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network"
2927 "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2017-05-10/resources"
3028 "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2018-07-01/storage"
3129 "github.com/Azure/go-autorest/autorest"
3230 "github.com/Azure/go-autorest/autorest/adal"
3331 "github.com/Azure/go-autorest/autorest/azure"
3432
3533 "k8s.io/klog"
34+ "k8s.io/legacy-cloud-providers/azure/clients/diskclient"
35+ "k8s.io/legacy-cloud-providers/azure/clients/interfaceclient"
36+ "k8s.io/legacy-cloud-providers/azure/clients/storageaccountclient"
37+ "k8s.io/legacy-cloud-providers/azure/clients/vmclient"
3638 "k8s.io/legacy-cloud-providers/azure/clients/vmssclient"
3739 "k8s.io/legacy-cloud-providers/azure/clients/vmssvmclient"
3840)
3941
40- // VirtualMachinesClient defines needed functions for azure compute.VirtualMachinesClient.
41- type VirtualMachinesClient interface {
42- Get (ctx context.Context , resourceGroupName string , VMName string , expand compute.InstanceViewTypes ) (result compute.VirtualMachine , err error )
43- Delete (ctx context.Context , resourceGroupName string , VMName string ) (resp * http.Response , err error )
44- List (ctx context.Context , resourceGroupName string ) (result []compute.VirtualMachine , err error )
45- }
46-
47- // InterfacesClient defines needed functions for azure network.InterfacesClient.
48- type InterfacesClient interface {
49- Delete (ctx context.Context , resourceGroupName string , networkInterfaceName string ) (resp * http.Response , err error )
50- }
51-
5242// DeploymentsClient defines needed functions for azure network.DeploymentsClient.
5343type DeploymentsClient interface {
5444 Get (ctx context.Context , resourceGroupName string , deploymentName string ) (result resources.DeploymentExtended , err error )
@@ -58,111 +48,6 @@ type DeploymentsClient interface {
5848 Delete (ctx context.Context , resourceGroupName string , deploymentName string ) (resp * http.Response , err error )
5949}
6050
61- // DisksClient defines needed functions for azure disk.DisksClient.
62- type DisksClient interface {
63- Delete (ctx context.Context , resourceGroupName string , diskName string ) (resp * http.Response , err error )
64- }
65-
66- // AccountsClient defines needed functions for azure storage.AccountsClient.
67- type AccountsClient interface {
68- ListKeys (ctx context.Context , resourceGroupName string , accountName string ) (result storage.AccountListKeysResult , err error )
69- }
70-
71- // azVirtualMachinesClient implements VirtualMachinesClient.
72- type azVirtualMachinesClient struct {
73- client compute.VirtualMachinesClient
74- }
75-
76- func newAzVirtualMachinesClient (subscriptionID , endpoint string , servicePrincipalToken * adal.ServicePrincipalToken ) * azVirtualMachinesClient {
77- virtualMachinesClient := compute .NewVirtualMachinesClient (subscriptionID )
78- virtualMachinesClient .BaseURI = endpoint
79- virtualMachinesClient .Authorizer = autorest .NewBearerAuthorizer (servicePrincipalToken )
80- virtualMachinesClient .PollingDelay = 5 * time .Second
81- configureUserAgent (& virtualMachinesClient .Client )
82-
83- return & azVirtualMachinesClient {
84- client : virtualMachinesClient ,
85- }
86- }
87-
88- func (az * azVirtualMachinesClient ) Get (ctx context.Context , resourceGroupName string , VMName string , expand compute.InstanceViewTypes ) (result compute.VirtualMachine , err error ) {
89- klog .V (10 ).Infof ("azVirtualMachinesClient.Get(%q,%q,%q): start" , resourceGroupName , VMName , expand )
90- defer func () {
91- klog .V (10 ).Infof ("azVirtualMachinesClient.Get(%q,%q,%q): end" , resourceGroupName , VMName , expand )
92- }()
93-
94- return az .client .Get (ctx , resourceGroupName , VMName , expand )
95- }
96-
97- func (az * azVirtualMachinesClient ) Delete (ctx context.Context , resourceGroupName string , VMName string ) (resp * http.Response , err error ) {
98- klog .V (10 ).Infof ("azVirtualMachinesClient.Delete(%q,%q): start" , resourceGroupName , VMName )
99- defer func () {
100- klog .V (10 ).Infof ("azVirtualMachinesClient.Delete(%q,%q): end" , resourceGroupName , VMName )
101- }()
102-
103- future , err := az .client .Delete (ctx , resourceGroupName , VMName )
104- if err != nil {
105- return future .Response (), err
106- }
107-
108- err = future .WaitForCompletionRef (ctx , az .client .Client )
109- return future .Response (), err
110- }
111-
112- func (az * azVirtualMachinesClient ) List (ctx context.Context , resourceGroupName string ) (result []compute.VirtualMachine , err error ) {
113- klog .V (10 ).Infof ("azVirtualMachinesClient.List(%q): start" , resourceGroupName )
114- defer func () {
115- klog .V (10 ).Infof ("azVirtualMachinesClient.List(%q): end" , resourceGroupName )
116- }()
117-
118- iterator , err := az .client .ListComplete (ctx , resourceGroupName )
119- if err != nil {
120- return nil , err
121- }
122-
123- result = make ([]compute.VirtualMachine , 0 )
124- for ; iterator .NotDone (); err = iterator .Next () {
125- if err != nil {
126- return nil , err
127- }
128-
129- result = append (result , iterator .Value ())
130- }
131-
132- return result , nil
133- }
134-
135- type azInterfacesClient struct {
136- client network.InterfacesClient
137- }
138-
139- func newAzInterfacesClient (subscriptionID , endpoint string , servicePrincipalToken * adal.ServicePrincipalToken ) * azInterfacesClient {
140- interfacesClient := network .NewInterfacesClient (subscriptionID )
141- interfacesClient .BaseURI = endpoint
142- interfacesClient .Authorizer = autorest .NewBearerAuthorizer (servicePrincipalToken )
143- interfacesClient .PollingDelay = 5 * time .Second
144- configureUserAgent (& interfacesClient .Client )
145-
146- return & azInterfacesClient {
147- client : interfacesClient ,
148- }
149- }
150-
151- func (az * azInterfacesClient ) Delete (ctx context.Context , resourceGroupName string , networkInterfaceName string ) (resp * http.Response , err error ) {
152- klog .V (10 ).Infof ("azInterfacesClient.Delete(%q,%q): start" , resourceGroupName , networkInterfaceName )
153- defer func () {
154- klog .V (10 ).Infof ("azInterfacesClient.Delete(%q,%q): end" , resourceGroupName , networkInterfaceName )
155- }()
156-
157- future , err := az .client .Delete (ctx , resourceGroupName , networkInterfaceName )
158- if err != nil {
159- return future .Response (), err
160- }
161-
162- err = future .WaitForCompletionRef (ctx , az .client .Client )
163- return future .Response (), err
164- }
165-
16651type azDeploymentsClient struct {
16752 client resources.DeploymentsClient
16853}
@@ -250,70 +135,18 @@ func (az *azDeploymentsClient) Delete(ctx context.Context, resourceGroupName, de
250135 return future .Response (), err
251136}
252137
253- type azDisksClient struct {
254- client compute.DisksClient
255- }
256-
257- func newAzDisksClient (subscriptionID , endpoint string , servicePrincipalToken * adal.ServicePrincipalToken ) * azDisksClient {
258- disksClient := compute .NewDisksClient (subscriptionID )
259- disksClient .BaseURI = endpoint
260- disksClient .Authorizer = autorest .NewBearerAuthorizer (servicePrincipalToken )
261- disksClient .PollingDelay = 5 * time .Second
262- configureUserAgent (& disksClient .Client )
263-
264- return & azDisksClient {
265- client : disksClient ,
266- }
267- }
268-
269- func (az * azDisksClient ) Delete (ctx context.Context , resourceGroupName string , diskName string ) (resp * http.Response , err error ) {
270- klog .V (10 ).Infof ("azDisksClient.Delete(%q,%q): start" , resourceGroupName , diskName )
271- defer func () {
272- klog .V (10 ).Infof ("azDisksClient.Delete(%q,%q): end" , resourceGroupName , diskName )
273- }()
274-
275- future , err := az .client .Delete (ctx , resourceGroupName , diskName )
276- if err != nil {
277- return future .Response (), err
278- }
279-
280- err = future .WaitForCompletionRef (ctx , az .client .Client )
281- return future .Response (), err
282- }
283-
284138type azAccountsClient struct {
285139 client storage.AccountsClient
286140}
287141
288- func newAzAccountsClient (subscriptionID , endpoint string , servicePrincipalToken * adal.ServicePrincipalToken ) * azAccountsClient {
289- accountsClient := storage .NewAccountsClient (subscriptionID )
290- accountsClient .BaseURI = endpoint
291- accountsClient .Authorizer = autorest .NewBearerAuthorizer (servicePrincipalToken )
292- accountsClient .PollingDelay = 5 * time .Second
293- configureUserAgent (& accountsClient .Client )
294-
295- return & azAccountsClient {
296- client : accountsClient ,
297- }
298- }
299-
300- func (az * azAccountsClient ) ListKeys (ctx context.Context , resourceGroupName string , accountName string ) (result storage.AccountListKeysResult , err error ) {
301- klog .V (10 ).Infof ("azAccountsClient.ListKeys(%q,%q): start" , resourceGroupName , accountName )
302- defer func () {
303- klog .V (10 ).Infof ("azAccountsClient.ListKeys(%q,%q): end" , resourceGroupName , accountName )
304- }()
305-
306- return az .client .ListKeys (ctx , resourceGroupName , accountName )
307- }
308-
309142type azClient struct {
310143 virtualMachineScaleSetsClient vmssclient.Interface
311144 virtualMachineScaleSetVMsClient vmssvmclient.Interface
312- virtualMachinesClient VirtualMachinesClient
145+ virtualMachinesClient vmclient. Interface
313146 deploymentsClient DeploymentsClient
314- interfacesClient InterfacesClient
315- disksClient DisksClient
316- storageAccountsClient AccountsClient
147+ interfacesClient interfaceclient. Interface
148+ disksClient diskclient. Interface
149+ storageAccountsClient storageaccountclient. Interface
317150 containerServicesClient containerservice.ContainerServicesClient
318151 managedContainerServicesClient containerservice.ManagedClustersClient
319152}
@@ -390,19 +223,23 @@ func newAzClient(cfg *Config, env *azure.Environment) (*azClient, error) {
390223 scaleSetVMsClient := vmssvmclient .New (vmssVMClientConfig )
391224 klog .V (5 ).Infof ("Created scale set vm client with authorizer: %v" , scaleSetVMsClient )
392225
393- virtualMachinesClient := newAzVirtualMachinesClient (cfg .SubscriptionID , env .ResourceManagerEndpoint , spt )
226+ vmClientConfig := azClientConfig .WithRateLimiter (cfg .VirtualMachineRateLimit )
227+ virtualMachinesClient := vmclient .New (vmClientConfig )
394228 klog .V (5 ).Infof ("Created vm client with authorizer: %v" , virtualMachinesClient )
395229
396230 deploymentsClient := newAzDeploymentsClient (cfg .SubscriptionID , env .ResourceManagerEndpoint , spt )
397231 klog .V (5 ).Infof ("Created deployments client with authorizer: %v" , deploymentsClient )
398232
399- interfacesClient := newAzInterfacesClient (cfg .SubscriptionID , env .ResourceManagerEndpoint , spt )
233+ interfaceClientConfig := azClientConfig .WithRateLimiter (cfg .InterfaceRateLimit )
234+ interfacesClient := interfaceclient .New (interfaceClientConfig )
400235 klog .V (5 ).Infof ("Created interfaces client with authorizer: %v" , interfacesClient )
401236
402- storageAccountsClient := newAzAccountsClient (cfg .SubscriptionID , env .ResourceManagerEndpoint , spt )
237+ accountClientConfig := azClientConfig .WithRateLimiter (cfg .StorageAccountRateLimit )
238+ storageAccountsClient := storageaccountclient .New (accountClientConfig )
403239 klog .V (5 ).Infof ("Created storage accounts client with authorizer: %v" , storageAccountsClient )
404240
405- disksClient := newAzDisksClient (cfg .SubscriptionID , env .ResourceManagerEndpoint , spt )
241+ diskClientConfig := azClientConfig .WithRateLimiter (cfg .DiskRateLimit )
242+ disksClient := diskclient .New (diskClientConfig )
406243 klog .V (5 ).Infof ("Created disks client with authorizer: %v" , disksClient )
407244
408245 containerServicesClient := containerservice .NewContainerServicesClient (cfg .SubscriptionID )
0 commit comments