From 1709464f339c4c787ec8b6df51c1dda08b4ee778 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Thu, 2 Nov 2023 12:12:41 +0100 Subject: [PATCH] e2e: add multiple labels to node update the e2e code to add multiple labels to the node at a time. fixes: #4146 Signed-off-by: Madhu Rajanna --- e2e/node.go | 7 +++++-- e2e/rbd.go | 19 ++++++------------- e2e/upgrade-rbd.go | 10 ++++------ 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/e2e/node.go b/e2e/node.go index 180eaa59632b..7a1cf074dba1 100644 --- a/e2e/node.go +++ b/e2e/node.go @@ -26,9 +26,10 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/kubernetes/test/e2e/framework" e2enode "k8s.io/kubernetes/test/e2e/framework/node" + testutils "k8s.io/kubernetes/test/utils" ) -func createNodeLabel(f *framework.Framework, labelKey, labelValue string) error { +func addLabelsToNodes(f *framework.Framework, labels map[string]string) error { // NOTE: This makes all nodes (in a multi-node setup) in the test take // the same label values, which is fine for the test nodes, err := f.ClientSet.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{}) @@ -36,7 +37,9 @@ func createNodeLabel(f *framework.Framework, labelKey, labelValue string) error return fmt.Errorf("failed to list node: %w", err) } for i := range nodes.Items { - e2enode.AddOrUpdateLabelOnNode(f.ClientSet, nodes.Items[i].Name, labelKey, labelValue) + if err := testutils.AddLabelsToNode(f.ClientSet, nodes.Items[i].Name, labels); err != nil { + return fmt.Errorf("failed to add label to node: %w", err) + } } return nil diff --git a/e2e/rbd.go b/e2e/rbd.go index 2da732bd1487..ed5899389708 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -275,19 +275,12 @@ var _ = Describe("RBD", func() { } c = f.ClientSet if deployRBD { - err := createNodeLabel(f, nodeRegionLabel, regionValue) - if err != nil { - framework.Failf("failed to create node label: %v", err) - } - err = createNodeLabel(f, nodeZoneLabel, zoneValue) - if err != nil { - framework.Failf("failed to create node label: %v", err) - } - err = createNodeLabel(f, crushLocationRegionLabel, crushLocationRegionValue) - if err != nil { - framework.Failf("failed to create node label: %v", err) - } - err = createNodeLabel(f, crushLocationZoneLabel, crushLocationZoneValue) + err := addLabelsToNodes(f, map[string]string{ + nodeRegionLabel: regionValue, + nodeZoneLabel: zoneValue, + crushLocationRegionLabel: crushLocationRegionValue, + crushLocationZoneLabel: crushLocationZoneValue, + }) if err != nil { framework.Failf("failed to create node label: %v", err) } diff --git a/e2e/upgrade-rbd.go b/e2e/upgrade-rbd.go index 0ed21e5441f4..21cdf841e6bd 100644 --- a/e2e/upgrade-rbd.go +++ b/e2e/upgrade-rbd.go @@ -107,12 +107,10 @@ var _ = Describe("RBD Upgrade Testing", func() { if err != nil { framework.Failf("failed to create snapshotclass: %v", err) } - - err = createNodeLabel(f, nodeRegionLabel, regionValue) - if err != nil { - framework.Failf("failed to create node label: %v", err) - } - err = createNodeLabel(f, nodeZoneLabel, zoneValue) + err = addLabelsToNodes(f, map[string]string{ + nodeRegionLabel: regionValue, + nodeZoneLabel: zoneValue, + }) if err != nil { framework.Failf("failed to create node label: %v", err) }