Skip to content

Commit f5c0e0f

Browse files
committed
fix: add eventually for bastion ready
Adds an eventually check around the bastion status check. Signed-off-by: Richard Case <[email protected]>
1 parent 8a0adec commit f5c0e0f

File tree

3 files changed

+59
-16
lines changed

3 files changed

+59
-16
lines changed

test/e2e/suites/unmanaged/helpers_test.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,16 +414,31 @@ type conditionAssertion struct {
414414
reason string
415415
}
416416

417-
func expectAWSClusterConditions(m *infrav1.AWSCluster, expected []conditionAssertion) {
418-
Expect(len(m.Status.Conditions)).To(BeNumerically(">=", len(expected)), "number of conditions")
417+
func hasAWSClusterConditions(m *infrav1.AWSCluster, expected []conditionAssertion) bool {
418+
if len(m.Status.Conditions) < len(expected) {
419+
return false
420+
}
419421
for _, c := range expected {
420422
actual := conditions.Get(m, c.conditionType)
421-
Expect(actual).To(Not(BeNil()))
422-
Expect(actual.Type).To(Equal(c.conditionType))
423-
Expect(actual.Status).To(Equal(c.status))
424-
Expect(actual.Severity).To(Equal(c.severity))
425-
Expect(actual.Reason).To(Equal(c.reason))
423+
if actual == nil {
424+
return false
425+
}
426+
427+
if actual.Type != c.conditionType {
428+
return false
429+
}
430+
if actual.Status != c.status {
431+
return false
432+
}
433+
if actual.Severity != c.severity {
434+
return false
435+
}
436+
if actual.Reason != c.reason {
437+
return false
438+
}
426439
}
440+
441+
return true
427442
}
428443

429444
func createEFS() *efs.FileSystemDescription {

test/e2e/suites/unmanaged/unmanaged_functional_clusterclass_test.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"context"
2424
"fmt"
2525
"path/filepath"
26+
"time"
2627

2728
"github.com/gofrs/flock"
2829
"github.com/onsi/ginkgo/v2"
@@ -81,11 +82,24 @@ var _ = ginkgo.Context("[unmanaged] [functional] [ClusterClass]", func() {
8182
WaitForControlPlaneIntervals: e2eCtx.E2EConfig.GetIntervals(specName, "wait-control-plane"),
8283
}, result)
8384

84-
ginkgo.By("Checking if bastion host is running")
85-
awsCluster, err := GetAWSClusterByName(ctx, e2eCtx.Environment.BootstrapClusterProxy, namespace.Name, clusterName)
86-
Expect(err).To(BeNil())
87-
Expect(awsCluster.Status.Bastion.State).To(Equal(infrav1.InstanceStateRunning))
88-
expectAWSClusterConditions(awsCluster, []conditionAssertion{{infrav1.BastionHostReadyCondition, corev1.ConditionTrue, "", ""}})
85+
Eventually(func(gomega Gomega) (bool, error) {
86+
ginkgo.By("Checking if the bastion is ready")
87+
awsCluster, err := GetAWSClusterByName(ctx, e2eCtx.Environment.BootstrapClusterProxy, namespace.Name, clusterName)
88+
if err != nil {
89+
return false, err
90+
}
91+
if awsCluster.Status.Bastion.State != infrav1.InstanceStateRunning {
92+
shared.Byf("Bastion is not running, state is %s", awsCluster.Status.Bastion.State)
93+
return false, nil
94+
}
95+
96+
if !hasAWSClusterConditions(awsCluster, []conditionAssertion{{infrav1.BastionHostReadyCondition, corev1.ConditionTrue, "", ""}}) {
97+
ginkgo.By("AWSCluster missing bastion host ready condition")
98+
return false, nil
99+
}
100+
101+
return true, nil
102+
}, 15*time.Minute, 30*time.Second).Should(BeTrue(), "Should've eventually succeeded creating bastion host")
89103

90104
ginkgo.By("PASSED!")
91105
})

test/e2e/suites/unmanaged/unmanaged_functional_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,24 @@ var _ = ginkgo.Context("[unmanaged] [functional]", func() {
204204
}, result)
205205

206206
// Check if bastion host is up and running
207-
awsCluster, err := GetAWSClusterByName(ctx, e2eCtx.Environment.BootstrapClusterProxy, namespace.Name, clusterName)
208-
Expect(err).To(BeNil())
209-
Expect(awsCluster.Status.Bastion.State).To(Equal(infrav1.InstanceStateRunning))
210-
expectAWSClusterConditions(awsCluster, []conditionAssertion{{infrav1.BastionHostReadyCondition, corev1.ConditionTrue, "", ""}})
207+
Eventually(func(gomega Gomega) (bool, error) {
208+
ginkgo.By("Checking if the bastion is ready")
209+
awsCluster, err := GetAWSClusterByName(ctx, e2eCtx.Environment.BootstrapClusterProxy, namespace.Name, clusterName)
210+
if err != nil {
211+
return false, err
212+
}
213+
if awsCluster.Status.Bastion.State != infrav1.InstanceStateRunning {
214+
shared.Byf("Bastion is not running, state is %s", awsCluster.Status.Bastion.State)
215+
return false, nil
216+
}
217+
218+
if !hasAWSClusterConditions(awsCluster, []conditionAssertion{{infrav1.BastionHostReadyCondition, corev1.ConditionTrue, "", ""}}) {
219+
ginkgo.By("AWSCluster missing bastion host ready condition")
220+
return false, nil
221+
}
222+
223+
return true, nil
224+
}, 15*time.Minute, 30*time.Second).Should(BeTrue(), "Should've eventually succeeded creating bastion host")
211225

212226
mdName := clusterName + "-md01"
213227
machineTempalte := makeAWSMachineTemplate(namespace.Name, mdName, e2eCtx.E2EConfig.GetVariable(shared.AwsNodeMachineType), nil)

0 commit comments

Comments
 (0)