diff --git a/internal/controller/redis_controller.go b/internal/controller/redis_controller.go index 61c14e0..c878589 100644 --- a/internal/controller/redis_controller.go +++ b/internal/controller/redis_controller.go @@ -125,7 +125,7 @@ func (r *RedisReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl // If the Status of the CR is not set, this means this reconcile is the first one, therefore we update the status subresource to be unknown, and we retrieve the full CR again to ensure we have the latest object if redis.Status.Conditions == nil || len(redis.Status.Conditions) == 0 { meta.SetStatusCondition(&redis.Status.Conditions, metav1.Condition{Type: conditionAvailable, Status: metav1.ConditionUnknown, Reason: "Reconciling", Message: "Starting reconciliation"}) - if err = r.Update(ctx, redis); err != nil { + if err = r.Status().Update(ctx, redis); err != nil { log.Error(err, "Failed to update redis resource") return ctrl.Result{}, err } @@ -158,7 +158,7 @@ func (r *RedisReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl // Once all operations are done, we set the Available condition to True meta.SetStatusCondition(&redis.Status.Conditions, metav1.Condition{Type: conditionAvailable, Status: metav1.ConditionTrue, Reason: "Reconciled", Message: "Reconciliation finished"}) - if err = r.Update(ctx, redis); err != nil { + if err = r.Status().Update(ctx, redis); err != nil { log.Error(err, "Failed to set status condition for redis resource") return ctrl.Result{}, err } diff --git a/internal/controller/redis_controller_test.go b/internal/controller/redis_controller_test.go index 3a4e536..d386525 100644 --- a/internal/controller/redis_controller_test.go +++ b/internal/controller/redis_controller_test.go @@ -82,9 +82,13 @@ var _ = Describe("Redis Controller", func() { }) redis := &cachev1alpha1.Redis{} getError := k8sClient.Get(ctx, typeNamespacedName, redis) + conditionAvailable := metav1.Condition{Type: conditionAvailable, Status: metav1.ConditionTrue, Reason: "Reconciled", Message: "Reconciliation finished"} Expect(err).NotTo(HaveOccurred()) Expect(getError).NotTo(HaveOccurred()) + Expect(redis.Status.Conditions[0].Type).To(Equal(conditionAvailable.Type)) + Expect(redis.Status.Conditions[0].Status).To(Equal(conditionAvailable.Status)) + }) }) })