From 384893cd1258583a75a76492110e41ee29631de8 Mon Sep 17 00:00:00 2001 From: Timofei Larkin Date: Tue, 25 Jun 2024 15:52:49 +0300 Subject: [PATCH] allow time for async things to finish in e2e tests --- internal/controller/etcdcluster_controller.go | 1 + internal/controller/observables.go | 16 ++++----- test/e2e/e2e_test.go | 34 +++++++++++++++++-- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/internal/controller/etcdcluster_controller.go b/internal/controller/etcdcluster_controller.go index b086ceca..981a3c3b 100644 --- a/internal/controller/etcdcluster_controller.go +++ b/internal/controller/etcdcluster_controller.go @@ -111,6 +111,7 @@ func (r *EtcdClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) if !state.endpointsFound { if !state.stsExists { // TODO: happy path for new cluster creation + log.Debug(ctx, "happy path for new cluster creation (not yet implemented)") } } diff --git a/internal/controller/observables.go b/internal/controller/observables.go index e79b35e4..adbaba3f 100644 --- a/internal/controller/observables.go +++ b/internal/controller/observables.go @@ -22,13 +22,13 @@ type etcdStatus struct { // observables stores observations that the operator can make about // states of objects in kubernetes type observables struct { - statefulSet appsv1.StatefulSet - stsExists bool - endpointsFound bool - etcdStatuses []etcdStatus - clusterID uint64 - endpointsReached int - pvcs []corev1.PersistentVolumeClaim + statefulSet appsv1.StatefulSet + stsExists bool + endpointsFound bool + etcdStatuses []etcdStatus + clusterID uint64 + _ int + _ []corev1.PersistentVolumeClaim } // setClusterID populates the clusterID field based on etcdStatuses @@ -68,7 +68,7 @@ func (s *etcdStatus) fill(ctx context.Context, c *clientv3.Client) { } // TODO: make a real function -func (o *observables) desiredReplicas() int { +func (o *observables) _() int { if o.etcdStatuses != nil { for i := range o.etcdStatuses { if o.etcdStatuses[i].memberList != nil { diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index aadc826f..9b18844f 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -21,6 +21,7 @@ import ( "os" "os/exec" "sync" + "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -95,6 +96,15 @@ var _ = Describe("etcd-operator", Ordered, func() { ExpectWithOffset(1, err).NotTo(HaveOccurred()) }) + Eventually(func() error { + cmd := exec.Command("kubectl", "get", + "statefulset/test", + "--namespace", namespace, + ) + _, err = utils.Run(cmd) + return err + }, time.Second*20, time.Second*2).Should(Succeed()) + By("wait for statefulset is ready", func() { cmd := exec.Command("kubectl", "wait", "statefulset/test", @@ -144,6 +154,15 @@ var _ = Describe("etcd-operator", Ordered, func() { ExpectWithOffset(1, err).NotTo(HaveOccurred()) }) + Eventually(func() error { + cmd := exec.Command("kubectl", "get", + "statefulset/test", + "--namespace", namespace, + ) + _, err = utils.Run(cmd) + return err + }, time.Second*20, time.Second*2).Should(Succeed()) + By("wait for statefulset is ready", func() { cmd := exec.Command("kubectl", "wait", "statefulset/test", @@ -192,6 +211,15 @@ var _ = Describe("etcd-operator", Ordered, func() { ExpectWithOffset(1, err).NotTo(HaveOccurred()) }) + Eventually(func() error { + cmd := exec.Command("kubectl", "get", + "statefulset/test", + "--namespace", namespace, + ) + _, err = utils.Run(cmd) + return err + }, time.Second*20, time.Second*2).Should(Succeed()) + By("wait for statefulset is ready", func() { cmd := exec.Command("kubectl", "wait", "statefulset/test", @@ -217,8 +245,10 @@ var _ = Describe("etcd-operator", Ordered, func() { auth := clientv3.NewAuth(client) By("check root role is created", func() { - _, err = auth.RoleGet(ctx, "root") - Expect(err).NotTo(HaveOccurred()) + Eventually(func() error { + _, err = auth.RoleGet(ctx, "root") + return err + }, time.Second*20, time.Second*2).Should(Succeed()) }) By("check root user is created and has root role", func() {