From 464edfe6f6efbfb894503ca783b975c8647d01ce Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 25 Jan 2023 18:06:44 +0100 Subject: [PATCH] test/integration: create nodes directly with kubernetes.io/hostname label By generating the unique name in advance, the label also can be set to a matching value directly in the Create request. This makes test startup in test/integration/scheduler_perf a bit faster because the extra patching can be avoided. It also leads to a better label because previously, the unique label value didn't match the node name. This is required for simulating dynamic resource allocation, which relies on the label to track where an allocated claim is available. --- test/integration/framework/perf_utils.go | 16 +++++++++++++++- .../config/performance-config.yaml | 16 ---------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/test/integration/framework/perf_utils.go b/test/integration/framework/perf_utils.go index 21585a5204e..bb1d2704b82 100644 --- a/test/integration/framework/perf_utils.go +++ b/test/integration/framework/perf_utils.go @@ -22,6 +22,7 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/rand" clientset "k8s.io/client-go/kubernetes" "k8s.io/klog/v2" testutils "k8s.io/kubernetes/test/utils" @@ -89,7 +90,20 @@ func (p *IntegrationTestNodePreparer) PrepareNodes(ctx context.Context, nextNode for i := 0; i < numNodes; i++ { var err error for retry := 0; retry < retries; retry++ { - _, err = p.client.CoreV1().Nodes().Create(ctx, baseNode, metav1.CreateOptions{}) + // Create nodes with the usual kubernetes.io/hostname label. + // For that we need to know the name in advance, if we want to + // do it in one request. + node := baseNode.DeepCopy() + name := node.Name + if name == "" { + name = node.GenerateName + rand.String(5) + node.Name = name + } + if node.Labels == nil { + node.Labels = make(map[string]string) + } + node.Labels["kubernetes.io/hostname"] = name + _, err = p.client.CoreV1().Nodes().Create(ctx, node, metav1.CreateOptions{}) if err == nil { break } diff --git a/test/integration/scheduler_perf/config/performance-config.yaml b/test/integration/scheduler_perf/config/performance-config.yaml index 84aa647c437..a4fe2ecf4d8 100644 --- a/test/integration/scheduler_perf/config/performance-config.yaml +++ b/test/integration/scheduler_perf/config/performance-config.yaml @@ -25,8 +25,6 @@ workloadTemplate: - opcode: createNodes countParam: $initNodes - uniqueNodeLabelStrategy: - labelKey: kubernetes.io/hostname - opcode: createNamespaces prefix: sched count: 2 @@ -198,8 +196,6 @@ workloadTemplate: - opcode: createNodes countParam: $initNodes - uniqueNodeLabelStrategy: - labelKey: kubernetes.io/hostname - opcode: createNamespaces prefix: sched count: 2 @@ -227,8 +223,6 @@ workloadTemplate: - opcode: createNodes countParam: $initNodes - uniqueNodeLabelStrategy: - labelKey: kubernetes.io/hostname - opcode: createNamespaces prefix: sched count: 2 @@ -491,8 +485,6 @@ workloadTemplate: - opcode: createNodes countParam: $initNodes - uniqueNodeLabelStrategy: - labelKey: kubernetes.io/hostname - opcode: createNamespaces prefix: init-ns countParam: $initNamespaces @@ -524,8 +516,6 @@ workloadTemplate: - opcode: createNodes countParam: $initNodes - uniqueNodeLabelStrategy: - labelKey: kubernetes.io/hostname - opcode: createNamespaces prefix: init-ns countParam: $initNamespaces @@ -591,8 +581,6 @@ workloadTemplate: - opcode: createNodes countParam: $initNodes - uniqueNodeLabelStrategy: - labelKey: kubernetes.io/hostname - opcode: createNamespaces prefix: init-ns countParam: $initNamespaces @@ -626,13 +614,9 @@ workloadTemplate: - opcode: createNodes countParam: $normalNodes - uniqueNodeLabelStrategy: - labelKey: kubernetes.io/hostname - opcode: createNodes nodeTemplatePath: config/node-with-taint.yaml countParam: $taintNodes - uniqueNodeLabelStrategy: - labelKey: kubernetes.io/hostname - opcode: createPods countParam: $measurePods collectMetrics: true