diff --git a/internal/controller/operator/eventing/controller.go b/internal/controller/operator/eventing/controller.go index c6d97938..181b081e 100644 --- a/internal/controller/operator/eventing/controller.go +++ b/internal/controller/operator/eventing/controller.go @@ -445,7 +445,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. @@ -519,9 +522,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 } @@ -533,7 +540,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 3843e046..71512b37 100644 --- a/internal/controller/operator/eventing/integrationtests/controller/integration_test.go +++ b/internal/controller/operator/eventing/integrationtests/controller/integration_test.go @@ -90,7 +90,7 @@ func Test_CreateEventingCR_NATS(t *testing.T) { ), givenNATSReady: false, wantMatches: gomega.And( - matchers.HaveStatusError(), + matchers.HaveStatusWarning(), matchers.HaveNATSNotAvailableCondition(), matchers.HaveFinalizer(), ), @@ -149,7 +149,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 be69d211..c2153443 100644 --- a/internal/controller/operator/eventing/status.go +++ b/internal/controller/operator/eventing/status.go @@ -26,23 +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 { + 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) }