From c67a4ff54aa81793f608ace50c6dd2f7d28481d7 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 3a6ef1f17..dc35a0598 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 { - // 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{ - &appsv1.Deployment{}: instanceEventing, - &corev1.ServiceAccount{}: instanceEventing, - &rbacv1.ClusterRole{}: instanceEventing, - &rbacv1.ClusterRoleBinding{}: instanceEventing, - &autoscalingv1.HorizontalPodAutoscaler{}: instanceEventing, + &appsv1.Deployment{}: createdByEventingManager, + &corev1.ServiceAccount{}: createdByEventingManager, + &rbacv1.ClusterRole{}: createdByEventingManager, + &rbacv1.ClusterRoleBinding{}: createdByEventingManager, + &autoscalingv1.HorizontalPodAutoscaler{}: createdByEventingManager, } return options } diff --git a/internal/controller/cache/cache_test.go b/internal/controller/cache/cache_test.go index 0e921241b..2c23e8ce5 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 9eb900d79..98946fb57 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 23b0e2030..9d3fcbd97 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)