From e8aea483752bbe9b047603cf6240727e9ac19b3b Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Fri, 29 Dec 2023 17:30:22 +0100 Subject: [PATCH] add label selector for created-by: nats-manager --- internal/label/label.go | 10 ++++++++-- internal/label/label_test.go | 13 +++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/internal/label/label.go b/internal/label/label.go index 51499768..c3140965 100644 --- a/internal/label/label.go +++ b/internal/label/label.go @@ -14,13 +14,19 @@ const ( KeyPartOf = "app.kubernetes.io/part-of" KeyDashboard = "kyma-project.io/dashboard" - // Kubernetes label keys used by nats-manager. + // Kubernetes label values used by nats-manager. ValueNATS = "nats" ValueNATSManager = "nats-manager" ) -// SelectorInstanceNATS returns a labelselector for instance ("app.kubernetes.io/instance") as usesd +// SelectorInstanceNATS returns a labelselector for instance ("app.kubernetes.io/instance") as used // by the nats-manager. func SelectorInstanceNATS() labels.Selector { return labels.SelectorFromSet(map[string]string{KeyInstance: ValueNATSManager}) } + +// SelectorCreatedByNATS returns a labelselector for created-by ("app.kubernetes.io/created-by") as used +// by the nats-manager. +func SelectorCreatedByNATS() labels.Selector { + return labels.SelectorFromSet(map[string]string{KeyCreatedBy: ValueNATSManager}) +} diff --git a/internal/label/label_test.go b/internal/label/label_test.go index 4a238464..47294725 100644 --- a/internal/label/label_test.go +++ b/internal/label/label_test.go @@ -21,3 +21,16 @@ func TestSelectorInstanceNATS(t *testing.T) { t.Errorf("Expected %v, but got %v", wantedSelector, actualSelector) } } + +func TestSelectorCreatedByNATS(t *testing.T) { + // arrange + wantedSelector := labels.SelectorFromSet(map[string]string{"app.kubernetes.io/created-by": "nats-manager"}) + + // act + actualSelector := label.SelectorCreatedByNATS() + + // assert + if !reflect.DeepEqual(wantedSelector, actualSelector) { + t.Errorf("Expected %v, but got %v", wantedSelector, actualSelector) + } +}