Skip to content

Commit

Permalink
add managed machine pool scale tests (#2765)
Browse files Browse the repository at this point in the history
* add managed machine pool scale tests

* scale machine pools relatively

* inline unneeded variable
  • Loading branch information
nojnhuh authored Nov 16, 2022
1 parent 4985b2a commit da2ffb3
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
92 changes: 92 additions & 0 deletions test/e2e/aks.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package e2e
import (
"context"
"fmt"
"sync"

"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2020-02-01/containerservice"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network"
Expand Down Expand Up @@ -355,6 +356,97 @@ func GetLatestStableAKSKubernetesVersion(ctx context.Context, subscriptionID, lo
return maxVersion, nil
}

type AKSMachinePoolSpecInput struct {
Cluster *clusterv1.Cluster
MachinePools []*expv1.MachinePool
WaitIntervals []interface{}
}

func AKSMachinePoolSpec(ctx context.Context, inputGetter func() AKSMachinePoolSpecInput) {
input := inputGetter()
var wg sync.WaitGroup

originalReplicas := map[types.NamespacedName]int32{}
for _, mp := range input.MachinePools {
originalReplicas[client.ObjectKeyFromObject(mp)] = to.Int32(mp.Spec.Replicas)
}

By("Scaling the machine pools out")
for _, mp := range input.MachinePools {
wg.Add(1)
go func(mp *expv1.MachinePool) {
defer GinkgoRecover()
defer wg.Done()
framework.ScaleMachinePoolAndWait(ctx, framework.ScaleMachinePoolAndWaitInput{
ClusterProxy: bootstrapClusterProxy,
Cluster: input.Cluster,
Replicas: to.Int32(mp.Spec.Replicas) + 1,
MachinePools: []*expv1.MachinePool{mp},
WaitForMachinePoolToScale: input.WaitIntervals,
})
}(mp)
}
wg.Wait()

By("Scaling the machine pools in")
for _, mp := range input.MachinePools {
wg.Add(1)
go func(mp *expv1.MachinePool) {
defer GinkgoRecover()
defer wg.Done()
framework.ScaleMachinePoolAndWait(ctx, framework.ScaleMachinePoolAndWaitInput{
ClusterProxy: bootstrapClusterProxy,
Cluster: input.Cluster,
Replicas: to.Int32(mp.Spec.Replicas) - 1,
MachinePools: []*expv1.MachinePool{mp},
WaitForMachinePoolToScale: input.WaitIntervals,
})
}(mp)
}
wg.Wait()

By("Scaling the machine pools to zero")
// System node pools cannot be scaled to 0, so only include user node pools.
var machinePoolsToScale []*expv1.MachinePool
for _, mp := range input.MachinePools {
ammp := &infrav1exp.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(infrav1exp.NodePoolModeSystem) {
machinePoolsToScale = append(machinePoolsToScale, mp)
}
}

framework.ScaleMachinePoolAndWait(ctx, framework.ScaleMachinePoolAndWaitInput{
ClusterProxy: bootstrapClusterProxy,
Cluster: input.Cluster,
Replicas: 0,
MachinePools: machinePoolsToScale,
WaitForMachinePoolToScale: input.WaitIntervals,
})

By("Restoring initial replica count")
for _, mp := range input.MachinePools {
wg.Add(1)
go func(mp *expv1.MachinePool) {
defer GinkgoRecover()
defer wg.Done()
framework.ScaleMachinePoolAndWait(ctx, framework.ScaleMachinePoolAndWaitInput{
ClusterProxy: bootstrapClusterProxy,
Cluster: input.Cluster,
Replicas: originalReplicas[client.ObjectKeyFromObject(mp)],
MachinePools: []*expv1.MachinePool{mp},
WaitForMachinePoolToScale: input.WaitIntervals,
})
}(mp)
}
wg.Wait()
}

type AKSAutoscaleSpecInput struct {
Cluster *clusterv1.Cluster
MachinePool *expv1.MachinePool
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,15 @@ var _ = Describe("Workload cluster creation", func() {
},
}, 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")}
})
})

By("creating a machine pool with public IP addresses from a prefix", func() {
AKSPublicIPPrefixSpec(ctx, func() AKSPublicIPPrefixSpecInput {
return AKSPublicIPPrefixSpecInput{
Expand Down

0 comments on commit da2ffb3

Please sign in to comment.