diff --git a/pkg/models/notification/notification.go b/pkg/models/notification/notification.go index 70542290a47a8827c13d73ddcdce53da318e24e2..b1a72a6148f5e3bd483eadcf4236c41505119d19 100644 --- a/pkg/models/notification/notification.go +++ b/pkg/models/notification/notification.go @@ -138,7 +138,7 @@ func (o *operator) Get(user, resource, name, subresource string) (runtime.Object // A tenant object will be created if the user is not nil. func (o *operator) Create(user, resource string, obj runtime.Object) (runtime.Object, error) { - if err := appendLabel(user, obj); err != nil { + if err := appendLabel(user, resource, obj); err != nil { return nil, err } @@ -182,7 +182,7 @@ func (o *operator) Delete(user, resource, name string) error { // If the user is not nil, a tenant object whose tenant label matches the user will be updated. func (o *operator) Update(user, resource, name string, obj runtime.Object) (runtime.Object, error) { - if err := appendLabel(user, obj); err != nil { + if err := appendLabel(user, resource, obj); err != nil { return nil, err } @@ -292,7 +292,7 @@ func isGlobal(obj runtime.Object) bool { } } -func appendLabel(user string, obj runtime.Object) error { +func appendLabel(user, resource string, obj runtime.Object) error { accessor, err := meta.Accessor(obj) if err != nil { @@ -305,20 +305,19 @@ func appendLabel(user string, obj runtime.Object) error { labels = make(map[string]string) } - switch obj.(type) { - case *corev1.Secret: + if resource == Secret { labels[constants.NotificationManagedLabel] = "true" - default: - if user == "" { - if isConfig(obj) { - labels["type"] = "default" - } else { - labels["type"] = "global" - } + } + + if user == "" { + if isConfig(obj) { + labels["type"] = "default" } else { - labels["type"] = "tenant" - labels["user"] = user + labels["type"] = "global" } + } else { + labels["type"] = "tenant" + labels["user"] = user } accessor.SetLabels(labels) diff --git a/pkg/models/notification/notification_test.go b/pkg/models/notification/notification_test.go index 2e66afcf9fe1d1a44ed817f6f10c50d33561043e..f8059df9339d89a40f19688a871cdb1cac249590 100644 --- a/pkg/models/notification/notification_test.go +++ b/pkg/models/notification/notification_test.go @@ -111,6 +111,7 @@ func TestOperator_Create(t *testing.T) { Name: "test", Namespace: constants.NotificationSecretNamespace, Labels: map[string]string{ + "type": "global", constants.NotificationManagedLabel: "true", }, }, @@ -119,6 +120,7 @@ func TestOperator_Create(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "test", Labels: map[string]string{ + "type": "global", constants.NotificationManagedLabel: "true", }, },