Exclude terminal pods from Daemonset e2e tests

Change-Id: Ic29ca1739ebdc54822d1751fcd56a99c628021c4
This commit is contained in:
Aldo Culquicondor 2023-06-28 09:34:16 -04:00
parent b3d94ae74f
commit 60fb8f2fbc
No known key found for this signature in database
GPG Key ID: C005626B875BD5E6

View File

@ -39,6 +39,7 @@ import (
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
@ -74,6 +75,16 @@ const (
// node selectors labels to namespaces // node selectors labels to namespaces
var NamespaceNodeSelectors = []string{"scheduler.alpha.kubernetes.io/node-selector"} 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) type updateDSFunc func(*appsv1.DaemonSet)
// updateDaemonSetWithRetries updates daemonsets with the given applyUpdate func // 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 { func listDaemonPods(ctx context.Context, c clientset.Interface, ns string, label map[string]string) *v1.PodList {
selector := labels.Set(label).AsSelector() 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) podList, err := c.CoreV1().Pods(ns).List(ctx, options)
framework.ExpectNoError(err) framework.ExpectNoError(err)
gomega.Expect(podList.Items).ToNot(gomega.BeEmpty()) gomega.Expect(podList.Items).ToNot(gomega.BeEmpty())