From 75cb1c226dd0bf092694706232fc046a5a251f48 Mon Sep 17 00:00:00 2001 From: Philip Gough Date: Tue, 30 Jul 2024 14:38:09 +0100 Subject: [PATCH] Watch CMO cluster monitoring ConfigMap for changes (#1549) Signed-off-by: Philip Gough --- .../observabilityaddon_controller.go | 62 +++++++++++-------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/operators/endpointmetrics/controllers/observabilityendpoint/observabilityaddon_controller.go b/operators/endpointmetrics/controllers/observabilityendpoint/observabilityaddon_controller.go index 4160b85f2..1eef31242 100644 --- a/operators/endpointmetrics/controllers/observabilityendpoint/observabilityaddon_controller.go +++ b/operators/endpointmetrics/controllers/observabilityendpoint/observabilityaddon_controller.go @@ -540,51 +540,63 @@ func (r *ObservabilityAddonReconciler) SetupWithManager(mgr ctrl.Manager) error builder.WithPredicates(getPred(openshift.CaConfigmapName, r.Namespace, false, true, true)), ). Watches( - &appsv1.Deployment{}, + &corev1.ConfigMap{}, &handler.EnqueueRequestForObject{}, - builder.WithPredicates(getPred(metricsCollectorName, r.Namespace, true, true, true)), + builder.WithPredicates(getPred(operatorconfig.ImageConfigMap, r.Namespace, true, true, false)), ). Watches( - &appsv1.Deployment{}, + &corev1.ConfigMap{}, + enqueueForAPIServerAuth(r.Namespace), + builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}), + ). + Watches( + &corev1.ConfigMap{}, &handler.EnqueueRequestForObject{}, - builder.WithPredicates(getPred(uwlMetricsCollectorName, r.Namespace, true, true, true)), + builder.WithPredicates(getPred(clusterMonitoringConfigName, promNamespace, true, true, false)), ). Watches( - &rbacv1.ClusterRoleBinding{}, + &appsv1.Deployment{}, &handler.EnqueueRequestForObject{}, - builder.WithPredicates(getPred(openshift.ClusterRoleBindingName, "", false, true, true)), + builder.WithPredicates(getPred(metricsCollectorName, r.Namespace, true, true, true)), ). Watches( - &corev1.ConfigMap{}, + &appsv1.Deployment{}, &handler.EnqueueRequestForObject{}, - builder.WithPredicates(getPred(operatorconfig.ImageConfigMap, r.Namespace, true, true, false)), + builder.WithPredicates(getPred(uwlMetricsCollectorName, r.Namespace, true, true, true)), ). Watches( &appsv1.StatefulSet{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(getPred(operatorconfig.PrometheusUserWorkload, uwlNamespace, true, false, true)), ). - // Watch the kube-system extension-apiserver-authentication ConfigMap for changes - Watches(&corev1.ConfigMap{}, handler.EnqueueRequestsFromMapFunc( - func(ctx context.Context, a client.Object) []reconcile.Request { - if a.GetName() == "extension-apiserver-authentication" && a.GetNamespace() == "kube-system" { - return []reconcile.Request{ - {NamespacedName: types.NamespacedName{ - Name: "metrics-collector-clientca-metric", - Namespace: r.Namespace, - }}, - {NamespacedName: types.NamespacedName{ - Name: "uwl-metrics-collector-clientca-metric", - Namespace: r.Namespace, - }}, - } - } - return nil - }), builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}), + Watches( + &rbacv1.ClusterRoleBinding{}, + &handler.EnqueueRequestForObject{}, + builder.WithPredicates(getPred(openshift.ClusterRoleBindingName, "", false, true, true)), ). Complete(r) } +// Watch the kube-system extension-apiserver-authentication ConfigMap for changes +func enqueueForAPIServerAuth(namespace string) handler.EventHandler { + return handler.EnqueueRequestsFromMapFunc( + func(ctx context.Context, a client.Object) []reconcile.Request { + if a.GetName() == "extension-apiserver-authentication" && a.GetNamespace() == "kube-system" { + return []reconcile.Request{ + {NamespacedName: types.NamespacedName{ + Name: "metrics-collector-clientca-metric", + Namespace: namespace, + }}, + {NamespacedName: types.NamespacedName{ + Name: "uwl-metrics-collector-clientca-metric", + Namespace: namespace, + }}, + } + } + return nil + }) +} + func remove(list []string, s string) []string { result := []string{} for _, v := range list {