Avoid duplicated notifications with Kubernetes DaemonSet (#252)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2021-01-04 23:35:27 +01:00
committed by GitHub
parent dc1216c221
commit cd65887ad0

View File

@@ -16,7 +16,9 @@ func (c *Client) PodList(opts metav1.ListOptions) ([]v1.Pod, error) {
if err != nil { if err != nil {
return nil, err 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 { 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 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)
}