diff --git a/azure/scope/clients.go b/azure/scope/clients.go index b766b066747..ffb60615b11 100644 --- a/azure/scope/clients.go +++ b/azure/scope/clients.go @@ -25,26 +25,31 @@ import ( "strings" "github.com/Azure/azure-sdk-for-go/sdk/azcore" - azureautorest "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/azure/auth" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" + "sigs.k8s.io/cluster-api-provider-azure/azure" ) // AzureClients contains all the Azure clients used by the scopes. type AzureClients struct { - auth.EnvironmentSettings + environmentSettings TokenCredential azcore.TokenCredential - ResourceManagerEndpoint string ResourceManagerVMDNSSuffix string authType infrav1.IdentityType } +type environmentSettings struct { + Values map[string]string + CloudType string + CloudSettings cloud.Configuration +} + // CloudEnvironment returns the Azure environment the controller runs in. func (c *AzureClients) CloudEnvironment() string { - return c.Environment.Name + return c.environmentSettings.CloudType } // TenantID returns the Azure tenant id the controller runs in. @@ -86,34 +91,28 @@ func (c *AzureClients) setCredentialsWithProvider(ctx context.Context, subscript return fmt.Errorf("credentials provider cannot have an empty value") } - settings, err := c.getSettingsFromEnvironment(environmentName) - if err != nil { - return err - } + c.environmentSettings = c.getSettingsFromEnvironment(environmentName) if subscriptionID == "" { - subscriptionID = settings.GetSubscriptionID() + subscriptionID = c.environmentSettings.Values["AZURE_SUBSCRIPTION_ID"] if subscriptionID == "" { return fmt.Errorf("error creating azure services. subscriptionID is not set in cluster or AZURE_SUBSCRIPTION_ID env var") } } - c.EnvironmentSettings = settings - c.ResourceManagerEndpoint = settings.Environment.ResourceManagerEndpoint - c.ResourceManagerVMDNSSuffix = settings.Environment.ResourceManagerVMDNSSuffix - c.Values["AZURE_SUBSCRIPTION_ID"] = strings.TrimSuffix(subscriptionID, "\n") - c.Values["AZURE_TENANT_ID"] = strings.TrimSuffix(credentialsProvider.GetTenantID(), "\n") - c.Values["AZURE_CLIENT_ID"] = strings.TrimSuffix(credentialsProvider.GetClientID(), "\n") + c.environmentSettings.Values["AZURE_SUBSCRIPTION_ID"] = strings.TrimSuffix(subscriptionID, "\n") + c.environmentSettings.Values["AZURE_TENANT_ID"] = strings.TrimSuffix(credentialsProvider.GetTenantID(), "\n") + c.environmentSettings.Values["AZURE_CLIENT_ID"] = strings.TrimSuffix(credentialsProvider.GetClientID(), "\n") clientSecret, err := credentialsProvider.GetClientSecret(ctx) if err != nil { return err } - c.Values["AZURE_CLIENT_SECRET"] = strings.TrimSuffix(clientSecret, "\n") + c.environmentSettings.Values["AZURE_CLIENT_SECRET"] = strings.TrimSuffix(clientSecret, "\n") c.authType = credentialsProvider.Type() - tokenCredential, err := credentialsProvider.GetTokenCredential(ctx, c.ResourceManagerEndpoint, c.Environment.ActiveDirectoryEndpoint, c.Environment.TokenAudience) + tokenCredential, err := credentialsProvider.GetTokenCredential(ctx, c.CloudSettings) if err != nil { return err } @@ -121,10 +120,11 @@ func (c *AzureClients) setCredentialsWithProvider(ctx context.Context, subscript return err } -func (c *AzureClients) getSettingsFromEnvironment(environmentName string) (s auth.EnvironmentSettings, err error) { - s = auth.EnvironmentSettings{ - Values: map[string]string{}, +func (c *AzureClients) getSettingsFromEnvironment(environmentName string) environmentSettings { + s := environmentSettings{ + Values: make(map[string]string), } + s.Values["AZURE_ENVIRONMENT"] = environmentName setValue(s, "AZURE_SUBSCRIPTION_ID") setValue(s, "AZURE_TENANT_ID") @@ -137,19 +137,33 @@ func (c *AzureClients) getSettingsFromEnvironment(environmentName string) (s aut setValue(s, "AZURE_PASSWORD") setValue(s, "AZURE_AD_RESOURCE") if v := s.Values["AZURE_ENVIRONMENT"]; v == "" { - s.Environment = azureautorest.PublicCloud + s.CloudType = azure.PublicCloudName + s.CloudSettings = cloud.AzurePublic } else { - s.Environment, err = azureautorest.EnvironmentFromName(v) - } - if s.Values["AZURE_AD_RESOURCE"] == "" { - s.Values["AZURE_AD_RESOURCE"] = s.Environment.ResourceManagerEndpoint + s.CloudType, s.CloudSettings = getCloudEnvironment(os.Getenv("AZURE_ENVIRONMENT")) } - return + return s } // setValue adds the specified environment variable value to the Values map if it exists. -func setValue(settings auth.EnvironmentSettings, key string) { +func setValue(settings environmentSettings, key string) { if v := os.Getenv(key); v != "" { settings.Values[key] = v } } + +func getCloudEnvironment(cloudType string) (string, cloud.Configuration) { + cloudType = strings.ToUpper(cloudType) + switch cloudType { + case "AZUREPUBLICCLOUD": + return azure.PublicCloudName, cloud.AzurePublic + case "AZURECLOUD": + return azure.PublicCloudName, cloud.AzurePublic + case "AZURECHINACLOUD": + return azure.ChinaCloudName, cloud.AzureChina + case "AZUREUSGOVERNMENT": + return azure.USGovernmentCloudName, cloud.AzureGovernment + default: + return azure.PublicCloudName, cloud.AzurePublic + } +} diff --git a/azure/scope/cluster.go b/azure/scope/cluster.go index 8148fc0469a..c98862a052e 100644 --- a/azure/scope/cluster.go +++ b/azure/scope/cluster.go @@ -25,6 +25,7 @@ import ( "strconv" "strings" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" asonetworkv1api20201101 "github.com/Azure/azure-service-operator/v2/api/network/v1api20201101" asonetworkv1api20220701 "github.com/Azure/azure-service-operator/v2/api/network/v1api20220701" asoresourcesv1 "github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601" @@ -128,7 +129,7 @@ type ClusterCache struct { // BaseURI returns the Azure ResourceManagerEndpoint. func (s *ClusterScope) BaseURI() string { - return s.ResourceManagerEndpoint + return s.AzureClients.CloudSettings.Services[cloud.ResourceManager].Endpoint } // GetClient returns the controller-runtime client. @@ -893,7 +894,7 @@ func (s *ClusterScope) GenerateFQDN(ipName string) string { return "" } hash := fmt.Sprintf("%x", h.Sum32()) - return strings.ToLower(fmt.Sprintf("%s-%s.%s.%s", s.ClusterName(), hash, s.Location(), s.AzureClients.ResourceManagerVMDNSSuffix)) + return strings.ToLower(fmt.Sprintf("%s-%s.%s", s.ClusterName(), hash, s.Location())) } // GenerateLegacyFQDN generates an IP name and a fully qualified domain name, based on a hash, cluster name and cluster location. @@ -904,7 +905,7 @@ func (s *ClusterScope) GenerateLegacyFQDN() (ip string, domain string) { return "", "" } ipName := fmt.Sprintf("%s-%x", s.ClusterName(), h.Sum32()) - fqdn := fmt.Sprintf("%s.%s.%s", ipName, s.Location(), s.AzureClients.ResourceManagerVMDNSSuffix) + fqdn := fmt.Sprintf("%s.%s", ipName, s.Location()) return ipName, fqdn } diff --git a/azure/scope/cluster_test.go b/azure/scope/cluster_test.go index 25d59445536..38edbb4711a 100644 --- a/azure/scope/cluster_test.go +++ b/azure/scope/cluster_test.go @@ -26,7 +26,6 @@ import ( asonetworkv1api20201101 "github.com/Azure/azure-service-operator/v2/api/network/v1api20201101" asonetworkv1api20220701 "github.com/Azure/azure-service-operator/v2/api/network/v1api20220701" asoresourcesv1 "github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601" - "github.com/Azure/go-autorest/autorest/azure/auth" "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -56,6 +55,7 @@ import ( const fakeClientID = "fake-client-id" const fakeTenantID = "fake-tenant-id" const fakeSubscriptionID = "123" +const SubscriptionID = "AZURE_SUBSCRIPTION_ID" func specToString(spec any) string { var sb strings.Builder @@ -875,9 +875,9 @@ func TestNatGatewaySpecs(t *testing.T) { }, }, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -949,9 +949,9 @@ func TestNatGatewaySpecs(t *testing.T) { }, }, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -1041,9 +1041,9 @@ func TestNatGatewaySpecs(t *testing.T) { }, }, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -1341,9 +1341,9 @@ func TestSubnetSpecs(t *testing.T) { }, }, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -1422,9 +1422,9 @@ func TestSubnetSpecs(t *testing.T) { }, }, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -1718,9 +1718,9 @@ func TestAzureBastionSpec(t *testing.T) { }, }, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -3174,9 +3174,9 @@ func TestClusterScope_LBSpecs(t *testing.T) { Cluster: cluster, AzureCluster: tc.azureCluster, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: tc.azureCluster.Spec.SubscriptionID, + SubscriptionID: tc.azureCluster.Spec.SubscriptionID, }, }, }, @@ -3496,9 +3496,9 @@ func TestVNetPeerings(t *testing.T) { Cluster: cluster, AzureCluster: azureCluster, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: tc.subscriptionID, + SubscriptionID: tc.subscriptionID, }, }, }, diff --git a/azure/scope/identity.go b/azure/scope/identity.go index 180b1c1fe81..f9d718a7977 100644 --- a/azure/scope/identity.go +++ b/azure/scope/identity.go @@ -45,7 +45,7 @@ type CredentialsProvider interface { GetClientID() string GetClientSecret(ctx context.Context) (string, error) GetTenantID() string - GetTokenCredential(ctx context.Context, resourceManagerEndpoint, activeDirectoryEndpoint, tokenAudience string) (azcore.TokenCredential, error) + GetTokenCredential(ctx context.Context, cloudConfig cloud.Configuration) (azcore.TokenCredential, error) Type() infrav1.IdentityType } @@ -82,7 +82,7 @@ func NewAzureCredentialsProvider(ctx context.Context, cache azure.CredentialCach } // GetTokenCredential returns an Azure TokenCredential based on the provided azure identity. -func (p *AzureCredentialsProvider) GetTokenCredential(ctx context.Context, resourceManagerEndpoint, activeDirectoryEndpoint, tokenAudience string) (azcore.TokenCredential, error) { +func (p *AzureCredentialsProvider) GetTokenCredential(ctx context.Context, cloudConfig cloud.Configuration) (azcore.TokenCredential, error) { ctx, log, done := tele.StartSpanWithLogger(ctx, "azure.scope.AzureCredentialsProvider.GetTokenCredential") defer done() @@ -117,15 +117,7 @@ func (p *AzureCredentialsProvider) GetTokenCredential(ctx context.Context, resou options := azidentity.ClientSecretCredentialOptions{ ClientOptions: azcore.ClientOptions{ TracingProvider: tracingProvider, - Cloud: cloud.Configuration{ - ActiveDirectoryAuthorityHost: activeDirectoryEndpoint, - Services: map[cloud.ServiceName]cloud.ServiceConfiguration{ - cloud.ResourceManager: { - Audience: tokenAudience, - Endpoint: resourceManagerEndpoint, - }, - }, - }, + Cloud: cloudConfig, }, } cred, authErr = p.cache.GetOrStoreClientSecret(p.GetTenantID(), p.Identity.Spec.ClientID, clientSecret, &options) diff --git a/azure/scope/identity_test.go b/azure/scope/identity_test.go index 9cb9a66c8fe..a117affb5e7 100644 --- a/azure/scope/identity_test.go +++ b/azure/scope/identity_test.go @@ -277,15 +277,7 @@ func TestGetTokenCredential(t *testing.T) { cacheExpect: func(cache *mock_azure.MockCredentialCache) { cache.EXPECT().GetOrStoreClientSecret(fakeTenantID, fakeClientID, "fooSecret", gomock.Cond(func(opts *azidentity.ClientSecretCredentialOptions) bool { // ignore tracing provider - return reflect.DeepEqual(opts.ClientOptions.Cloud, cloud.Configuration{ - ActiveDirectoryAuthorityHost: "https://login.microsoftonline.com", - Services: map[cloud.ServiceName]cloud.ServiceConfiguration{ - cloud.ResourceManager: { - Audience: "", - Endpoint: "", - }, - }, - }) + return reflect.DeepEqual(opts.ClientOptions.Cloud, cloud.AzurePublic) })) }, }, @@ -322,15 +314,7 @@ func TestGetTokenCredential(t *testing.T) { cacheExpect: func(cache *mock_azure.MockCredentialCache) { cache.EXPECT().GetOrStoreClientSecret(fakeTenantID, fakeClientID, "fooSecret", gomock.Cond(func(opts *azidentity.ClientSecretCredentialOptions) bool { // ignore tracing provider - return reflect.DeepEqual(opts.ClientOptions.Cloud, cloud.Configuration{ - ActiveDirectoryAuthorityHost: "https://login.microsoftonline.com", - Services: map[cloud.ServiceName]cloud.ServiceConfiguration{ - cloud.ResourceManager: { - Audience: "", - Endpoint: "", - }, - }, - }) + return reflect.DeepEqual(opts.ClientOptions.Cloud, cloud.AzurePublic) })) }, }, @@ -443,7 +427,7 @@ func TestGetTokenCredential(t *testing.T) { provider, err := NewAzureCredentialsProvider(context.Background(), cache, fakeClient, tt.cluster.Spec.IdentityRef, "") g.Expect(err).NotTo(HaveOccurred()) - _, err = provider.GetTokenCredential(context.Background(), "", tt.ActiveDirectoryAuthorityHost, "") + _, err = provider.GetTokenCredential(context.Background(), cloud.AzurePublic) g.Expect(err).NotTo(HaveOccurred()) }) } diff --git a/azure/scope/machine_test.go b/azure/scope/machine_test.go index cfbb44b3588..3d2052ff93a 100644 --- a/azure/scope/machine_test.go +++ b/azure/scope/machine_test.go @@ -21,10 +21,9 @@ import ( "reflect" "testing" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2" - azureautorest "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/azure/auth" "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" "go.uber.org/mock/gomock" @@ -377,9 +376,9 @@ func TestMachineScope_InboundNatSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -458,9 +457,9 @@ func TestMachineScope_RoleAssignmentSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -504,9 +503,9 @@ func TestMachineScope_RoleAssignmentSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -550,7 +549,7 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { want []azure.ResourceSpecGetter }{ { - name: "If OS type is Linux and cloud is AzurePublicCloud, it returns ExtensionSpec", + name: "If OS type is Linux and cloud is AzurePublic, it returns ExtensionSpec", machineScope: MachineScope{ Machine: &clusterv1.Machine{}, AzureMachine: &infrav1.AzureMachine{ @@ -565,10 +564,9 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, - }, + environmentSettings: environmentSettings{ + CloudType: azure.PublicCloudName, + CloudSettings: cloud.AzurePublic, }, }, AzureCluster: &infrav1.AzureCluster{ @@ -616,13 +614,6 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, }, ClusterScoper: &ClusterScope{ - AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, - }, - }, - }, AzureCluster: &infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", @@ -653,13 +644,6 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, }, ClusterScoper: &ClusterScope{ - AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.USGovernmentCloud.Name, - }, - }, - }, AzureCluster: &infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", @@ -691,10 +675,9 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, - }, + environmentSettings: environmentSettings{ + CloudType: azure.PublicCloudName, + CloudSettings: cloud.AzurePublic, }, }, AzureCluster: &infrav1.AzureCluster{ @@ -741,13 +724,6 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, }, ClusterScoper: &ClusterScope{ - AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.USGovernmentCloud.Name, - }, - }, - }, AzureCluster: &infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", @@ -778,13 +754,6 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, }, ClusterScoper: &ClusterScope{ - AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, - }, - }, - }, AzureCluster: &infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", @@ -815,13 +784,6 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, }, ClusterScoper: &ClusterScope{ - AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.USGovernmentCloud.Name, - }, - }, - }, AzureCluster: &infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", @@ -866,10 +828,9 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, - }, + environmentSettings: environmentSettings{ + CloudType: azure.PublicCloudName, + CloudSettings: cloud.AzurePublic, }, }, AzureCluster: &infrav1.AzureCluster{ @@ -1742,9 +1703,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -1849,9 +1810,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -1963,9 +1924,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -2072,9 +2033,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -2177,9 +2138,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -2290,9 +2251,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -2399,9 +2360,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -2509,9 +2470,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -2619,9 +2580,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -2730,9 +2691,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -2870,9 +2831,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -3008,9 +2969,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, diff --git a/azure/scope/machinepool_test.go b/azure/scope/machinepool_test.go index 4d17b61ff4d..edd288d91dc 100644 --- a/azure/scope/machinepool_test.go +++ b/azure/scope/machinepool_test.go @@ -29,8 +29,6 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" - azureautorest "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/azure/auth" . "github.com/onsi/gomega" "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" @@ -780,9 +778,9 @@ func TestMachinePoolScope_RoleAssignmentSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -826,9 +824,9 @@ func TestMachinePoolScope_RoleAssignmentSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + environmentSettings: environmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + SubscriptionID: "123", }, }, }, @@ -889,10 +887,8 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, - }, + environmentSettings: environmentSettings{ + CloudType: azure.PublicCloudName, }, }, AzureCluster: &infrav1.AzureCluster{ @@ -937,13 +933,6 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, }, ClusterScoper: &ClusterScope{ - AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.USGovernmentCloud.Name, - }, - }, - }, AzureCluster: &infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", @@ -975,10 +964,8 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, - }, + environmentSettings: environmentSettings{ + CloudType: azure.PublicCloudName, }, }, AzureCluster: &infrav1.AzureCluster{ @@ -1024,13 +1011,6 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, }, ClusterScoper: &ClusterScope{ - AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.USGovernmentCloud.Name, - }, - }, - }, AzureCluster: &infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", @@ -1060,13 +1040,6 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, }, ClusterScoper: &ClusterScope{ - AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, - }, - }, - }, AzureCluster: &infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", @@ -1096,13 +1069,6 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, }, ClusterScoper: &ClusterScope{ - AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.USGovernmentCloud.Name, - }, - }, - }, AzureCluster: &infrav1.AzureCluster{ Spec: infrav1.AzureClusterSpec{ ResourceGroup: "my-rg", @@ -1146,10 +1112,8 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, - }, + environmentSettings: environmentSettings{ + CloudType: azure.PublicCloudName, }, }, AzureCluster: &infrav1.AzureCluster{ diff --git a/azure/scope/managedcontrolplane.go b/azure/scope/managedcontrolplane.go index 0956cf6478a..32c5ee3086f 100644 --- a/azure/scope/managedcontrolplane.go +++ b/azure/scope/managedcontrolplane.go @@ -23,6 +23,7 @@ import ( "strings" "time" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" asocontainerservicev1preview "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20230315preview" asokubernetesconfigurationv1 "github.com/Azure/azure-service-operator/v2/api/kubernetesconfiguration/v1api20230501" asonetworkv1api20201101 "github.com/Azure/azure-service-operator/v2/api/network/v1api20201101" @@ -227,7 +228,7 @@ func (s *ManagedControlPlaneScope) SubscriptionID() string { // BaseURI returns the Azure ResourceManagerEndpoint. func (s *ManagedControlPlaneScope) BaseURI() string { - return s.AzureClients.ResourceManagerEndpoint + return s.AzureClients.CloudSettings.Services[cloud.ResourceManager].Endpoint } // PatchObject persists the cluster configuration and status. diff --git a/go.mod b/go.mod index 67ba88c8bf6..79895734dce 100644 --- a/go.mod +++ b/go.mod @@ -19,8 +19,6 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0 github.com/Azure/azure-sdk-for-go/sdk/tracing/azotel v0.4.0 github.com/Azure/azure-service-operator/v2 v2.11.0 - github.com/Azure/go-autorest/autorest v0.11.30 - github.com/Azure/go-autorest/autorest/azure/auth v0.5.13 github.com/asaskevich/govalidator/v11 v11.0.2-0.20250122183457-e11347878e23 github.com/blang/semver v3.5.1+incompatible github.com/go-logr/logr v1.4.2 @@ -71,6 +69,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault v1.4.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.6.0 // indirect github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect + github.com/Azure/go-autorest/autorest v0.11.30 // indirect github.com/antlr4-go/antlr/v4 v4.13.0 // indirect github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/fxamacker/cbor/v2 v2.7.0 // indirect @@ -96,7 +95,6 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/kubernetesconfiguration/armkubernetesconfiguration v1.1.1 github.com/Azure/go-autorest v14.2.0+incompatible // indirect github.com/Azure/go-autorest/autorest/adal v0.9.24 // indirect - github.com/Azure/go-autorest/autorest/azure/cli v0.4.6 // indirect github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect github.com/Azure/go-autorest/autorest/mocks v0.4.2 // indirect github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect @@ -120,7 +118,6 @@ require ( github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudflare/circl v1.3.7 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/dimchansky/utfbom v1.1.1 // indirect github.com/distribution/reference v0.6.0 // indirect github.com/docker/docker v27.3.1+incompatible // indirect github.com/docker/go-connections v0.5.0 // indirect @@ -168,7 +165,6 @@ require ( github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect - github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/moby/spdystream v0.4.0 // indirect diff --git a/go.sum b/go.sum index 1a58b10bea9..34eac569905 100644 --- a/go.sum +++ b/go.sum @@ -93,17 +93,11 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOEl github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs= github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= -github.com/Azure/go-autorest/autorest v0.11.28/go.mod h1:MrkzG3Y3AH668QyF9KRk5neJnGgmhQ6krbhR8Q5eMvA= github.com/Azure/go-autorest/autorest v0.11.30 h1:iaZ1RGz/ALZtN5eq4Nr1SOFSlf2E4pDI3Tcsl+dZPVE= github.com/Azure/go-autorest/autorest v0.11.30/go.mod h1:t1kpPIOpIVX7annvothKvb0stsrXa37i7b+xpmBW8Fs= -github.com/Azure/go-autorest/autorest/adal v0.9.18/go.mod h1:XVVeme+LZwABT8K5Lc3hA4nAe8LDBVle26gTrguhhPQ= github.com/Azure/go-autorest/autorest/adal v0.9.22/go.mod h1:XuAbAEUv2Tta//+voMI038TrJBqjKam0me7qR+L8Cmk= github.com/Azure/go-autorest/autorest/adal v0.9.24 h1:BHZfgGsGwdkHDyZdtQRQk1WeUdW0m2WPAwuHZwUi5i4= github.com/Azure/go-autorest/autorest/adal v0.9.24/go.mod h1:7T1+g0PYFmACYW5LlG2fcoPiPlFHjClyRGL7dRlP5c8= -github.com/Azure/go-autorest/autorest/azure/auth v0.5.13 h1:Ov8avRZi2vmrE2JcXw+tu5K/yB41r7xK9GZDiBF7NdM= -github.com/Azure/go-autorest/autorest/azure/auth v0.5.13/go.mod h1:5BAVfWLWXihP47vYrPuBKKf4cS0bXI+KM9Qx6ETDJYo= -github.com/Azure/go-autorest/autorest/azure/cli v0.4.6 h1:w77/uPk80ZET2F+AfQExZyEWtn+0Rk/uw17m9fv5Ajc= -github.com/Azure/go-autorest/autorest/azure/cli v0.4.6/go.mod h1:piCfgPho7BiIDdEQ1+g4VmKyD5y+p/XtSNqE6Hc4QD0= github.com/Azure/go-autorest/autorest/date v0.3.0 h1:7gUk1U5M/CQbp9WoqinNzJar+8KY+LPI6wiWrP/myHw= github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74= github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k= @@ -189,8 +183,6 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= -github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U= -github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= @@ -249,7 +241,6 @@ github.com/gobuffalo/flect v1.0.3/go.mod h1:A5msMlrHtLqh9umBSnvabjsMrCcCpAyzglnD github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= -github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo= github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= @@ -378,8 +369,6 @@ github.com/microsoft/go-mssqldb v1.7.2 h1:CHkFJiObW7ItKTJfHo1QX7QBBD1iV+mn1eOyRP github.com/microsoft/go-mssqldb v1.7.2/go.mod h1:kOvZKUdrhhFQmxLZqbwUV0rHkNkZpthMITIb2Ko1IoA= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=