diff --git a/test/e2e/aks_machinepools.go b/test/e2e/aks_machinepools.go index efe745d05b7..6f5ecceaef8 100644 --- a/test/e2e/aks_machinepools.go +++ b/test/e2e/aks_machinepools.go @@ -23,11 +23,14 @@ import ( "context" "sync" + asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001" . "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" + infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1alpha1" + "sigs.k8s.io/cluster-api-provider-azure/exp/mutators" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/test/framework" @@ -46,7 +49,7 @@ func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSp originalReplicas := map[types.NamespacedName]int32{} for _, mp := range input.MachinePools { - originalReplicas[client.ObjectKeyFromObject(mp)] = ptr.Deref[int32](mp.Spec.Replicas, 0) + originalReplicas[client.ObjectKeyFromObject(mp)] = ptr.Deref(mp.Spec.Replicas, 0) } By("Scaling the machine pools out") @@ -58,7 +61,7 @@ func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSp framework.ScaleMachinePoolAndWait(ctx, framework.ScaleMachinePoolAndWaitInput{ ClusterProxy: bootstrapClusterProxy, Cluster: input.Cluster, - Replicas: ptr.Deref[int32](mp.Spec.Replicas, 0) + 1, + Replicas: ptr.Deref(mp.Spec.Replicas, 0) + 1, MachinePools: []*expv1.MachinePool{mp}, WaitForMachinePoolToScale: input.WaitIntervals, }) @@ -75,7 +78,7 @@ func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSp framework.ScaleMachinePoolAndWait(ctx, framework.ScaleMachinePoolAndWaitInput{ ClusterProxy: bootstrapClusterProxy, Cluster: input.Cluster, - Replicas: ptr.Deref[int32](mp.Spec.Replicas, 0) - 1, + Replicas: ptr.Deref(mp.Spec.Replicas, 0) - 1, MachinePools: []*expv1.MachinePool{mp}, WaitForMachinePoolToScale: input.WaitIntervals, }) @@ -87,15 +90,41 @@ func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSp // System node pools cannot be scaled to 0, so only include user node pools. var machinePoolsToScale []*expv1.MachinePool for _, mp := range input.MachinePools { - ammp := &infrav1.AzureManagedMachinePool{} - err := bootstrapClusterProxy.GetClient().Get(ctx, types.NamespacedName{ - Namespace: mp.Spec.Template.Spec.InfrastructureRef.Namespace, - Name: mp.Spec.Template.Spec.InfrastructureRef.Name, - }, ammp) - Expect(err).NotTo(HaveOccurred()) - - if ammp.Spec.Mode != string(infrav1.NodePoolModeSystem) { - machinePoolsToScale = append(machinePoolsToScale, mp) + switch mp.Spec.Template.Spec.InfrastructureRef.Kind { + case infrav1.AzureManagedMachinePoolKind: + ammp := &infrav1.AzureManagedMachinePool{} + err := bootstrapClusterProxy.GetClient().Get(ctx, types.NamespacedName{ + Namespace: mp.Spec.Template.Spec.InfrastructureRef.Namespace, + Name: mp.Spec.Template.Spec.InfrastructureRef.Name, + }, ammp) + Expect(err).NotTo(HaveOccurred()) + + if ammp.Spec.Mode != string(infrav1.NodePoolModeSystem) { + machinePoolsToScale = append(machinePoolsToScale, mp) + } + case infrav1exp.AzureASOManagedMachinePoolKind: + ammp := &infrav1exp.AzureASOManagedMachinePool{} + err := bootstrapClusterProxy.GetClient().Get(ctx, types.NamespacedName{ + Namespace: mp.Spec.Template.Spec.InfrastructureRef.Namespace, + Name: mp.Spec.Template.Spec.InfrastructureRef.Name, + }, ammp) + Expect(err).NotTo(HaveOccurred()) + + resources, err := mutators.ToUnstructured(ctx, ammp.Spec.Resources) + Expect(err).NotTo(HaveOccurred()) + for _, resource := range resources { + if resource.GetKind() != "ManagedClustersAgentPool" { + continue + } + // mode may not be set in spec. Get the ASO object and check in status. + resource.SetNamespace(ammp.Namespace) + agentPool := &asocontainerservicev1.ManagedClustersAgentPool{} + Expect(bootstrapClusterProxy.GetClient().Get(ctx, client.ObjectKeyFromObject(resource), agentPool)).To(Succeed()) + if ptr.Deref(agentPool.Status.Mode, "") != asocontainerservicev1.AgentPoolMode_STATUS_System { + machinePoolsToScale = append(machinePoolsToScale, mp) + } + break + } } } diff --git a/test/e2e/azure_test.go b/test/e2e/azure_test.go index bdf292c46a6..3d258f60ecd 100644 --- a/test/e2e/azure_test.go +++ b/test/e2e/azure_test.go @@ -974,6 +974,16 @@ var _ = Describe("Workload cluster creation", func() { WaitForControlPlaneMachinesReady: WaitForAKSControlPlaneReady, }), ), result) + + By("Exercising machine pools", func() { + AKSMachinePoolSpec(ctx, func() AKSMachinePoolSpecInput { + return AKSMachinePoolSpecInput{ + Cluster: result.Cluster, + MachinePools: result.MachinePools, + WaitIntervals: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"), + } + }) + }) }) })