Skip to content

Commit d71829a

Browse files
committed
e2e: avoid setting NodeName for CSI driver deployments
We don't want to set the name directly because then starting the pod can fail when the node is temporarily out of resources (kubernetes#87855). For CSI driver deployments, we have three options: - modify the pod spec with custom code, similar to how the NodeSelection utility code does it - add variants of SetNodeSelection and SetNodeAffinity which work with a pod spec instead of a pod - change their parameter from pod to pod spec and then use them also when patching a pod spec The last approach is used here because it seems more general. There might be other cases in the future where there's only a pod spec that needs to be modified.
1 parent 86141c0 commit d71829a

File tree

13 files changed

+20
-19
lines changed

13 files changed

+20
-19
lines changed

test/e2e/framework/pod/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func CreateSecPod(client clientset.Interface, namespace string, pvclaims []*v1.P
8686
// CreateSecPodWithNodeSelection creates security pod with given claims
8787
func CreateSecPodWithNodeSelection(client clientset.Interface, namespace string, pvclaims []*v1.PersistentVolumeClaim, inlineVolumeSources []*v1.VolumeSource, isPrivileged bool, command string, hostIPC bool, hostPID bool, seLinuxLabel *v1.SELinuxOptions, fsGroup *int64, node NodeSelection, timeout time.Duration) (*v1.Pod, error) {
8888
pod := MakeSecPod(namespace, pvclaims, inlineVolumeSources, isPrivileged, command, hostIPC, hostPID, seLinuxLabel, fsGroup)
89-
SetNodeSelection(pod, node)
89+
SetNodeSelection(&pod.Spec, node)
9090

9191
pod, err := client.CoreV1().Pods(namespace).Create(context.TODO(), pod, metav1.CreateOptions{})
9292
if err != nil {

test/e2e/framework/pod/node_selection.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,24 @@ func SetAntiAffinity(nodeSelection *NodeSelection, nodeName string) {
8282

8383
// SetNodeAffinity modifies the given pod object with
8484
// NodeAffinity to the given node name.
85-
func SetNodeAffinity(pod *v1.Pod, nodeName string) {
85+
func SetNodeAffinity(podSpec *v1.PodSpec, nodeName string) {
8686
nodeSelection := &NodeSelection{}
8787
SetAffinity(nodeSelection, nodeName)
88-
pod.Spec.Affinity = nodeSelection.Affinity
88+
podSpec.Affinity = nodeSelection.Affinity
8989
}
9090

9191
// SetNodeSelection modifies the given pod object with
9292
// the specified NodeSelection
93-
func SetNodeSelection(pod *v1.Pod, nodeSelection NodeSelection) {
94-
pod.Spec.NodeSelector = nodeSelection.Selector
95-
pod.Spec.Affinity = nodeSelection.Affinity
93+
func SetNodeSelection(podSpec *v1.PodSpec, nodeSelection NodeSelection) {
94+
podSpec.NodeSelector = nodeSelection.Selector
95+
podSpec.Affinity = nodeSelection.Affinity
9696
// pod.Spec.NodeName should not be set directly because
9797
// it will bypass the scheduler, potentially causing
9898
// kubelet to Fail the pod immediately if it's out of
9999
// resources. Instead, we want the pod to remain
100100
// pending in the scheduler until the node has resources
101101
// freed up.
102102
if nodeSelection.Name != "" {
103-
SetNodeAffinity(pod, nodeSelection.Name)
103+
SetNodeAffinity(podSpec, nodeSelection.Name)
104104
}
105105
}

test/e2e/framework/volume/fixtures.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ func runVolumeTesterPod(client clientset.Interface, config TestConfig, podSuffix
381381
Volumes: []v1.Volume{},
382382
},
383383
}
384-
e2epod.SetNodeSelection(clientPod, config.ClientNodeSelection)
384+
e2epod.SetNodeSelection(&clientPod.Spec, config.ClientNodeSelection)
385385

386386
for i, test := range tests {
387387
volumeName := fmt.Sprintf("%s-%s-%d", config.Prefix, "volume", i)

test/e2e/storage/csi_mock_volume.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ func startPausePodWithVolumeSource(cs clientset.Interface, volumeSource v1.Volum
689689
},
690690
},
691691
}
692-
e2epod.SetNodeSelection(pod, node)
692+
e2epod.SetNodeSelection(&pod.Spec, node)
693693
return cs.CoreV1().Pods(ns).Create(context.TODO(), pod, metav1.CreateOptions{})
694694
}
695695

test/e2e/storage/persistent_volumes-local.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ func makeLocalPodWithNodeName(config *localTestConfig, volume *localTestVolume,
989989
return
990990
}
991991

992-
e2epod.SetNodeAffinity(pod, nodeName)
992+
e2epod.SetNodeAffinity(&pod.Spec, nodeName)
993993
return
994994
}
995995

test/e2e/storage/testsuites/ephemeral.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func StartInPodWithInlineVolume(c clientset.Interface, ns, podName, command stri
301301
RestartPolicy: v1.RestartPolicyNever,
302302
},
303303
}
304-
e2epod.SetNodeSelection(pod, node)
304+
e2epod.SetNodeSelection(&pod.Spec, node)
305305

306306
for i, csiVolume := range csiVolumes {
307307
name := fmt.Sprintf("my-volume-%d", i)

test/e2e/storage/testsuites/provisioning.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ func StartInPodWithVolume(c clientset.Interface, ns, claimName, podName, command
595595
},
596596
}
597597

598-
e2epod.SetNodeSelection(pod, node)
598+
e2epod.SetNodeSelection(&pod.Spec, node)
599599
pod, err := c.CoreV1().Pods(ns).Create(context.TODO(), pod, metav1.CreateOptions{})
600600
framework.ExpectNoError(err, "Failed to create pod: %v", err)
601601
return pod

test/e2e/storage/testsuites/subpath.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ func (s *subPathTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
151151

152152
subPath := f.Namespace.Name
153153
l.pod = SubpathTestPod(f, subPath, string(volType), l.resource.VolSource, true)
154-
e2epod.SetNodeSelection(l.pod, l.config.ClientNodeSelection)
154+
e2epod.SetNodeSelection(&l.pod.Spec, l.config.ClientNodeSelection)
155155

156156
l.formatPod = volumeFormatPod(f, l.resource.VolSource)
157-
e2epod.SetNodeSelection(l.formatPod, l.config.ClientNodeSelection)
157+
e2epod.SetNodeSelection(&l.formatPod.Spec, l.config.ClientNodeSelection)
158158

159159
l.subPathDir = filepath.Join(volumePath, subPath)
160160
l.filePathInSubpath = filepath.Join(volumePath, fileName)

test/e2e/storage/testsuites/volume_io.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func makePodSpec(config volume.TestConfig, initCmd string, volsrc v1.VolumeSourc
241241
},
242242
}
243243

244-
e2epod.SetNodeSelection(pod, config.ClientNodeSelection)
244+
e2epod.SetNodeSelection(&pod.Spec, config.ClientNodeSelection)
245245
return pod
246246
}
247247

test/e2e/storage/testsuites/volumemode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (t *volumeModeTestSuite) DefineTests(driver TestDriver, pattern testpattern
215215
ginkgo.By("Creating pod")
216216
pod := e2epod.MakeSecPod(l.ns.Name, []*v1.PersistentVolumeClaim{l.Pvc}, nil, false, "", false, false, e2epv.SELinuxLabel, nil)
217217
// Setting node
218-
e2epod.SetNodeSelection(pod, l.config.ClientNodeSelection)
218+
e2epod.SetNodeSelection(&pod.Spec, l.config.ClientNodeSelection)
219219
pod, err = l.cs.CoreV1().Pods(l.ns.Name).Create(context.TODO(), pod, metav1.CreateOptions{})
220220
framework.ExpectNoError(err, "Failed to create pod")
221221
defer func() {

0 commit comments

Comments
 (0)