Skip to content

Commit 94f5f0b

Browse files
committed
Wait for client to be ready after restore
1 parent e8881ac commit 94f5f0b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

tests/e2e/hcp_backup_restore_suite_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func runHCPBackupAndRestore(
7272
hcKubeconfig, err := h.GetHostedClusterKubeconfig(h.HostedCluster)
7373
gomega.Expect(err).ToNot(gomega.HaveOccurred())
7474
crClientForHC, err := client.New(hcKubeconfig, client.Options{Scheme: lib.Scheme})
75+
gomega.Eventually(h.ValidateClient(crClientForHC), 5*time.Minute, 2*time.Second).Should(gomega.BeTrue())
7576
gomega.Expect(err).ToNot(gomega.HaveOccurred())
7677
err = brCase.PreBackupVerifyGuest(crClientForHC, "" /*unused*/)
7778
gomega.Expect(err).ToNot(gomega.HaveOccurred(), "failed to run pre-backup verification for guest cluster: %v", err)
@@ -110,6 +111,7 @@ func runHCPBackupAndRestore(
110111
gomega.Expect(err).ToNot(gomega.HaveOccurred())
111112
crClientForHC, err := client.New(hcKubeconfig, client.Options{Scheme: lib.Scheme})
112113
gomega.Expect(err).ToNot(gomega.HaveOccurred())
114+
gomega.Eventually(h.ValidateClient(crClientForHC), 5*time.Minute, 2*time.Second).Should(gomega.BeTrue())
113115
err = brCase.PostRestoreVerifyGuest(crClientForHC, "" /*unused*/)
114116
gomega.Expect(err).ToNot(gomega.HaveOccurred(), "failed to run post-restore verification for guest cluster: %v", err)
115117
}

tests/e2e/lib/hcp/hcp.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"time"
99

10+
configv1 "github.com/openshift/api/config/v1"
1011
hypershiftv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
1112
appsv1 "k8s.io/api/apps/v1"
1213
corev1 "k8s.io/api/core/v1"
@@ -713,3 +714,14 @@ func (h *HCHandler) GetHostedClusterKubeconfig(hc *hypershiftv1.HostedCluster) (
713714
kubeconfigData := kubeconfigSecret.Data["kubeconfig"]
714715
return buildConfigFromBytes(kubeconfigData)
715716
}
717+
718+
func (h *HCHandler) ValidateClient(c client.Client) wait.ConditionFunc {
719+
return func() (bool, error) {
720+
clusterVersion := &configv1.ClusterVersion{}
721+
if err := c.Get(h.Ctx, client.ObjectKey{Name: "version"}, clusterVersion); err != nil {
722+
log.Printf("Error getting cluster version: %v", err)
723+
return false, nil
724+
}
725+
return true, nil
726+
}
727+
}

0 commit comments

Comments
 (0)