Skip to content

Commit 4baa868

Browse files
committed
move Verify functions to framework
Signed-off-by: sivchari <[email protected]>
1 parent e7ca5f4 commit 4baa868

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

test/framework/cluster_helpers.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ import (
2222
"fmt"
2323
"os"
2424
"path/filepath"
25+
"time"
2526

2627
. "github.com/onsi/ginkgo/v2"
2728
. "github.com/onsi/gomega"
2829
apierrors "k8s.io/apimachinery/pkg/api/errors"
30+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2931
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3032
"k8s.io/klog/v2"
3133
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -430,3 +432,64 @@ func DescribeAllCluster(ctx context.Context, input DescribeAllClusterInput) {
430432
})
431433
}
432434
}
435+
436+
type VerifyClusterAvailableInput struct {
437+
Getter Getter
438+
Name string
439+
Namespace string
440+
}
441+
442+
// VerifyClusterAvailable verifies that the Cluster's Available condition is set to true.
443+
func VerifyClusterAvailable(ctx context.Context, input VerifyClusterAvailableInput) {
444+
cluster := &clusterv1.Cluster{}
445+
key := client.ObjectKey{
446+
Name: input.Name,
447+
Namespace: input.Namespace,
448+
}
449+
450+
// Wait for the cluster Available condition to stabilize.
451+
Eventually(func(g Gomega) {
452+
g.Expect(input.Getter.Get(ctx, key, cluster)).To(Succeed())
453+
for _, condition := range cluster.Status.Conditions {
454+
if condition.Type == clusterv1.AvailableCondition {
455+
g.Expect(condition.Status).To(Equal(metav1.ConditionTrue), "The Available condition on the Cluster should be set to true")
456+
g.Expect(condition.Message).To(BeEmpty(), "The Available condition on the Cluster should have an empty message")
457+
return
458+
}
459+
}
460+
}, 5*time.Minute, 10*time.Second).Should(Succeed(), "Failed to verify Cluster Available condition for %s", klog.KRef(input.Namespace, input.Name))
461+
}
462+
463+
type VerifyMachinesReadyInput struct {
464+
Lister Lister
465+
Name string
466+
Namespace string
467+
}
468+
469+
// VerifyMachinesReady verifies that all Machines' Ready condition is set to true.
470+
func VerifyMachinesReady(ctx context.Context, input VerifyMachinesReadyInput) {
471+
machineList := &clusterv1.MachineList{}
472+
473+
// Wait for all machines to have Ready condition set to true.
474+
Eventually(func(g Gomega) {
475+
g.Expect(input.Lister.List(ctx, machineList, client.InNamespace(input.Namespace),
476+
client.MatchingLabels{
477+
clusterv1.ClusterNameLabel: input.Name,
478+
})).To(Succeed())
479+
480+
g.Expect(machineList.Items).ToNot(BeEmpty(), "No machines found for cluster %s", input.Name)
481+
482+
for _, machine := range machineList.Items {
483+
readyConditionFound := false
484+
for _, condition := range machine.Status.Conditions {
485+
if condition.Type == clusterv1.ReadyCondition {
486+
readyConditionFound = true
487+
g.Expect(condition.Status).To(Equal(metav1.ConditionTrue), "The Ready condition on Machine %q should be set to true", machine.Name)
488+
g.Expect(condition.Message).To(BeEmpty(), "The Ready condition on Machine %q should have an empty message", machine.Name)
489+
break
490+
}
491+
}
492+
g.Expect(readyConditionFound).To(BeTrue(), "Machine %q should have a Ready condition", machine.Name)
493+
}
494+
}, 5*time.Minute, 10*time.Second).Should(Succeed(), "Failed to verify Machines Ready condition for Cluster %s", klog.KRef(input.Namespace, input.Name))
495+
}

0 commit comments

Comments
 (0)