Skip to content

Commit 61b22ba

Browse files
authored
Merge pull request #7406 from killianmuldoon/test/add-delete-md
🌱 Add deleting MachineDeploymentTopology to ClusterClass changes test
2 parents 8c4f8ac + 006a17d commit 61b22ba

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/e2e/clusterclass_changes.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ func ClusterClassChangesSpec(ctx context.Context, inputGetter func() ClusterClas
178178
WaitForMachineDeployments: input.E2EConfig.GetIntervals(specName, "wait-worker-nodes"),
179179
})
180180

181+
By("Deleting a MachineDeploymentTopology in the Cluster Topology and wait for associated MachineDeployment to be deleted")
182+
deleteMachineDeploymentTopologyAndWait(ctx, deleteMachineDeploymentTopologyAndWaitInput{
183+
ClusterProxy: input.BootstrapClusterProxy,
184+
Cluster: clusterResources.Cluster,
185+
WaitForMachineDeployments: input.E2EConfig.GetIntervals(specName, "wait-worker-nodes"),
186+
})
181187
By("PASSED!")
182188
})
183189

@@ -459,3 +465,42 @@ func rebaseClusterClassAndWait(ctx context.Context, input rebaseClusterClassAndW
459465
Expect(afterControlPlane.GetGeneration()).To(Equal(beforeControlPlane.GetGeneration()),
460466
"ControlPlane generation should not be incremented during the rebase because ControlPlane should not be affected.")
461467
}
468+
469+
// deleteMachineDeploymentTopologyAndWaitInput is the input type for deleteMachineDeploymentTopologyAndWaitInput.
470+
type deleteMachineDeploymentTopologyAndWaitInput struct {
471+
ClusterProxy framework.ClusterProxy
472+
Cluster *clusterv1.Cluster
473+
WaitForMachineDeployments []interface{}
474+
}
475+
476+
// deleteMachineDeploymentTopologyAndWait deletes a MachineDeploymentTopology from the Cluster and waits until the changes
477+
// are rolled out by ensuring the associated MachineDeployment is correctly deleted.
478+
func deleteMachineDeploymentTopologyAndWait(ctx context.Context, input deleteMachineDeploymentTopologyAndWaitInput) {
479+
Expect(ctx).NotTo(BeNil(), "ctx is required for deleteMachineDeploymentTopologyAndWait")
480+
Expect(input.ClusterProxy).ToNot(BeNil(), "Invalid argument. input.ClusterProxy can't be nil when calling deleteMachineDeploymentTopologyAndWait")
481+
Expect(input.Cluster).ToNot(BeNil(), "Invalid argument. input.Cluster can't be nil when calling deleteMachineDeploymentTopologyAndWait")
482+
Expect(len(input.Cluster.Spec.Topology.Workers.MachineDeployments)).To(BeNumerically(">", 0),
483+
"Invalid Cluster. deleteMachineDeploymentTopologyAndWait requires at least one MachineDeploymentTopology to be defined in the Cluster topology")
484+
485+
log.Logf("Removing MachineDeploymentTopology from the Cluster Topology.")
486+
patchHelper, err := patch.NewHelper(input.Cluster, input.ClusterProxy.GetClient())
487+
Expect(err).ToNot(HaveOccurred())
488+
489+
// Remove the first MachineDeploymentTopology under input.Cluster.Spec.Topology.Workers.MachineDeployments
490+
mdTopologyToDelete := input.Cluster.Spec.Topology.Workers.MachineDeployments[0]
491+
input.Cluster.Spec.Topology.Workers.MachineDeployments = input.Cluster.Spec.Topology.Workers.MachineDeployments[1:]
492+
Expect(patchHelper.Patch(ctx, input.Cluster)).To(Succeed())
493+
494+
log.Logf("Waiting for MachineDeployment to be deleted.")
495+
Eventually(func() error {
496+
// Get MachineDeployment for the current MachineDeploymentTopology.
497+
mdList := &clusterv1.MachineDeploymentList{}
498+
Expect(input.ClusterProxy.GetClient().List(ctx, mdList, client.InNamespace(input.Cluster.Namespace), client.MatchingLabels{
499+
clusterv1.ClusterTopologyMachineDeploymentLabelName: mdTopologyToDelete.Name,
500+
})).To(Succeed())
501+
if len(mdList.Items) != 0 {
502+
return errors.Errorf("expected no MachineDeployment for topology %q, but got %d", mdTopologyToDelete.Name, len(mdList.Items))
503+
}
504+
return nil
505+
}, input.WaitForMachineDeployments...).Should(BeNil())
506+
}

0 commit comments

Comments
 (0)