Skip to content

Commit

Permalink
Merge pull request #525 from feiskyer/fix-azurestack-cloud
Browse files Browse the repository at this point in the history
Allow disabling AzureStackCloud API versions when using AzureStackCloud config on public cloud
  • Loading branch information
k8s-ci-robot authored Feb 27, 2021
2 parents ab57903 + adba372 commit e0f9259
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 34 deletions.
1 change: 1 addition & 0 deletions pkg/azureclients/azure_client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ClientConfig struct {
RateLimitConfig *RateLimitConfig
Backoff *retry.Backoff
UserAgent string
DisableAzureStackCloud bool
}

// WithRateLimiter returns a new ClientConfig with rateLimitConfig set.
Expand Down
2 changes: 1 addition & 1 deletion pkg/azureclients/diskclient/azure_diskclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand Down
22 changes: 12 additions & 10 deletions pkg/azureclients/interfaceclient/azure_interfaceclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ var _ Interface = &Client{}

// Client implements network interface client.
type Client struct {
armClient armclient.Interface
subscriptionID string
cloudName string
armClient armclient.Interface
subscriptionID string
cloudName string
disableAzureStackCloud bool

// Rate limiting configures.
rateLimiterReader flowcontrol.RateLimiter
Expand All @@ -59,7 +60,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand All @@ -73,11 +74,12 @@ func New(config *azclients.ClientConfig) *Client {
config.RateLimitConfig.CloudProviderRateLimitBucketWrite)

client := &Client{
armClient: armClient,
rateLimiterReader: rateLimiterReader,
rateLimiterWriter: rateLimiterWriter,
subscriptionID: config.SubscriptionID,
cloudName: config.CloudName,
armClient: armClient,
rateLimiterReader: rateLimiterReader,
rateLimiterWriter: rateLimiterWriter,
subscriptionID: config.SubscriptionID,
cloudName: config.CloudName,
disableAzureStackCloud: config.DisableAzureStackCloud,
}

return client
Expand Down Expand Up @@ -187,7 +189,7 @@ func (c *Client) getVMSSNetworkInterface(ctx context.Context, resourceGroupName

result := network.Interface{}
computeAPIVersion := ComputeAPIVersion
if strings.EqualFold(c.cloudName, AzureStackCloudName) {
if strings.EqualFold(c.cloudName, AzureStackCloudName) && !c.disableAzureStackCloud {
computeAPIVersion = AzureStackComputeAPIVersion
}
queryParameters := map[string]interface{}{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand Down
22 changes: 12 additions & 10 deletions pkg/azureclients/publicipclient/azure_publicipclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ var _ Interface = &Client{}

// Client implements PublicIPAddress client Interface.
type Client struct {
armClient armclient.Interface
subscriptionID string
cloudName string
armClient armclient.Interface
subscriptionID string
cloudName string
disableAzureStackCloud bool

// Rate limiting configures.
rateLimiterReader flowcontrol.RateLimiter
Expand All @@ -59,7 +60,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand All @@ -73,11 +74,12 @@ func New(config *azclients.ClientConfig) *Client {
config.RateLimitConfig.CloudProviderRateLimitBucketWrite)

client := &Client{
armClient: armClient,
rateLimiterReader: rateLimiterReader,
rateLimiterWriter: rateLimiterWriter,
subscriptionID: config.SubscriptionID,
cloudName: config.CloudName,
armClient: armClient,
rateLimiterReader: rateLimiterReader,
rateLimiterWriter: rateLimiterWriter,
subscriptionID: config.SubscriptionID,
cloudName: config.CloudName,
disableAzureStackCloud: config.DisableAzureStackCloud,
}

return client
Expand Down Expand Up @@ -189,7 +191,7 @@ func (c *Client) getVMSSPublicIPAddress(ctx context.Context, resourceGroupName s

result := network.PublicIPAddress{}
computeAPIVersion := ComputeAPIVersion
if strings.EqualFold(c.cloudName, AzureStackCloudName) {
if strings.EqualFold(c.cloudName, AzureStackCloudName) && !c.disableAzureStackCloud {
computeAPIVersion = AzureStackComputeAPIVersion
}
queryParameters := map[string]interface{}{
Expand Down
2 changes: 1 addition & 1 deletion pkg/azureclients/routeclient/azure_routeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand Down
2 changes: 1 addition & 1 deletion pkg/azureclients/snapshotclient/azure_snapshotclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand Down
2 changes: 1 addition & 1 deletion pkg/azureclients/subnetclient/azure_subnetclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand Down
2 changes: 1 addition & 1 deletion pkg/azureclients/vmclient/azure_vmclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand Down
2 changes: 1 addition & 1 deletion pkg/azureclients/vmsizeclient/azure_vmsizeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand Down
2 changes: 1 addition & 1 deletion pkg/azureclients/vmssclient/azure_vmssclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand Down
2 changes: 1 addition & 1 deletion pkg/azureclients/vmssvmclient/azure_vmssvmclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func New(config *azclients.ClientConfig) *Client {
baseURI := config.ResourceManagerEndpoint
authorizer := config.Authorizer
apiVersion := APIVersion
if strings.EqualFold(config.CloudName, AzureStackCloudName) {
if strings.EqualFold(config.CloudName, AzureStackCloudName) && !config.DisableAzureStackCloud {
apiVersion = AzureStackCloudAPIVersion
}
armClient := armclient.New(authorizer, baseURI, config.UserAgent, apiVersion, config.Location, config.Backoff)
Expand Down
6 changes: 6 additions & 0 deletions pkg/provider/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ type Config struct {
// DisableAvailabilitySetNodes disables VMAS nodes support when "VMType" is set to "vmss".
DisableAvailabilitySetNodes bool `json:"disableAvailabilitySetNodes,omitempty" yaml:"disableAvailabilitySetNodes,omitempty"`

// DisableAzureStackCloud disables AzureStackCloud support. It should be used
// when setting AzureAuthConfig.Cloud with "AZURESTACKCLOUD" to customize ARM endpoints
// while the cluster is not running on AzureStack.
DisableAzureStackCloud bool `json:"disableAzureStackCloud,omitempty" yaml:"disableAzureStackCloud,omitempty"`

// Tags determines what tags shall be applied to the shared resources managed by controller manager, which
// includes load balancer, security group and route table. The supported format is `a=b,c=d,...`. After updated
// this config, the old tags would be replaced by the new ones.
Expand Down Expand Up @@ -643,6 +648,7 @@ func (az *Cloud) getAzureClientConfig(servicePrincipalToken *adal.ServicePrincip
ResourceManagerEndpoint: az.Environment.ResourceManagerEndpoint,
Authorizer: autorest.NewBearerAuthorizer(servicePrincipalToken),
Backoff: &retry.Backoff{Steps: 1},
DisableAzureStackCloud: az.Config.DisableAzureStackCloud,
}

if az.Config.CloudProviderBackoff {
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/azure_controller_standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (as *availabilitySet) DetachDisk(nodeName types.NodeName, diskMap map[strin
(disk.ManagedDisk != nil && diskURI != "" && strings.EqualFold(*disk.ManagedDisk.ID, diskURI)) {
// found the disk
klog.V(2).Infof("azureDisk - detach disk: name %q uri %q", diskName, diskURI)
if strings.EqualFold(as.cloud.Environment.Name, AzureStackCloudName) {
if strings.EqualFold(as.cloud.Environment.Name, AzureStackCloudName) && !as.Config.DisableAzureStackCloud {
disks = append(disks[:i], disks[i+1:]...)
} else {
disks[i].ToBeDetached = to.BoolPtr(true)
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/azure_controller_vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (ss *scaleSet) DetachDisk(nodeName types.NodeName, diskMap map[string]strin
(disk.ManagedDisk != nil && diskURI != "" && strings.EqualFold(*disk.ManagedDisk.ID, diskURI)) {
// found the disk
klog.V(2).Infof("azureDisk - detach disk: name %q uri %q", diskName, diskURI)
if strings.EqualFold(ss.cloud.Environment.Name, AzureStackCloudName) {
if strings.EqualFold(ss.cloud.Environment.Name, AzureStackCloudName) && !ss.Config.DisableAzureStackCloud {
disks = append(disks[:i], disks[i+1:]...)
} else {
disks[i].ToBeDetached = to.BoolPtr(true)
Expand Down

0 comments on commit e0f9259

Please sign in to comment.