From 3fa898bbc64e20f6a9999a747db47d6957920db1 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Mon, 2 Sep 2024 09:25:59 -0400 Subject: [PATCH] Incorporate feedback from review Signed-off-by: Davanum Srinivas --- test/e2e/framework/util.go | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 37d48fafd79..cc2e77518ba 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -40,7 +40,6 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/sets" @@ -130,7 +129,7 @@ const ( // SnapshotDeleteTimeout is how long for snapshot to delete snapshotContent. SnapshotDeleteTimeout = 5 * time.Minute - // ControlPlaneLabel is valid for kubeadm based clusters like kops ONLY + // ControlPlaneLabel is valid label for kubeadm based clusters like kops ONLY ControlPlaneLabel = "node-role.kubernetes.io/control-plane" ) @@ -711,11 +710,29 @@ func getControlPlaneAddresses(ctx context.Context, c clientset.Interface) ([]str // GetControlPlaneNodes returns a list of control plane nodes func GetControlPlaneNodes(ctx context.Context, c clientset.Interface) *v1.NodeList { - selector := labels.Set{ControlPlaneLabel: ""}.AsSelector() - cpNodes, err := c.CoreV1().Nodes(). - List(ctx, metav1.ListOptions{LabelSelector: selector.String()}) - ExpectNoError(err, "error reading control-plane nodes") - return cpNodes + allNodes, err := c.CoreV1().Nodes().List(ctx, metav1.ListOptions{}) + ExpectNoError(err, "error reading all nodes") + + var cpNodes v1.NodeList + + for _, node := range allNodes.Items { + // Check for the control plane label + if _, hasLabel := node.Labels[ControlPlaneLabel]; hasLabel { + cpNodes.Items = append(cpNodes.Items, node) + continue + } + + // Check for the specific taint + for _, taint := range node.Spec.Taints { + // NOTE the taint key is the same as the control plane label + if taint.Key == ControlPlaneLabel && taint.Effect == v1.TaintEffectNoSchedule { + cpNodes.Items = append(cpNodes.Items, node) + continue + } + } + } + + return &cpNodes } // GetControlPlaneAddresses returns all IP addresses on which the kubelet can reach the control plane.