Skip to content

Commit

Permalink
Use created-by label to cache runtime objects
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobebway committed Nov 30, 2023
1 parent 63eca19 commit c67a4ff
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
13 changes: 6 additions & 7 deletions internal/controller/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
),
}
Expand Down
4 changes: 2 additions & 2 deletions internal/label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
6 changes: 3 additions & 3 deletions internal/label/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,15 +17,15 @@ 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",
},
),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// when
got := SelectorInstanceEventing()
got := SelectorCreatedByEventingManager()

// then
require.Equal(t, tt.want, got)
Expand Down

0 comments on commit c67a4ff

Please sign in to comment.