From ab5bef09e26ea6c3643f2b8b4668a7ad055ff7e3 Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Wed, 3 Jan 2024 15:03:27 +0100 Subject: [PATCH] managed by --- internal/controller/cache/cache.go | 20 ++++++++++---------- pkg/label/label.go | 5 +++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/internal/controller/cache/cache.go b/internal/controller/cache/cache.go index 1b3e9cef..4b9f385b 100644 --- a/internal/controller/cache/cache.go +++ b/internal/controller/cache/cache.go @@ -21,20 +21,20 @@ func New(config *rest.Config, options cache.Options) (cache.Cache, error) { func applySelectors(options cache.Options) cache.Options { // The only objects we allow are the ones with the 'created-by: nats-manager' label applied. - createdByNATSManager := fromLabelSelector(label.SelectorCreatedByNATS()) + labelSelector := fromLabelSelector(label.SelectorManagedByNATS()) // Apply the label selector to all relevant objects. options.ByObject = map[client.Object]cache.ByObject{ - &appsv1.Deployment{}: createdByNATSManager, - &autoscalingv1.HorizontalPodAutoscaler{}: createdByNATSManager, - &corev1.ServiceAccount{}: createdByNATSManager, - &rbacv1.ClusterRole{}: createdByNATSManager, - &rbacv1.ClusterRoleBinding{}: createdByNATSManager, - &policyv1.PodDisruptionBudget{}: createdByNATSManager, + &appsv1.Deployment{}: labelSelector, + &autoscalingv1.HorizontalPodAutoscaler{}: labelSelector, + &corev1.ServiceAccount{}: labelSelector, + &rbacv1.ClusterRole{}: labelSelector, + &rbacv1.ClusterRoleBinding{}: labelSelector, + &policyv1.PodDisruptionBudget{}: labelSelector, - &corev1.ConfigMap{}: createdByNATSManager, - &corev1.Secret{}: createdByNATSManager, - &corev1.Service{}: createdByNATSManager, + &corev1.ConfigMap{}: labelSelector, + &corev1.Secret{}: labelSelector, + &corev1.Service{}: labelSelector, } return options } diff --git a/pkg/label/label.go b/pkg/label/label.go index c3140965..f4f89fea 100644 --- a/pkg/label/label.go +++ b/pkg/label/label.go @@ -30,3 +30,8 @@ func SelectorInstanceNATS() labels.Selector { func SelectorCreatedByNATS() labels.Selector { return labels.SelectorFromSet(map[string]string{KeyCreatedBy: ValueNATSManager}) } + +// TODO +func SelectorManagedByNATS() labels.Selector { + return labels.SelectorFromSet(map[string]string{KeyManagedBy: ValueNATSManager}) +}