From 07314a7d135ebe280ec52bc26c0f16c9cfad97e5 Mon Sep 17 00:00:00 2001 From: Matt Boersma Date: Thu, 21 Sep 2023 11:50:52 -0600 Subject: [PATCH] Convert AKS e2e tests to SDKv2 --- test/e2e/aks_autoscaler.go | 23 +++++----- test/e2e/aks_node_labels.go | 16 ++++--- test/e2e/aks_node_taints.go | 21 +++++---- test/e2e/aks_public_ip_prefix.go | 27 +++++------ test/e2e/aks_tags.go | 29 ++++++------ test/e2e/aks_upgrade.go | 19 ++++---- test/e2e/aks_versions.go | 79 +++++++++++++++++--------------- 7 files changed, 112 insertions(+), 102 deletions(-) diff --git a/test/e2e/aks_autoscaler.go b/test/e2e/aks_autoscaler.go index 20690d96591..0a5a887209f 100644 --- a/test/e2e/aks_autoscaler.go +++ b/test/e2e/aks_autoscaler.go @@ -22,14 +22,14 @@ package e2e import ( "context" - "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2021-05-01/containerservice" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4" "github.com/Azure/go-autorest/autorest/azure/auth" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/types" "k8s.io/utils/ptr" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" - azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -47,10 +47,10 @@ func AKSAutoscaleSpec(ctx context.Context, inputGetter func() AKSAutoscaleSpecIn settings, err := auth.GetSettingsFromEnvironment() Expect(err).NotTo(HaveOccurred()) subscriptionID := settings.GetSubscriptionID() - auth, err := azureutil.GetAuthorizer(settings) + cred, err := azidentity.NewDefaultAzureCredential(nil) + Expect(err).NotTo(HaveOccurred()) + agentpoolClient, err := armcontainerservice.NewAgentPoolsClient(subscriptionID, cred, nil) Expect(err).NotTo(HaveOccurred()) - agentpoolClient := containerservice.NewAgentPoolsClient(subscriptionID) - agentpoolClient.Authorizer = auth mgmtClient := bootstrapClusterProxy.GetClient() Expect(mgmtClient).NotTo(BeNil()) @@ -68,8 +68,9 @@ func AKSAutoscaleSpec(ctx context.Context, inputGetter func() AKSAutoscaleSpecIn resourceGroupName := amcp.Spec.ResourceGroupName managedClusterName := amcp.Name agentPoolName := *ammp.Spec.Name - getAgentPool := func() (containerservice.AgentPool, error) { - return agentpoolClient.Get(ctx, resourceGroupName, managedClusterName, agentPoolName) + getAgentPool := func() (armcontainerservice.AgentPool, error) { + resp, err := agentpoolClient.Get(ctx, resourceGroupName, managedClusterName, agentPoolName, nil) + return resp.AgentPool, err } toggleAutoscaling := func() { @@ -109,20 +110,20 @@ func AKSAutoscaleSpec(ctx context.Context, inputGetter func() AKSAutoscaleSpecIn validateUntoggled(getAgentPool, inputGetter) } -func validateAKSAutoscaleDisabled(agentPoolGetter func() (containerservice.AgentPool, error), inputGetter func() AKSAutoscaleSpecInput) { +func validateAKSAutoscaleDisabled(agentPoolGetter func() (armcontainerservice.AgentPool, error), inputGetter func() AKSAutoscaleSpecInput) { By("Validating autoscaler disabled") Eventually(func(g Gomega) { agentpool, err := agentPoolGetter() g.Expect(err).NotTo(HaveOccurred()) - g.Expect(ptr.Deref(agentpool.EnableAutoScaling, false)).To(BeFalse()) + g.Expect(ptr.Deref(agentpool.Properties.EnableAutoScaling, false)).To(BeFalse()) }, inputGetter().WaitIntervals...).Should(Succeed()) } -func validateAKSAutoscaleEnabled(agentPoolGetter func() (containerservice.AgentPool, error), inputGetter func() AKSAutoscaleSpecInput) { +func validateAKSAutoscaleEnabled(agentPoolGetter func() (armcontainerservice.AgentPool, error), inputGetter func() AKSAutoscaleSpecInput) { By("Validating autoscaler enabled") Eventually(func(g Gomega) { agentpool, err := agentPoolGetter() g.Expect(err).NotTo(HaveOccurred()) - g.Expect(ptr.Deref(agentpool.EnableAutoScaling, false)).To(BeTrue()) + g.Expect(ptr.Deref(agentpool.Properties.EnableAutoScaling, false)).To(BeTrue()) }, inputGetter().WaitIntervals...).Should(Succeed()) } diff --git a/test/e2e/aks_node_labels.go b/test/e2e/aks_node_labels.go index b812e87c6c9..723ba9887a6 100644 --- a/test/e2e/aks_node_labels.go +++ b/test/e2e/aks_node_labels.go @@ -23,7 +23,8 @@ import ( "context" "sync" - "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2021-05-01/containerservice" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4" "github.com/Azure/go-autorest/autorest/azure/auth" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -47,11 +48,11 @@ func AKSNodeLabelsSpec(ctx context.Context, inputGetter func() AKSNodeLabelsSpec settings, err := auth.GetSettingsFromEnvironment() Expect(err).NotTo(HaveOccurred()) subscriptionID := settings.GetSubscriptionID() - auth, err := settings.GetAuthorizer() + cred, err := azidentity.NewDefaultAzureCredential(nil) Expect(err).NotTo(HaveOccurred()) - agentpoolsClient := containerservice.NewAgentPoolsClient(subscriptionID) - agentpoolsClient.Authorizer = auth + agentpoolsClient, err := armcontainerservice.NewAgentPoolsClient(subscriptionID, cred, nil) + Expect(err).NotTo(HaveOccurred()) mgmtClient := bootstrapClusterProxy.GetClient() Expect(mgmtClient).NotTo(BeNil()) @@ -79,13 +80,14 @@ func AKSNodeLabelsSpec(ctx context.Context, inputGetter func() AKSNodeLabelsSpec var expectedLabels map[string]string checkLabels := func(g Gomega) { - agentpool, err := agentpoolsClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name, *ammp.Spec.Name) + resp, err := agentpoolsClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name, *ammp.Spec.Name, nil) g.Expect(err).NotTo(HaveOccurred()) + agentpool := resp.AgentPool var actualLabels map[string]string - if agentpool.NodeLabels != nil { + if agentpool.Properties.NodeLabels != nil { actualLabels = make(map[string]string) - for k, v := range agentpool.NodeLabels { + for k, v := range agentpool.Properties.NodeLabels { actualLabels[k] = ptr.Deref(v, "") } } diff --git a/test/e2e/aks_node_taints.go b/test/e2e/aks_node_taints.go index 31073cb9621..a57b99510f7 100644 --- a/test/e2e/aks_node_taints.go +++ b/test/e2e/aks_node_taints.go @@ -24,12 +24,14 @@ import ( "fmt" "sync" - "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2021-05-01/containerservice" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4" "github.com/Azure/go-autorest/autorest/azure/auth" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/ptr" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" @@ -48,11 +50,11 @@ func AKSNodeTaintsSpec(ctx context.Context, inputGetter func() AKSNodeTaintsSpec settings, err := auth.GetSettingsFromEnvironment() Expect(err).NotTo(HaveOccurred()) subscriptionID := settings.GetSubscriptionID() - auth, err := settings.GetAuthorizer() + cred, err := azidentity.NewDefaultAzureCredential(nil) Expect(err).NotTo(HaveOccurred()) - agentpoolsClient := containerservice.NewAgentPoolsClient(subscriptionID) - agentpoolsClient.Authorizer = auth + agentpoolsClient, err := armcontainerservice.NewAgentPoolsClient(subscriptionID, cred, nil) + Expect(err).NotTo(HaveOccurred()) mgmtClient := bootstrapClusterProxy.GetClient() Expect(mgmtClient).NotTo(BeNil()) @@ -81,18 +83,17 @@ func AKSNodeTaintsSpec(ctx context.Context, inputGetter func() AKSNodeTaintsSpec var expectedTaints infrav1.Taints checkTaints := func(g Gomega) { - var expectedTaintStrs *[]string + var expectedTaintStrs []*string if expectedTaints != nil { - expectedTaintStrs = new([]string) - *expectedTaintStrs = make([]string, 0, len(expectedTaints)) + expectedTaintStrs = make([]*string, 0, len(expectedTaints)) for _, taint := range expectedTaints { - *expectedTaintStrs = append(*expectedTaintStrs, fmt.Sprintf("%s=%s:%s", taint.Key, taint.Value, taint.Effect)) + expectedTaintStrs = append(expectedTaintStrs, ptr.To(fmt.Sprintf("%s=%s:%s", taint.Key, taint.Value, taint.Effect))) } } - agentpool, err := agentpoolsClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name, *ammp.Spec.Name) + resp, err := agentpoolsClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name, *ammp.Spec.Name, nil) g.Expect(err).NotTo(HaveOccurred()) - actualTaintStrs := agentpool.NodeTaints + actualTaintStrs := resp.AgentPool.Properties.NodeTaints if expectedTaintStrs == nil { g.Expect(actualTaintStrs).To(BeNil()) } else { diff --git a/test/e2e/aks_public_ip_prefix.go b/test/e2e/aks_public_ip_prefix.go index 5b2758bbf7f..a119efe2b17 100644 --- a/test/e2e/aks_public_ip_prefix.go +++ b/test/e2e/aks_public_ip_prefix.go @@ -22,7 +22,8 @@ package e2e import ( "context" - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4" "github.com/Azure/go-autorest/autorest/azure/auth" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -31,7 +32,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" - azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/util/conditions" @@ -50,7 +50,7 @@ func AKSPublicIPPrefixSpec(ctx context.Context, inputGetter func() AKSPublicIPPr settings, err := auth.GetSettingsFromEnvironment() Expect(err).NotTo(HaveOccurred()) subscriptionID := settings.GetSubscriptionID() - auth, err := azureutil.GetAuthorizer(settings) + cred, err := azidentity.NewDefaultAzureCredential(nil) Expect(err).NotTo(HaveOccurred()) mgmtClient := bootstrapClusterProxy.GetClient() @@ -62,24 +62,25 @@ func AKSPublicIPPrefixSpec(ctx context.Context, inputGetter func() AKSPublicIPPr resourceGroupName := infraControlPlane.Spec.ResourceGroupName - publicIPPrefixClient := network.NewPublicIPPrefixesClient(subscriptionID) - publicIPPrefixClient.Authorizer = auth + publicIPPrefixClient, err := armnetwork.NewPublicIPPrefixesClient(subscriptionID, cred, nil) + Expect(err).NotTo(HaveOccurred()) By("Creating public IP prefix with 2 addresses") - publicIPPrefixFuture, err := publicIPPrefixClient.CreateOrUpdate(ctx, resourceGroupName, input.Cluster.Name, network.PublicIPPrefix{ + poller, err := publicIPPrefixClient.BeginCreateOrUpdate(ctx, resourceGroupName, input.Cluster.Name, armnetwork.PublicIPPrefix{ Location: ptr.To(infraControlPlane.Spec.Location), - Sku: &network.PublicIPPrefixSku{ - Name: network.PublicIPPrefixSkuNameStandard, + SKU: &armnetwork.PublicIPPrefixSKU{ + Name: ptr.To(armnetwork.PublicIPPrefixSKUNameStandard), }, - PublicIPPrefixPropertiesFormat: &network.PublicIPPrefixPropertiesFormat{ + Properties: &armnetwork.PublicIPPrefixPropertiesFormat{ PrefixLength: ptr.To[int32](31), // In bits. This provides 2 addresses. }, - }) + }, nil) Expect(err).NotTo(HaveOccurred()) - var publicIPPrefix network.PublicIPPrefix + var publicIPPrefix armnetwork.PublicIPPrefix Eventually(func(g Gomega) { - publicIPPrefix, err = publicIPPrefixFuture.Result(publicIPPrefixClient) - g.Expect(err).NotTo(HaveOccurred()) + resp, err := poller.PollUntilDone(ctx, nil) + Expect(err).NotTo(HaveOccurred()) + publicIPPrefix = resp.PublicIPPrefix }, input.WaitIntervals...).Should(Succeed(), "failed to create public IP prefix") By("Creating node pool with 2 nodes") diff --git a/test/e2e/aks_tags.go b/test/e2e/aks_tags.go index 2f0020e65d7..465154298b3 100644 --- a/test/e2e/aks_tags.go +++ b/test/e2e/aks_tags.go @@ -23,7 +23,8 @@ import ( "context" "sync" - "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2021-05-01/containerservice" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4" "github.com/Azure/go-autorest/autorest/azure/auth" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -47,14 +48,14 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional settings, err := auth.GetSettingsFromEnvironment() Expect(err).NotTo(HaveOccurred()) subscriptionID := settings.GetSubscriptionID() - auth, err := settings.GetAuthorizer() + cred, err := azidentity.NewDefaultAzureCredential(nil) Expect(err).NotTo(HaveOccurred()) - managedclustersClient := containerservice.NewManagedClustersClient(subscriptionID) - managedclustersClient.Authorizer = auth + managedclustersClient, err := armcontainerservice.NewManagedClustersClient(subscriptionID, cred, nil) + Expect(err).NotTo(HaveOccurred()) - agentpoolsClient := containerservice.NewAgentPoolsClient(subscriptionID) - agentpoolsClient.Authorizer = auth + agentpoolsClient, err := armcontainerservice.NewAgentPoolsClient(subscriptionID, cred, nil) + Expect(err).NotTo(HaveOccurred()) mgmtClient := bootstrapClusterProxy.GetClient() Expect(mgmtClient).NotTo(BeNil()) @@ -74,9 +75,9 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional defer wg.Done() nonAdditionalTagKeys := map[string]struct{}{} - managedcluster, err := managedclustersClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name) + resp, err := managedclustersClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name, nil) Expect(err).NotTo(HaveOccurred()) - for k := range managedcluster.Tags { + for k := range resp.ManagedCluster.Tags { if _, exists := infraControlPlane.Spec.AdditionalTags[k]; !exists { nonAdditionalTagKeys[k] = struct{}{} } @@ -84,9 +85,9 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional var expectedTags infrav1.Tags checkTags := func(g Gomega) { - managedcluster, err := managedclustersClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name) + resp, err := managedclustersClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name, nil) g.Expect(err).NotTo(HaveOccurred()) - actualTags := converters.MapToTags(managedcluster.Tags) + actualTags := converters.MapToTags(resp.ManagedCluster.Tags) // Ignore tags not originally specified in spec.additionalTags for k := range nonAdditionalTagKeys { delete(actualTags, k) @@ -158,9 +159,9 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional }, ammp)).To(Succeed()) nonAdditionalTagKeys := map[string]struct{}{} - agentpool, err := agentpoolsClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name, *ammp.Spec.Name) + resp, err := agentpoolsClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name, *ammp.Spec.Name, nil) Expect(err).NotTo(HaveOccurred()) - for k := range agentpool.Tags { + for k := range resp.AgentPool.Properties.Tags { if _, exists := infraControlPlane.Spec.AdditionalTags[k]; !exists { nonAdditionalTagKeys[k] = struct{}{} } @@ -168,9 +169,9 @@ func AKSAdditionalTagsSpec(ctx context.Context, inputGetter func() AKSAdditional var expectedTags infrav1.Tags checkTags := func(g Gomega) { - agentpool, err := agentpoolsClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name, *ammp.Spec.Name) + resp, err := agentpoolsClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name, *ammp.Spec.Name, nil) g.Expect(err).NotTo(HaveOccurred()) - actualTags := converters.MapToTags(agentpool.Tags) + actualTags := converters.MapToTags(resp.AgentPool.Properties.Tags) // Ignore tags not originally specified in spec.additionalTags for k := range nonAdditionalTagKeys { delete(actualTags, k) diff --git a/test/e2e/aks_upgrade.go b/test/e2e/aks_upgrade.go index 8b3678dc56b..2d2e07d574d 100644 --- a/test/e2e/aks_upgrade.go +++ b/test/e2e/aks_upgrade.go @@ -22,12 +22,12 @@ package e2e import ( "context" - "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2021-05-01/containerservice" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4" "github.com/Azure/go-autorest/autorest/azure/auth" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" - azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/test/framework" @@ -48,11 +48,11 @@ func AKSUpgradeSpec(ctx context.Context, inputGetter func() AKSUpgradeSpecInput) settings, err := auth.GetSettingsFromEnvironment() Expect(err).NotTo(HaveOccurred()) subscriptionID := settings.GetSubscriptionID() - auth, err := azureutil.GetAuthorizer(settings) + cred, err := azidentity.NewDefaultAzureCredential(nil) Expect(err).NotTo(HaveOccurred()) - managedClustersClient := containerservice.NewManagedClustersClient(subscriptionID) - managedClustersClient.Authorizer = auth + managedClustersClient, err := armcontainerservice.NewManagedClustersClient(subscriptionID, cred, nil) + Expect(err).NotTo(HaveOccurred()) mgmtClient := bootstrapClusterProxy.GetClient() Expect(mgmtClient).NotTo(BeNil()) @@ -67,11 +67,12 @@ func AKSUpgradeSpec(ctx context.Context, inputGetter func() AKSUpgradeSpecInput) }, inputGetter().WaitForControlPlane...).Should(Succeed()) Eventually(func(g Gomega) { - aksCluster, err := managedClustersClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name) + resp, err := managedClustersClient.Get(ctx, infraControlPlane.Spec.ResourceGroupName, infraControlPlane.Name, nil) g.Expect(err).NotTo(HaveOccurred()) - g.Expect(aksCluster.ManagedClusterProperties).NotTo(BeNil()) - g.Expect(aksCluster.ManagedClusterProperties.KubernetesVersion).NotTo(BeNil()) - g.Expect("v" + *aksCluster.KubernetesVersion).To(Equal(input.KubernetesVersionUpgradeTo)) + aksCluster := resp.ManagedCluster + g.Expect(aksCluster.Properties).NotTo(BeNil()) + g.Expect(aksCluster.Properties.KubernetesVersion).NotTo(BeNil()) + g.Expect("v" + *aksCluster.Properties.KubernetesVersion).To(Equal(input.KubernetesVersionUpgradeTo)) }, input.WaitForControlPlane...).Should(Succeed()) By("Upgrading the machinepool instances") diff --git a/test/e2e/aks_versions.go b/test/e2e/aks_versions.go index 141948db61b..e864c6ac15c 100644 --- a/test/e2e/aks_versions.go +++ b/test/e2e/aks_versions.go @@ -23,12 +23,13 @@ import ( "context" "fmt" - "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2020-02-01/containerservice" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4" "github.com/Azure/go-autorest/autorest/azure/auth" . "github.com/onsi/gomega" "github.com/pkg/errors" "golang.org/x/mod/semver" - azureutil "sigs.k8s.io/cluster-api-provider-azure/util/azure" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/test/framework/clusterctl" "sigs.k8s.io/controller-runtime/pkg/client" @@ -74,17 +75,15 @@ func byClusterOptions(name, namespace string) []client.ListOption { // If the desired version is not available, we check for any available patch version using desired version's Major.Minor semver release. // If no versions are available in the desired version's Major.Minor semver release, we return an error. func GetWorkingAKSKubernetesVersion(ctx context.Context, subscriptionID, location, version string) (string, error) { - settings, err := auth.GetSettingsFromEnvironment() + cred, err := azidentity.NewDefaultAzureCredential(nil) if err != nil { - return "", errors.Wrap(err, "failed to get settings from environment") + return "", errors.Wrap(err, "failed to create a default credential") } - authorizer, err := azureutil.GetAuthorizer(settings) + managedClustersClient, err := armcontainerservice.NewManagedClustersClient(subscriptionID, cred, nil) if err != nil { - return "", errors.Wrap(err, "failed to create an Authorizer") + return "", errors.Wrap(err, "failed to create a ContainerServices client") } - containerServiceClient := containerservice.NewContainerServicesClient(subscriptionID) - containerServiceClient.Authorizer = authorizer - result, err := containerServiceClient.ListOrchestrators(ctx, location, ManagedClustersResourceType) + result, err := managedClustersClient.ListKubernetesVersions(ctx, location, nil) if err != nil { return "", errors.Wrap(err, "failed to list Orchestrators") } @@ -106,21 +105,26 @@ func GetWorkingAKSKubernetesVersion(ctx context.Context, subscriptionID, locatio baseVersion := fmt.Sprintf("%s.0", semver.MajorMinor(version)) maxVersion := fmt.Sprintf("%s.0", semver.MajorMinor(version)) var foundWorkingVersion bool - for _, o := range *result.Orchestrators { - orchVersion := *o.OrchestratorVersion - // semver comparisons require a "v" prefix - if orchVersion[:1] != "v" { - orchVersion = fmt.Sprintf("v%s", *o.OrchestratorVersion) - } - // if the inputted version matches with an available AKS version we can return immediately - if orchVersion == version && !latestStableVersionDesired { - return version, nil - } - - // or, keep track of the highest aks version for a given major.minor - if semver.MajorMinor(orchVersion) == semver.MajorMinor(maxVersion) && semver.Compare(orchVersion, maxVersion) >= 0 { - maxVersion = orchVersion - foundWorkingVersion = true + for _, minor := range result.KubernetesVersionListResult.Values { + for patch := range minor.PatchVersions { + orchVersion := patch + + // semver comparisons require a "v" prefix + if patch[:1] != "v" { + orchVersion = "v" + patch + } + if semver.MajorMinor(orchVersion) != semver.MajorMinor(baseVersion) { + continue + } + // if the inputted version matches with an available AKS version we can return immediately + if orchVersion == version && !latestStableVersionDesired { + return version, nil + } + // or, keep track of the highest aks version for a given major.minor + if semver.Compare(orchVersion, maxVersion) >= 0 { + maxVersion = orchVersion + foundWorkingVersion = true + } } } @@ -144,33 +148,32 @@ func GetNextLatestStableAKSKubernetesVersion(ctx context.Context, subscriptionID } func getLatestStableAKSKubernetesVersionOffset(ctx context.Context, subscriptionID, location string, offset int) (string, error) { - settings, err := auth.GetSettingsFromEnvironment() + cred, err := azidentity.NewDefaultAzureCredential(nil) if err != nil { - return "", errors.Wrap(err, "failed to get settings from environment") + return "", errors.Wrap(err, "failed to create a default credential") } - authorizer, err := azureutil.GetAuthorizer(settings) + managedClustersClient, err := armcontainerservice.NewManagedClustersClient(subscriptionID, cred, nil) if err != nil { - return "", errors.Wrap(err, "failed to create an Authorizer") + return "", errors.Wrap(err, "failed to create a ContainerServices client") } - containerServiceClient := containerservice.NewContainerServicesClient(subscriptionID) - containerServiceClient.Authorizer = authorizer - result, err := containerServiceClient.ListOrchestrators(ctx, location, ManagedClustersResourceType) + result, err := managedClustersClient.ListKubernetesVersions(ctx, location, nil) if err != nil { return "", errors.Wrap(err, "failed to list Orchestrators") } var orchestratorversions []string var foundWorkingVersion bool - var orchVersion string + var version string var maxVersion string - for _, o := range *result.Orchestrators { - orchVersion = *o.OrchestratorVersion - // semver comparisons require a "v" prefix - if orchVersion[:1] != "v" && o.IsPreview == nil { - orchVersion = fmt.Sprintf("v%s", *o.OrchestratorVersion) + for _, minor := range result.KubernetesVersionListResult.Values { + for patch := range minor.PatchVersions { + // semver comparisons require a "v" prefix + if patch[:1] != "v" && !ptr.Deref(minor.IsPreview, false) { + version = "v" + patch + } + orchestratorversions = append(orchestratorversions, version) } - orchestratorversions = append(orchestratorversions, orchVersion) } semver.Sort(orchestratorversions) maxVersion = orchestratorversions[len(orchestratorversions)-1-offset]