Skip to content

Commit

Permalink
move message to const
Browse files Browse the repository at this point in the history
  • Loading branch information
friedrichwilken committed Dec 19, 2023
1 parent a58128e commit 57d8f26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
12 changes: 6 additions & 6 deletions internal/controller/nats/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Check failure on line 49 in internal/controller/nats/controller.go

View workflow job for this annotation

GitHub Actions / lint

line is 124 characters (lll)

Check failure on line 49 in internal/controller/nats/controller.go

View workflow job for this annotation

GitHub Actions / lint

line is 124 characters (lll)
)

// Reconciler reconciles a NATS object.
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions internal/controller/nats/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 57d8f26

Please sign in to comment.