Skip to content

Commit 3322ff9

Browse files
committed
generalize solution
1 parent 11b0e9a commit 3322ff9

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

pkg/credentialprovider/azure/azure_credentials.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (a *acrProvider) loadConfig(rdr io.Reader) error {
144144
klog.Errorf("Failed to load azure credential file: %v", err)
145145
}
146146

147-
a.environment, err = auth.ParseAzureEnvironment(a.config.Cloud, a.config.CloudFQDN, a.config.IdentitySystem)
147+
a.environment, err = auth.ParseAzureEnvironment(a.config.Cloud, a.config.ResourceManagerEndpoint, a.config.IdentitySystem)
148148
if err != nil {
149149
return err
150150
}

staging/src/k8s.io/legacy-cloud-providers/azure/auth/azure_auth.go

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ type AzureAuthConfig struct {
6565
// IdentitySystem indicates the identity provider. Relevant only to hybrid clouds (Azure Stack).
6666
// Allowed values are 'azure_ad' (default), 'adfs'.
6767
IdentitySystem string `json:"identitySystem,omitempty" yaml:"identitySystem,omitempty"`
68-
// CloudFQDN represents the hybrid cloud's fully qualified domain name: {location}.{domain}
69-
// If set, cloud provider will generate its autorest.Environment instead of using one of the pre-defined ones.
70-
CloudFQDN string `json:"cloudFQDN,omitempty" yaml:"cloudFQDN,omitempty"`
68+
// ResourceManagerEndpoint is the cloud's resource manager endpoint. If set, cloud provider queries this endpoint
69+
// in order to generate an autorest.Environment instance instead of using one of the pre-defined Environments.
70+
ResourceManagerEndpoint string `json:"resourceManagerEndpoint,omitempty" yaml:"resourceManagerEndpoint,omitempty"`
7171
}
7272

7373
// GetServicePrincipalToken creates a new service principal token based on the configuration
@@ -133,18 +133,17 @@ func GetServicePrincipalToken(config *AzureAuthConfig, env *azure.Environment) (
133133
}
134134

135135
// ParseAzureEnvironment returns the azure environment.
136-
// If 'cloudFQDN' is set, environment is computed by quering the cloud's resource manager endpoint.
136+
// If 'resourceManagerEndpoint' is set, the environment is computed by quering the cloud's resource manager endpoint.
137137
// Otherwise, a pre-defined Environment is looked up by name.
138-
func ParseAzureEnvironment(cloudName, cloudFQDN, identitySystem string) (*azure.Environment, error) {
138+
func ParseAzureEnvironment(cloudName, resourceManagerEndpoint, identitySystem string) (*azure.Environment, error) {
139139
var env azure.Environment
140140
var err error
141-
if cloudFQDN != "" {
142-
resourceManagerEndpoint := fmt.Sprintf("https://management.%s/", cloudFQDN)
143-
nameOverride := azure.OverrideProperty{Key: azure.EnvironmentName, Value: cloudName}
141+
if resourceManagerEndpoint != "" {
144142
klog.V(4).Infof("Loading environment from resource manager endpoint: %s", resourceManagerEndpoint)
143+
nameOverride := azure.OverrideProperty{Key: azure.EnvironmentName, Value: cloudName}
145144
env, err = azure.EnvironmentFromURL(resourceManagerEndpoint, nameOverride)
146-
if err == nil && strings.EqualFold(cloudName, "AzureStackCloud") {
147-
azureStackOverrides(&env, cloudFQDN, identitySystem)
145+
if err == nil {
146+
azureStackOverrides(&env, resourceManagerEndpoint, identitySystem)
148147
}
149148
} else if cloudName == "" {
150149
klog.V(4).Info("Using public cloud environment")
@@ -172,19 +171,16 @@ func decodePkcs12(pkcs []byte, password string) (*x509.Certificate, *rsa.Private
172171
}
173172

174173
// azureStackOverrides ensures that the Environment matches what AKSe currently generates for Azure Stack
175-
func azureStackOverrides(env *azure.Environment, cloudFQDN, identitySystem string) {
176-
env.ManagementPortalURL = fmt.Sprintf("https://portal.%s/", cloudFQDN)
177-
// TODO: figure out why AKSe does this
178-
// why is autorest not setting ServiceManagementEndpoint?
174+
func azureStackOverrides(env *azure.Environment, resourceManagerEndpoint, identitySystem string) {
175+
env.ManagementPortalURL = strings.Replace(resourceManagerEndpoint, "https://management.", "https://portal.", -1)
176+
// TODO: figure out why AKSe does this, why is autorest not setting ServiceManagementEndpoint?
179177
env.ServiceManagementEndpoint = env.TokenAudience
180-
// TODO: figure out why AKSe does this
181-
// May not be required, ResourceManagerVMDNSSuffix is not used by k/k
182-
split := strings.Split(cloudFQDN, ".")
183-
domain := strings.Join(split[1:], ".")
184-
env.ResourceManagerVMDNSSuffix = fmt.Sprintf("cloudapp.%s", domain)
185-
// NOTE: autorest sets KeyVaultEndpoint while AKSe does not
178+
// TODO: figure out why AKSe does this, may not be required, ResourceManagerVMDNSSuffix is not referenced anywhere
179+
env.ResourceManagerVMDNSSuffix = strings.Replace(resourceManagerEndpoint, "https://management.", "cloudapp.", -1)
180+
env.ResourceManagerVMDNSSuffix = strings.TrimSuffix(env.ResourceManagerVMDNSSuffix, "/")
186181
if strings.EqualFold(identitySystem, ADFSIdentitySystem) {
187182
env.ActiveDirectoryEndpoint = strings.TrimSuffix(env.ActiveDirectoryEndpoint, "/")
188183
env.ActiveDirectoryEndpoint = strings.TrimSuffix(env.ActiveDirectoryEndpoint, "adfs")
189184
}
185+
// NOTE: autorest sets KeyVaultEndpoint while AKSe does not
190186
}

staging/src/k8s.io/legacy-cloud-providers/azure/azure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func (az *Cloud) InitializeCloudFromConfig(config *Config, fromSecret bool) erro
325325
}
326326
}
327327

328-
env, err := auth.ParseAzureEnvironment(config.Cloud, config.CloudFQDN, config.IdentitySystem)
328+
env, err := auth.ParseAzureEnvironment(config.Cloud, config.ResourceManagerEndpoint, config.IdentitySystem)
329329
if err != nil {
330330
return err
331331
}

0 commit comments

Comments
 (0)