diff --git a/test/e2e/clusterclass_changes.go b/test/e2e/clusterclass_changes.go index 7d0bc50f344e..428d9ec822aa 100644 --- a/test/e2e/clusterclass_changes.go +++ b/test/e2e/clusterclass_changes.go @@ -272,16 +272,17 @@ func ClusterClassChangesSpec(ctx context.Context, inputGetter func() ClusterClas WaitForMachinePools: input.E2EConfig.GetIntervals(specName, "wait-machine-pool-nodes"), }) - Byf("Verify Cluster Available condition is true") - framework.VerifyClusterAvailable(ctx, framework.VerifyClusterAvailableInput{ - Getter: input.BootstrapClusterProxy.GetClient(), + Byf("Wait for all Machine Ready conditions are true") + framework.WaitForMachinesReady(ctx, framework.WaitForMachinesReadyInput{ + Lister: input.BootstrapClusterProxy.GetClient(), Name: clusterResources.Cluster.Name, Namespace: clusterResources.Cluster.Namespace, + Intervals: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"), }) - Byf("Verify Machines Ready condition is true") - framework.VerifyMachinesReady(ctx, framework.VerifyMachinesReadyInput{ - Lister: input.BootstrapClusterProxy.GetClient(), + Byf("Verify Cluster Available condition is true") + framework.VerifyClusterAvailable(ctx, framework.VerifyClusterAvailableInput{ + Getter: input.BootstrapClusterProxy.GetClient(), Name: clusterResources.Cluster.Name, Namespace: clusterResources.Cluster.Namespace, }) diff --git a/test/framework/machines.go b/test/framework/machines.go index 5dde9e87eac3..b02f0cde4856 100644 --- a/test/framework/machines.go +++ b/test/framework/machines.go @@ -22,6 +22,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog/v2" "sigs.k8s.io/controller-runtime/pkg/client" @@ -93,3 +94,38 @@ func WaitForClusterMachinesReady(ctx context.Context, input WaitForClusterMachin return }, intervals...).Should(Equal(len(machines.Items)), "Timed out waiting for %d nodes to be ready", len(machines.Items)) } + +type WaitForMachinesReadyInput struct { + Lister Lister + Name string + Namespace string + Intervals []interface{} +} + +func WaitForMachinesReady(ctx context.Context, input WaitForMachinesReadyInput, intervals ...interface{}) { + By("Waiting for the machines' Ready condition to be true") + machineList := &clusterv1.MachineList{} + + // Wait for all machines to have Ready condition set to true. + Eventually(func(g Gomega) { + g.Expect(input.Lister.List(ctx, machineList, client.InNamespace(input.Namespace), + client.MatchingLabels{ + clusterv1.ClusterNameLabel: input.Name, + })).To(Succeed()) + + g.Expect(machineList.Items).ToNot(BeEmpty(), "No machines found for cluster %s", input.Name) + + for _, machine := range machineList.Items { + readyConditionFound := false + for _, condition := range machine.Status.Conditions { + if condition.Type == clusterv1.ReadyCondition { + readyConditionFound = true + g.Expect(condition.Status).To(Equal(metav1.ConditionTrue), "The Ready condition on Machine %q should be set to true; message: %s", machine.Name, condition.Message) + g.Expect(condition.Message).To(BeEmpty(), "The Ready condition on Machine %q should have an empty message", machine.Name) + break + } + } + g.Expect(readyConditionFound).To(BeTrue(), "Machine %q should have a Ready condition", machine.Name) + } + }, intervals...).Should(Succeed(), "Failed to wait for Machines Ready condition for Cluster %s", klog.KRef(input.Namespace, input.Name)) +}