Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert AKS e2e tests to SDKv2 #4026

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions test/e2e/aks_autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())

Expand All @@ -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() {
Expand Down Expand Up @@ -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())
}
16 changes: 9 additions & 7 deletions test/e2e/aks_node_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())
Expand Down Expand Up @@ -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, "")
}
}
Expand Down
21 changes: 11 additions & 10 deletions test/e2e/aks_node_taints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())
Expand Down Expand Up @@ -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 {
Expand Down
27 changes: 14 additions & 13 deletions test/e2e/aks_public_ip_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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()
Expand All @@ -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")
Expand Down
29 changes: 15 additions & 14 deletions test/e2e/aks_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())
Expand All @@ -74,19 +75,19 @@ 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{}{}
}
}

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)
Expand Down Expand Up @@ -158,19 +159,19 @@ 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{}{}
}
}

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)
Expand Down
19 changes: 10 additions & 9 deletions test/e2e/aks_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())
Expand All @@ -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")
Expand Down
Loading