Skip to content

Commit

Permalink
add label selector for nats-manager
Browse files Browse the repository at this point in the history
Adds a labelselector for nats-manager instance.
  • Loading branch information
friedrichwilken committed Dec 29, 2023
1 parent 4a346ac commit 9abf991
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions internal/label/label.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package label

import (
"k8s.io/apimachinery/pkg/labels"
)

const (
// Kubernetes label keys used by nats-manager.
KeyComponent = "app.kubernetes.io/component"
KeyCreatedBy = "app.kubernetes.io/created-by"
KeyInstance = "app.kubernetes.io/instance"
KeyManagedBy = "app.kubernetes.io/managed-by"
KeyName = "app.kubernetes.io/name"
KeyPartOf = "app.kubernetes.io/part-of"
KeyDashboard = "kyma-project.io/dashboard"

// Kubernetes label keys used by nats-manager.
ValueNATS = "nats"
ValueNATSManager = "nats-manager"
)

// SelectorInstanceNATS returns a labelselector for instance ("app.kubernetes.io/instance") as usesd
// by the nats-manager.
func SelectorInstanceNATS() labels.Selector {
return labels.SelectorFromSet(map[string]string{KeyInstance: ValueNATSManager})
}
23 changes: 23 additions & 0 deletions internal/label/label_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package label_test

import (
"reflect"
"testing"

"k8s.io/apimachinery/pkg/labels"

"github.com/kyma-project/nats-manager/internal/label"
)

func TestSelectorInstanceNATS(t *testing.T) {
// arrange
wantedSelector := labels.SelectorFromSet(map[string]string{"app.kubernetes.io/instance": "nats-manager"})

// act
actualSelector := label.SelectorInstanceNATS()

// assert
if !reflect.DeepEqual(wantedSelector, actualSelector) {
t.Errorf("Expected %v, but got %v", wantedSelector, actualSelector)
}
}

0 comments on commit 9abf991

Please sign in to comment.