@@ -22,10 +22,12 @@ import (
22
22
"fmt"
23
23
"os"
24
24
"path/filepath"
25
+ "time"
25
26
26
27
. "github.com/onsi/ginkgo/v2"
27
28
. "github.com/onsi/gomega"
28
29
apierrors "k8s.io/apimachinery/pkg/api/errors"
30
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
31
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
30
32
"k8s.io/klog/v2"
31
33
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -430,3 +432,64 @@ func DescribeAllCluster(ctx context.Context, input DescribeAllClusterInput) {
430
432
})
431
433
}
432
434
}
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