...
1 package prometheusctl
2
3 import (
4 "reflect"
5
6 monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
7
8 "edge-infra.dev/pkg/k8s/meta"
9
10 "sigs.k8s.io/controller-runtime/pkg/event"
11 "sigs.k8s.io/controller-runtime/pkg/predicate"
12 )
13
14 var (
15 prometheusKind = reflect.TypeOf(monitoringv1.Prometheus{}).Name()
16 )
17
18 func predicates(prometheus meta.NamespacedObjectReference) predicate.Funcs {
19 return predicate.Funcs{
20 UpdateFunc: func(e event.UpdateEvent) bool {
21
22 if e.ObjectNew.GetObjectKind().GroupVersionKind().Kind == prometheusKind &&
23 e.ObjectOld.GetGeneration() != e.ObjectNew.GetGeneration() &&
24 e.ObjectNew.GetName() == prometheus.Name &&
25 e.ObjectNew.GetNamespace() == prometheus.Namespace {
26 return true
27 }
28
29
30
31 if e.ObjectNew.GetObjectKind().GroupVersionKind().Kind != prometheusKind &&
32 e.ObjectNew.GetResourceVersion() != e.ObjectOld.GetResourceVersion() &&
33 e.ObjectNew.GetAnnotations()[allowedMetrics] != "" {
34 return true
35 }
36
37 return false
38 },
39 CreateFunc: func(e event.CreateEvent) bool {
40
41 if e.Object.GetObjectKind().GroupVersionKind().Kind == prometheusKind &&
42 e.Object.GetName() == prometheus.Name &&
43 e.Object.GetNamespace() == prometheus.Namespace {
44 return true
45 }
46
47
48
49 if e.Object.GetAnnotations()[allowedMetrics] != "" {
50 return true
51 }
52
53 return false
54 },
55 DeleteFunc: func(_ event.DeleteEvent) bool {
56 return true
57 },
58 }
59 }
60
View as plain text