@@ -248,7 +248,14 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) {
248
248
}
249
249
250
250
servicePrincipalToken , err := auth .GetServicePrincipalToken (& config .AzureAuthConfig , env )
251
- if err != nil {
251
+ if err == auth .ErrorNoAuth {
252
+ if ! config .UseInstanceMetadata {
253
+ // No credentials provided, useInstanceMetadata should be enabled.
254
+ return nil , fmt .Errorf ("useInstanceMetadata must be enabled without Azure credentials" )
255
+ }
256
+
257
+ klog .V (2 ).Infof ("Azure cloud provider is starting without credentials" )
258
+ } else if err != nil {
252
259
return nil , err
253
260
}
254
261
@@ -348,16 +355,6 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) {
348
355
}
349
356
}
350
357
351
- azClientConfig := & azClientConfig {
352
- subscriptionID : config .SubscriptionID ,
353
- resourceManagerEndpoint : env .ResourceManagerEndpoint ,
354
- servicePrincipalToken : servicePrincipalToken ,
355
- rateLimiterReader : operationPollRateLimiter ,
356
- rateLimiterWriter : operationPollRateLimiterWrite ,
357
- CloudProviderBackoffRetries : config .CloudProviderBackoffRetries ,
358
- CloudProviderBackoffDuration : config .CloudProviderBackoffDuration ,
359
- ShouldOmitCloudProviderBackoff : config .shouldOmitCloudProviderBackoff (),
360
- }
361
358
az := Cloud {
362
359
Config : * config ,
363
360
Environment : * env ,
@@ -366,29 +363,45 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) {
366
363
unmanagedNodes : sets .NewString (),
367
364
routeCIDRs : map [string ]string {},
368
365
resourceRequestBackoff : resourceRequestBackoff ,
369
-
370
- DisksClient : newAzDisksClient (azClientConfig ),
371
- SnapshotsClient : newSnapshotsClient (azClientConfig ),
372
- RoutesClient : newAzRoutesClient (azClientConfig ),
373
- SubnetsClient : newAzSubnetsClient (azClientConfig ),
374
- InterfacesClient : newAzInterfacesClient (azClientConfig ),
375
- RouteTablesClient : newAzRouteTablesClient (azClientConfig ),
376
- LoadBalancerClient : newAzLoadBalancersClient (azClientConfig ),
377
- SecurityGroupsClient : newAzSecurityGroupsClient (azClientConfig ),
378
- StorageAccountClient : newAzStorageAccountClient (azClientConfig ),
379
- VirtualMachinesClient : newAzVirtualMachinesClient (azClientConfig ),
380
- PublicIPAddressesClient : newAzPublicIPAddressesClient (azClientConfig ),
381
- VirtualMachineSizesClient : newAzVirtualMachineSizesClient (azClientConfig ),
382
- VirtualMachineScaleSetsClient : newAzVirtualMachineScaleSetsClient (azClientConfig ),
383
- VirtualMachineScaleSetVMsClient : newAzVirtualMachineScaleSetVMsClient (azClientConfig ),
384
- FileClient : & azureFileClient {env : * env },
385
366
}
386
-
387
367
az .metadata , err = NewInstanceMetadataService (metadataURL )
388
368
if err != nil {
389
369
return nil , err
390
370
}
391
371
372
+ // No credentials provided, InstanceMetadataService would be used for getting Azure resources.
373
+ // Note that this only applies to Kubelet, controller-manager should configure credentials for managing Azure resources.
374
+ if servicePrincipalToken == nil {
375
+ return & az , nil
376
+ }
377
+
378
+ // Initialize Azure clients.
379
+ azClientConfig := & azClientConfig {
380
+ subscriptionID : config .SubscriptionID ,
381
+ resourceManagerEndpoint : env .ResourceManagerEndpoint ,
382
+ servicePrincipalToken : servicePrincipalToken ,
383
+ rateLimiterReader : operationPollRateLimiter ,
384
+ rateLimiterWriter : operationPollRateLimiterWrite ,
385
+ CloudProviderBackoffRetries : config .CloudProviderBackoffRetries ,
386
+ CloudProviderBackoffDuration : config .CloudProviderBackoffDuration ,
387
+ ShouldOmitCloudProviderBackoff : config .shouldOmitCloudProviderBackoff (),
388
+ }
389
+ az .DisksClient = newAzDisksClient (azClientConfig )
390
+ az .SnapshotsClient = newSnapshotsClient (azClientConfig )
391
+ az .RoutesClient = newAzRoutesClient (azClientConfig )
392
+ az .SubnetsClient = newAzSubnetsClient (azClientConfig )
393
+ az .InterfacesClient = newAzInterfacesClient (azClientConfig )
394
+ az .RouteTablesClient = newAzRouteTablesClient (azClientConfig )
395
+ az .LoadBalancerClient = newAzLoadBalancersClient (azClientConfig )
396
+ az .SecurityGroupsClient = newAzSecurityGroupsClient (azClientConfig )
397
+ az .StorageAccountClient = newAzStorageAccountClient (azClientConfig )
398
+ az .VirtualMachinesClient = newAzVirtualMachinesClient (azClientConfig )
399
+ az .PublicIPAddressesClient = newAzPublicIPAddressesClient (azClientConfig )
400
+ az .VirtualMachineSizesClient = newAzVirtualMachineSizesClient (azClientConfig )
401
+ az .VirtualMachineScaleSetsClient = newAzVirtualMachineScaleSetsClient (azClientConfig )
402
+ az .VirtualMachineScaleSetVMsClient = newAzVirtualMachineScaleSetVMsClient (azClientConfig )
403
+ az .FileClient = & azureFileClient {env : * env }
404
+
392
405
if az .MaximumLoadBalancerRuleCount == 0 {
393
406
az .MaximumLoadBalancerRuleCount = maximumLoadBalancerRuleCount
394
407
}
0 commit comments