From cd65887ad0f2eda08a4e957b4ca6cba04f0f3f14 Mon Sep 17 00:00:00 2001
From: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Date: Mon, 4 Jan 2021 23:35:27 +0100
Subject: [PATCH] Avoid duplicated notifications with Kubernetes DaemonSet
 (#252)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
---
 pkg/k8s/pod.go | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/pkg/k8s/pod.go b/pkg/k8s/pod.go
index 15b08a7e..bf7a9fbb 100644
--- a/pkg/k8s/pod.go
+++ b/pkg/k8s/pod.go
@@ -16,7 +16,9 @@ func (c *Client) PodList(opts metav1.ListOptions) ([]v1.Pod, error) {
 		if err != nil {
 			return nil, err
 		}
-		podList = append(podList, pods.Items...)
+		for _, pod := range pods.Items {
+			podList = appendPod(podList, pod)
+		}
 	}
 
 	sort.Slice(podList, func(i, j int) bool {
@@ -25,3 +27,12 @@ func (c *Client) PodList(opts metav1.ListOptions) ([]v1.Pod, error) {
 
 	return podList, nil
 }
+
+func appendPod(pods []v1.Pod, i v1.Pod) []v1.Pod {
+	for _, pod := range pods {
+		if len(pod.OwnerReferences) > 0 && len(i.OwnerReferences) > 0 && pod.OwnerReferences[0].UID == i.OwnerReferences[0].UID {
+			return pods
+		}
+	}
+	return append(pods, i)
+}