diff --git a/internal/controller/nats/controller.go b/internal/controller/nats/controller.go index 51126560..29012af9 100644 --- a/internal/controller/nats/controller.go +++ b/internal/controller/nats/controller.go @@ -42,10 +42,11 @@ import ( ) const ( - NATSFinalizerName = "nats.operator.kyma-project.io/finalizer" - ControllerName = "nats-manager" - ManagedByLabelKey = "app.kubernetes.io/managed-by" - ManagedByLabelValue = ControllerName + NATSFinalizerName = "nats.operator.kyma-project.io/finalizer" + ControllerName = "nats-manager" + ManagedByLabelKey = "app.kubernetes.io/managed-by" + ManagedByLabelValue = ControllerName + CreationNotAllowedMsg = "Only a single NATS CR with name: %s and namespace: %s is allowed to be created in a Kyma cluster." ) // Reconciler reconciles a NATS object. @@ -162,8 +163,7 @@ func (r *Reconciler) handleNATSCRAllowedCheck(ctx context.Context, nats *natsv1a // Update conditions in status. nats.Status.UpdateConditionStatefulSet(metav1.ConditionFalse, natsv1alpha1.ConditionReasonForbidden, "") - errorMessage := fmt.Sprintf("Only a single NATS CR with name: %s and namespace: %s "+ - "is allowed to be created in a Kyma cluster.", r.allowedNATSCR.Name, r.allowedNATSCR.Namespace) + errorMessage := fmt.Sprintf(CreationNotAllowedMsg, r.allowedNATSCR.Name, r.allowedNATSCR.Namespace) nats.Status.UpdateConditionAvailable(metav1.ConditionFalse, natsv1alpha1.ConditionReasonForbidden, errorMessage) events.Warn(r.recorder, nats, natsv1alpha1.ConditionReasonForbidden, errorMessage) diff --git a/internal/controller/nats/controller_test.go b/internal/controller/nats/controller_test.go index 047ca5ec..38481a12 100644 --- a/internal/controller/nats/controller_test.go +++ b/internal/controller/nats/controller_test.go @@ -211,17 +211,13 @@ func Test_handleNATSCRAllowedCheck(t *testing.T) { Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: string(natsv1alpha1.ConditionReasonForbidden), - Message: fmt.Sprintf("Only a single NATS CR with name: %s and namespace: %s "+ - "is allowed to be created in a Kyma cluster.", givenAllowedNATS.Name, - givenAllowedNATS.Namespace), + Message: fmt.Sprintf(CreationNotAllowedMsg, givenAllowedNATS.Name, givenAllowedNATS.Namespace), }, } require.True(t, natsv1alpha1.ConditionsEquals(wantConditions, gotNATS.Status.Conditions)) wantK8sEvent := []string{ - fmt.Sprintf("Warning Forbidden Only a single NATS CR with name: %s and namespace: %s "+ - "is allowed to be created in a Kyma cluster.", givenAllowedNATS.Name, - givenAllowedNATS.Namespace), + fmt.Sprintf(CreationNotAllowedMsg, givenAllowedNATS.Name, givenAllowedNATS.Namespace), } // check k8s events