From a02878a631fcc9df72268da1cd3c69baaf7ebd51 Mon Sep 17 00:00:00 2001 From: Abhradeep Chakraborty Date: Wed, 21 Aug 2024 16:16:43 +0530 Subject: [PATCH] fix Signed-off-by: Abhradeep Chakraborty --- e2e/dragonfly_controller_test.go | 12 +++++--- internal/controller/dragonfly_controller.go | 34 ++++++++++----------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/e2e/dragonfly_controller_test.go b/e2e/dragonfly_controller_test.go index 70589e7..7702705 100644 --- a/e2e/dragonfly_controller_test.go +++ b/e2e/dragonfly_controller_test.go @@ -418,11 +418,13 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, FlakeAttempts(3), func() err = k8sClient.Update(ctx, &df) Expect(err).To(BeNil()) + GinkgoLogr.Info("start timestamp", "timestamp", time.Now().UTC()) // Wait until Dragonfly object is marked ready err = waitForDragonflyPhase(ctx, k8sClient, name, namespace, controller.PhaseReady, 3*time.Minute) Expect(err).To(BeNil()) err = waitForStatefulSetReady(ctx, k8sClient, name, namespace, 3*time.Minute) Expect(err).To(BeNil()) + GinkgoLogr.Info("end timestamp", "timestamp", time.Now().UTC()) // Check for service and statefulset var ss appsv1.StatefulSet @@ -524,11 +526,11 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, FlakeAttempts(3), func() err = k8sClient.Update(ctx, &df) Expect(err).To(BeNil()) - // // Wait until Dragonfly object is marked ready - // err = waitForDragonflyPhase(ctx, k8sClient, name, namespace, controller.PhaseReady, 1*time.Minute) - // Expect(err).To(BeNil()) - // err = waitForStatefulSetReady(ctx, k8sClient, name, namespace, 3*time.Minute) - // Expect(err).To(BeNil()) + // Wait until Dragonfly object is marked ready + err = waitForDragonflyPhase(ctx, k8sClient, name, namespace, controller.PhaseReady, 1*time.Minute) + Expect(err).To(BeNil()) + err = waitForStatefulSetReady(ctx, k8sClient, name, namespace, 3*time.Minute) + Expect(err).To(BeNil()) var svc corev1.Service err = k8sClient.Get(ctx, types.NamespacedName{ diff --git a/internal/controller/dragonfly_controller.go b/internal/controller/dragonfly_controller.go index 519a642..43ba27f 100644 --- a/internal/controller/dragonfly_controller.go +++ b/internal/controller/dragonfly_controller.go @@ -131,24 +131,6 @@ func (r *DragonflyReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } } - // perform a rollout only if the pod spec has changed - // Check if the pod spec has changed - log.Info("Checking if pod spec has changed", "updatedReplicas", statefulSet.Status.UpdatedReplicas, "currentReplicas", statefulSet.Status.Replicas) - if statefulSet.Status.UpdatedReplicas != statefulSet.Status.Replicas { - log.Info("Pod spec has changed, performing a rollout") - r.EventRecorder.Event(&df, corev1.EventTypeNormal, "Rollout", "Starting a rollout") - - // Start rollout and update status - // update status so that we can track progress - df.Status.IsRollingUpdate = true - if err := r.Status().Update(ctx, &df); err != nil { - log.Error(err, "could not update the Dragonfly object") - return ctrl.Result{Requeue: true}, err - } - - r.EventRecorder.Event(&df, corev1.EventTypeNormal, "Resources", "Performing a rollout") - } - log.Info("Updated resources for object") r.EventRecorder.Event(&df, corev1.EventTypeNormal, "Resources", "Updated resources") @@ -303,6 +285,22 @@ func (r *DragonflyReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } return ctrl.Result{}, nil + } else if statefulSet.Status.UpdatedReplicas != statefulSet.Status.Replicas { + // perform a rollout only if the pod spec has changed + // Check if the pod spec has changed + log.Info("Checking if pod spec has changed", "updatedReplicas", statefulSet.Status.UpdatedReplicas, "currentReplicas", statefulSet.Status.Replicas) + log.Info("Pod spec has changed, performing a rollout") + r.EventRecorder.Event(&df, corev1.EventTypeNormal, "Rollout", "Starting a rollout") + + // Start rollout and update status + // update status so that we can track progress + df.Status.IsRollingUpdate = true + if err := r.Status().Update(ctx, &df); err != nil { + log.Error(err, "could not update the Dragonfly object") + return ctrl.Result{Requeue: true}, err + } + + r.EventRecorder.Event(&df, corev1.EventTypeNormal, "Resources", "Performing a rollout") } return ctrl.Result{Requeue: true}, nil }