@cryptotaxi247 / netdata-1 / commits / 2c222b28d

improvement(go.d/k8sstate): respect ignore annotation (#19342)

Ilya Mashchenko committed Jan 7, 2025 at 22:49 UTC 2c222b28d159d3dc81292f64d2d08424e55af747
1 file changed +14
src/go/plugin/go.d/collector/k8s_state/discover_pod.go
+14
@@ -4,6 +4,9 @@ package k8s_state
4
5 import (
6 "context"
7 + "strings"
8 +
9 + corev1 "k8s.io/api/core/v1"
10
11 "github.com/netdata/netdata/go/plugins/logger"
12
@@ -96,6 +99,9 @@ func (d *podDiscoverer) runDiscover(ctx context.Context, in chan<- resource) {
99 if exists {
100 r.val = item
101 }
102 + if pod, err := toPod(r); err == nil && hasIgnoreAnnotation(pod) {
103 + return
104 + }
105 send(ctx, in, r)
106 }()
107 }
@@ -104,3 +110,11 @@ func (d *podDiscoverer) runDiscover(ctx context.Context, in chan<- resource) {
110 func podSource(namespace, name string) string {
111 return "k8s/pod/" + namespace + "/" + name
112 }
113 +
114 +func hasIgnoreAnnotation(pod *corev1.Pod) bool {
115 + if pod == nil {
116 + return false
117 + }
118 + v := pod.Annotations["netdata.cloud/ignore"]
119 + return strings.EqualFold(v, "true") || strings.EqualFold(v, "yes")
120 +}