From 78ec8b62a7829ba6ac07274a1a4ed6f8e60a162b Mon Sep 17 00:00:00 2001 From: marcobebway Date: Thu, 30 Nov 2023 17:40:33 +0100 Subject: [PATCH] Use created-by label to cache runtime objects --- internal/controller/cache/cache.go | 13 ++++++------- internal/controller/cache/cache_test.go | 2 +- internal/label/label.go | 4 ++-- internal/label/label_test.go | 6 +++--- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/internal/controller/cache/cache.go b/internal/controller/cache/cache.go index e201aa5e..9368f7d9 100644 --- a/internal/controller/cache/cache.go +++ b/internal/controller/cache/cache.go @@ -19,14 +19,13 @@ func New(config *rest.Config, options cache.Options) (cache.Cache, error) { // applySelectors applies label selectors to runtime objects created by the EventingManager. func applySelectors(options cache.Options) cache.Options { - //nolint:godox // TODO(marcobebway) filter by label "app.kubernetes.io/created-by=eventing-manager" when it is released - instanceEventing := fromLabelSelector(label.SelectorInstanceEventing()) + createdByEventingManager := fromLabelSelector(label.SelectorCreatedByEventingManager()) options.ByObject = map[client.Object]cache.ByObject{ - &kappsv1.Deployment{}: instanceEventing, - &kcorev1.ServiceAccount{}: instanceEventing, - &krbacv1.ClusterRole{}: instanceEventing, - &krbacv1.ClusterRoleBinding{}: instanceEventing, - &kautoscalingv1.HorizontalPodAutoscaler{}: instanceEventing, + &kappsv1.Deployment{}: createdByEventingManager, + &kcorev1.ServiceAccount{}: createdByEventingManager, + &krbacv1.ClusterRole{}: createdByEventingManager, + &krbacv1.ClusterRoleBinding{}: createdByEventingManager, + &kautoscalingv1.HorizontalPodAutoscaler{}: createdByEventingManager, } return options } diff --git a/internal/controller/cache/cache_test.go b/internal/controller/cache/cache_test.go index 7b070111..f159e5dc 100644 --- a/internal/controller/cache/cache_test.go +++ b/internal/controller/cache/cache_test.go @@ -20,7 +20,7 @@ func Test_applySelectors(t *testing.T) { selector := cache.ByObject{ Label: labels.SelectorFromSet( map[string]string{ - "app.kubernetes.io/instance": "eventing", + "app.kubernetes.io/created-by": "eventing-manager", }, ), } diff --git a/internal/label/label.go b/internal/label/label.go index 9eb900d7..98946fb5 100644 --- a/internal/label/label.go +++ b/internal/label/label.go @@ -19,6 +19,6 @@ const ( ValueEventing = "eventing" ) -func SelectorInstanceEventing() labels.Selector { - return labels.SelectorFromSet(map[string]string{KeyInstance: ValueEventing}) +func SelectorCreatedByEventingManager() labels.Selector { + return labels.SelectorFromSet(map[string]string{KeyCreatedBy: ValueEventingManager}) } diff --git a/internal/label/label_test.go b/internal/label/label_test.go index 23b0e203..9d3fcbd9 100644 --- a/internal/label/label_test.go +++ b/internal/label/label_test.go @@ -7,7 +7,7 @@ import ( "k8s.io/apimachinery/pkg/labels" ) -func TestSelectorInstanceEventing(t *testing.T) { +func TestSelectorCreatedByEventingManager(t *testing.T) { // given tests := []struct { name string @@ -17,7 +17,7 @@ func TestSelectorInstanceEventing(t *testing.T) { name: "should return the correct selector", want: labels.SelectorFromSet( map[string]string{ - "app.kubernetes.io/instance": "eventing", + "app.kubernetes.io/created-by": "eventing-manager", }, ), }, @@ -25,7 +25,7 @@ func TestSelectorInstanceEventing(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // when - got := SelectorInstanceEventing() + got := SelectorCreatedByEventingManager() // then require.Equal(t, tt.want, got)