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) }