mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-14 06:15:45 +00:00
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.
This commit is contained in:
parent
ad18954259
commit
464edfe6f6
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user