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 <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2023-11-02 12:12:41 +01:00 committed by mergify[bot]
parent 4d3b1fc46f
commit a9e8a32a98
3 changed files with 17 additions and 23 deletions

View File

@ -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 labels to node: %w", err)
}
}
return nil

View File

@ -275,21 +275,14 @@ var _ = Describe("RBD", func() {
}
c = f.ClientSet
if deployRBD {
err := createNodeLabel(f, nodeRegionLabel, regionValue)
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)
}
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)
if err != nil {
framework.Failf("failed to create node label: %v", err)
framework.Failf("failed to add node labels: %v", err)
}
if cephCSINamespace != defaultNs {
err = createNamespace(c, cephCSINamespace)

View File

@ -107,14 +107,12 @@ var _ = Describe("RBD Upgrade Testing", func() {
if err != nil {
framework.Failf("failed to create snapshotclass: %v", err)
}
err = createNodeLabel(f, nodeRegionLabel, regionValue)
err = addLabelsToNodes(f, map[string]string{
nodeRegionLabel: regionValue,
nodeZoneLabel: zoneValue,
})
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)
framework.Failf("failed to add node labels: %v", err)
}
})
AfterEach(func() {