diff --git a/internal/controller/operator/eventing/controller.go b/internal/controller/operator/eventing/controller.go index ce7de177..8ac0384b 100644 --- a/internal/controller/operator/eventing/controller.go +++ b/internal/controller/operator/eventing/controller.go @@ -448,7 +448,10 @@ func (r *Reconciler) handleEventingReconcile(ctx context.Context, // set state processing if not set yet r.InitStateProcessing(eventing) if eventing.Spec.Backend == nil { - return ctrl.Result{Requeue: true}, r.syncStatusForEmptyBackend(ctx, eventing, log) + return kctrl.Result{Requeue: true}, r.syncStatusForEmptyBackend(ctx, + operatorv1alpha1.ConditionReasonBackendNotSpecified, + operatorv1alpha1.ConditionBackendNotSpecifiedMessage, + eventing, log) } // sync webhooks CABundle. @@ -523,9 +526,13 @@ func (r *Reconciler) reconcileNATSBackend(ctx context.Context, eventing *operato // into CrashLoopBackOff. log.Infof("NATS module not enabled, deleting publisher proxy resources") delErr := r.eventingManager.DeletePublisherProxyResources(ctx, eventing) + if delErr != nil { + return kctrl.Result{}, delErr + } // update the Eventing CR status. notFoundErr := fmt.Errorf("NATS module has to be installed: %v", err) - return kctrl.Result{}, errors.Join(r.syncStatusWithNATSErr(ctx, eventing, notFoundErr, log), delErr) + return kctrl.Result{}, r.syncStatusWithNATSState(ctx, operatorv1alpha1.StateWarning, eventing, + notFoundErr, log) } return kctrl.Result{}, err } @@ -537,7 +544,7 @@ func (r *Reconciler) reconcileNATSBackend(ctx context.Context, eventing *operato // check nats CR if it exists and is in natsAvailable state err = r.checkNATSAvailability(ctx, eventing) if err != nil { - return kctrl.Result{}, r.syncStatusWithNATSErr(ctx, eventing, err, log) + return kctrl.Result{}, r.syncStatusWithNATSState(ctx, operatorv1alpha1.StateWarning, eventing, err, log) } // set NATSAvailable condition to true and update status diff --git a/internal/controller/operator/eventing/integrationtests/controller/integration_test.go b/internal/controller/operator/eventing/integrationtests/controller/integration_test.go index 9946d0a5..d577b29b 100644 --- a/internal/controller/operator/eventing/integrationtests/controller/integration_test.go +++ b/internal/controller/operator/eventing/integrationtests/controller/integration_test.go @@ -87,7 +87,7 @@ func Test_CreateEventingCR_NATS(t *testing.T) { ), givenNATSReady: false, wantMatches: gomega.And( - matchers.HaveStatusError(), + matchers.HaveStatusWarning(), matchers.HaveNATSNotAvailableCondition(), matchers.HaveFinalizer(), ), @@ -146,7 +146,7 @@ func Test_CreateEventingCR_NATS(t *testing.T) { ), givenNATSCRDMissing: true, wantMatches: gomega.And( - matchers.HaveStatusError(), + matchers.HaveStatusWarning(), matchers.HaveNATSNotAvailableConditionWith("NATS module has to be installed: "+ "customresourcedefinitions.apiextensions.k8s.io \"nats.operator.kyma-project.io\" not found"), matchers.HaveFinalizer(), diff --git a/internal/controller/operator/eventing/status.go b/internal/controller/operator/eventing/status.go index f5674794..63985e04 100644 --- a/internal/controller/operator/eventing/status.go +++ b/internal/controller/operator/eventing/status.go @@ -26,24 +26,29 @@ func (es *Reconciler) InitStateProcessing(eventing *operatorv1alpha1.Eventing) { // syncStatusWithNATSErr syncs Eventing status and sets an error state. // Returns the relevant error. func (r *Reconciler) syncStatusWithNATSErr(ctx context.Context, - eventing *operatorv1alpha1.Eventing, err error, log *zap.SugaredLogger, -) error { + eventing *operatorv1alpha1.Eventing, err error, log *zap.SugaredLogger) error { + return r.syncStatusWithNATSState(ctx, operatorv1alpha1.StateError, eventing, err, log) +} + +func (r *Reconciler) syncStatusWithNATSState(ctx context.Context, state string, + eventing *operatorv1alpha1.Eventing, err error, log *zap.SugaredLogger) error { // Set error state in status - eventing.Status.SetStateError() - eventing.Status.UpdateConditionBackendAvailable(kmetav1.ConditionFalse, operatorv1alpha1.ConditionReasonNATSNotAvailable, + eventing.Status.State = state + eventing.Status.UpdateConditionBackendAvailable(kmetav1.ConditionFalse, + operatorv1alpha1.ConditionReasonNATSNotAvailable, err.Error()) return errors.Join(err, r.syncEventingStatus(ctx, eventing, log)) } -func (r *Reconciler) syncStatusForEmptyBackend(ctx context.Context, - eventing *operatorv1alpha1.Eventing, log *zap.SugaredLogger) error { +func (r *Reconciler) syncStatusForEmptyBackend(ctx context.Context, reason operatorv1alpha1.ConditionReason, + message string, eventing *operatorv1alpha1.Eventing, log *zap.SugaredLogger) error { // Set error state in status eventing.Status.SetStateWarning() eventing.Status.UpdateConditionBackendAvailable( kmetav1.ConditionFalse, operatorv1alpha1.ConditionReasonBackendNotSpecified, - operatorv1alpha1.ConditionBackendNotSpecifiedMessage) + message) return r.syncEventingStatus(ctx, eventing, log) }