package prometheusctl import ( "reflect" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" "edge-infra.dev/pkg/k8s/meta" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/predicate" ) var ( prometheusKind = reflect.TypeOf(monitoringv1.Prometheus{}).Name() ) func predicates(prometheus meta.NamespacedObjectReference) predicate.Funcs { return predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { // process updates to the spec of Prometheus objects that we care about if e.ObjectNew.GetObjectKind().GroupVersionKind().Kind == prometheusKind && e.ObjectOld.GetGeneration() != e.ObjectNew.GetGeneration() && e.ObjectNew.GetName() == prometheus.Name && e.ObjectNew.GetNamespace() == prometheus.Namespace { return true } // otherwise, we want to reconcile `*Monitor` objects if their annotations // change and they contain the annotation that we care about if e.ObjectNew.GetObjectKind().GroupVersionKind().Kind != prometheusKind && e.ObjectNew.GetResourceVersion() != e.ObjectOld.GetResourceVersion() && e.ObjectNew.GetAnnotations()[allowedMetrics] != "" { return true } return false }, CreateFunc: func(e event.CreateEvent) bool { // only process the prometheus that we care about if e.Object.GetObjectKind().GroupVersionKind().Kind == prometheusKind && e.Object.GetName() == prometheus.Name && e.Object.GetNamespace() == prometheus.Namespace { return true } // otherwise, we want to reconcile `*Monitor` objects if they have the annotation // we care ab out if e.Object.GetAnnotations()[allowedMetrics] != "" { return true } return false }, DeleteFunc: func(_ event.DeleteEvent) bool { return true }, } }