Skip to content

Commit 376e493

Browse files
committed
Set ReconcileSuccess after necessary cli commands succeed
- ReconcileSuccess was set to true when set plugins command failed - ReconcileSuccess will only be set to true if all necessary commands (set plugins, feature flags, rebalance) are run successfullly
1 parent c273d60 commit 376e493

File tree

2 files changed

+12
-34
lines changed

2 files changed

+12
-34
lines changed

controllers/rabbitmqcluster_controller.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,23 +186,28 @@ func (r *RabbitmqClusterReconciler) Reconcile(ctx context.Context, req ctrl.Requ
186186
return ctrl.Result{RequeueAfter: requeueAfter}, err
187187
}
188188

189-
// Set ReconcileSuccess to true here because all CRUD operations to Kube API related
190-
// to child resources returned no error
191-
rabbitmqCluster.Status.SetCondition(status.ReconcileSuccess, corev1.ConditionTrue, "Success", "Created or Updated all child resources")
192-
if writerErr := r.Status().Update(ctx, rabbitmqCluster); writerErr != nil {
193-
logger.Error(writerErr, "Failed to Update Custom Resource status")
194-
}
195-
196189
if err := r.setDefaultUserStatus(ctx, rabbitmqCluster); err != nil {
197190
return ctrl.Result{}, err
198191
}
199192

200193
// By this point the StatefulSet may have finished deploying. Run any
201194
// post-deploy steps if so, or requeue until the deployment is finished.
202195
if requeueAfter, err := r.runRabbitmqCLICommandsIfAnnotated(ctx, rabbitmqCluster); err != nil || requeueAfter > 0 {
196+
if err != nil {
197+
rabbitmqCluster.Status.SetCondition(status.ReconcileSuccess, corev1.ConditionFalse, "FailedCLICommand", err.Error())
198+
if writerErr := r.Status().Update(ctx, rabbitmqCluster); writerErr != nil {
199+
logger.Error(writerErr, "Failed to update ReconcileSuccess condition state")
200+
}
201+
}
203202
return ctrl.Result{RequeueAfter: requeueAfter}, err
204203
}
205204

205+
// Set ReconcileSuccess to true after all reconciliation steps have finished with no error
206+
rabbitmqCluster.Status.SetCondition(status.ReconcileSuccess, corev1.ConditionTrue, "Success", "Finish reconciling")
207+
if writerErr := r.Status().Update(ctx, rabbitmqCluster); writerErr != nil {
208+
logger.Error(writerErr, "Failed to Update Custom Resource status")
209+
}
210+
206211
logger.Info("Finished reconciling")
207212

208213
return ctrl.Result{}, nil

controllers/rabbitmqcluster_controller_test.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -676,33 +676,6 @@ var _ = Describe("RabbitmqClusterController", func() {
676676
return "ReconcileSuccess status: condition not present"
677677
}, 5).Should(Equal("ReconcileSuccess status: False"))
678678
})
679-
680-
By("transitioning to True when a valid spec in updated", func() {
681-
// We have to Get() the CR again because Reconcile() changes the object
682-
// If we try to Update() without getting the latest version of the CR
683-
// We are very likely to hit a Conflict error
684-
Expect(client.Get(ctx, runtimeClient.ObjectKey{
685-
Name: crName,
686-
Namespace: defaultNamespace,
687-
}, cluster)).To(Succeed())
688-
cluster.Spec.Service.Annotations = map[string]string{"thisIs": "valid"}
689-
Expect(client.Update(ctx, cluster)).To(Succeed())
690-
691-
Eventually(func() string {
692-
someRabbit := &rabbitmqv1beta1.RabbitmqCluster{}
693-
Expect(client.Get(ctx, runtimeClient.ObjectKey{
694-
Name: crName,
695-
Namespace: defaultNamespace,
696-
}, someRabbit)).To(Succeed())
697-
698-
for i := range someRabbit.Status.Conditions {
699-
if someRabbit.Status.Conditions[i].Type == status.ReconcileSuccess {
700-
return fmt.Sprintf("ReconcileSuccess status: %s", someRabbit.Status.Conditions[i].Status)
701-
}
702-
}
703-
return "ReconcileSuccess status: condition not present"
704-
}, 5).Should(Equal("ReconcileSuccess status: True"))
705-
})
706679
})
707680
})
708681

0 commit comments

Comments
 (0)