Skip to content

Commit

Permalink
add test on happy path status condition
Browse files Browse the repository at this point in the history
  • Loading branch information
tomp21 committed Dec 25, 2024
1 parent 1ab0248 commit 4aad98a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/controller/redis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/redis_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

})
})
})

0 comments on commit 4aad98a

Please sign in to comment.