Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use created-by label to cache runtime objects #275

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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