Skip to content
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
53 changes: 41 additions & 12 deletions test/e2e/aks_machinepools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand All @@ -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,
})
Expand All @@ -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,
})
Expand All @@ -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
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions test/e2e/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
})
})
})
})

Expand Down