From 60fb8f2fbc5acf06d89574bac5f47d04e19db701 Mon Sep 17 00:00:00 2001 From: Aldo Culquicondor Date: Wed, 28 Jun 2023 09:34:16 -0400 Subject: [PATCH] Exclude terminal pods from Daemonset e2e tests Change-Id: Ic29ca1739ebdc54822d1751fcd56a99c628021c4 --- test/e2e/apps/daemon_set.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/e2e/apps/daemon_set.go b/test/e2e/apps/daemon_set.go index d55e991277a..460b882fe18 100644 --- a/test/e2e/apps/daemon_set.go +++ b/test/e2e/apps/daemon_set.go @@ -39,6 +39,7 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/selection" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/sets" @@ -74,6 +75,16 @@ const ( // node selectors labels to namespaces var NamespaceNodeSelectors = []string{"scheduler.alpha.kubernetes.io/node-selector"} +var nonTerminalPhaseSelector = func() labels.Selector { + var reqs []labels.Requirement + for _, phase := range []v1.PodPhase{v1.PodFailed, v1.PodSucceeded} { + req, _ := labels.NewRequirement("status.phase", selection.NotEquals, []string{string(phase)}) + reqs = append(reqs, *req) + } + selector := labels.NewSelector() + return selector.Add(reqs...) +}() + type updateDSFunc func(*appsv1.DaemonSet) // updateDaemonSetWithRetries updates daemonsets with the given applyUpdate func @@ -1025,7 +1036,10 @@ func newDaemonSetWithLabel(dsName, image string, label map[string]string) *appsv func listDaemonPods(ctx context.Context, c clientset.Interface, ns string, label map[string]string) *v1.PodList { selector := labels.Set(label).AsSelector() - options := metav1.ListOptions{LabelSelector: selector.String()} + options := metav1.ListOptions{ + LabelSelector: selector.String(), + FieldSelector: nonTerminalPhaseSelector.String(), + } podList, err := c.CoreV1().Pods(ns).List(ctx, options) framework.ExpectNoError(err) gomega.Expect(podList.Items).ToNot(gomega.BeEmpty())