Skip to content

Commit

Permalink
Use created-by label to cache runtime objects (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobebway authored Jan 11, 2024
1 parent 196670b commit 384036d
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 {
//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
}
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 384036d

Please sign in to comment.