From 5e29be4c8832c4b6ddbb3aa01f7dca718e4cd08e Mon Sep 17 00:00:00 2001 From: Nicolas Takashi Date: Sun, 14 Jul 2024 10:42:18 +0100 Subject: [PATCH] [CHORE] upgrading helm chart (#110) (#113) --- controllers/prometheusrule_controller.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/controllers/prometheusrule_controller.go b/controllers/prometheusrule_controller.go index 0c90d4e..a953d21 100644 --- a/controllers/prometheusrule_controller.go +++ b/controllers/prometheusrule_controller.go @@ -18,7 +18,9 @@ import ( "k8s.io/utils/pointer" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/predicate" ) const ( @@ -339,7 +341,28 @@ func prometheusInnerRuleToCoralogixInnerRule(rule prometheus.Rule) coralogixv1al // SetupWithManager sets up the controller with the Manager. func (r *PrometheusRuleReconciler) SetupWithManager(mgr ctrl.Manager) error { + shouldTrackPrometheusRules := func(labels map[string]string) bool { + if value, ok := labels["app.coralogix.com/track-recording-rules"]; ok && value == "true" { + return true + } + if value, ok := labels["app.coralogix.com/track-alerting-rules"]; ok && value == "true" { + return true + } + return false + } + return ctrl.NewControllerManagedBy(mgr). For(&prometheus.PrometheusRule{}). + WithEventFilter(predicate.Funcs{ + CreateFunc: func(e event.CreateEvent) bool { + return shouldTrackPrometheusRules(e.Object.GetLabels()) + }, + UpdateFunc: func(e event.UpdateEvent) bool { + return shouldTrackPrometheusRules(e.ObjectNew.GetLabels()) || shouldTrackPrometheusRules(e.ObjectOld.GetLabels()) + }, + DeleteFunc: func(e event.DeleteEvent) bool { + return shouldTrackPrometheusRules(e.Object.GetLabels()) + }, + }). Complete(r) }