Skip to content

Commit

Permalink
improvement(go.d/k8sstate): respect ignore annotation (netdata#19342)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Jan 7, 2025
1 parent 4437c51 commit 2c222b2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/go/plugin/go.d/collector/k8s_state/discover_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ package k8s_state

import (
"context"
"strings"

corev1 "k8s.io/api/core/v1"

"github.com/netdata/netdata/go/plugins/logger"

Expand Down Expand Up @@ -96,6 +99,9 @@ func (d *podDiscoverer) runDiscover(ctx context.Context, in chan<- resource) {
if exists {
r.val = item
}
if pod, err := toPod(r); err == nil && hasIgnoreAnnotation(pod) {
return
}
send(ctx, in, r)
}()
}
Expand All @@ -104,3 +110,11 @@ func (d *podDiscoverer) runDiscover(ctx context.Context, in chan<- resource) {
func podSource(namespace, name string) string {
return "k8s/pod/" + namespace + "/" + name
}

func hasIgnoreAnnotation(pod *corev1.Pod) bool {
if pod == nil {
return false
}
v := pod.Annotations["netdata.cloud/ignore"]
return strings.EqualFold(v, "true") || strings.EqualFold(v, "yes")
}

0 comments on commit 2c222b2

Please sign in to comment.