mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Don't set NodeName directly in Pods so that it still goes through the scheduler
Change-Id: I244b6aac0289a13339f3ac228c4ad9ecf8c07b42
This commit is contained in:
parent
7faee2c30a
commit
fb9f02b5e1
@ -86,10 +86,7 @@ func CreateSecPod(client clientset.Interface, namespace string, pvclaims []*v1.P
|
||||
// CreateSecPodWithNodeSelection creates security pod with given claims
|
||||
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) {
|
||||
pod := MakeSecPod(namespace, pvclaims, inlineVolumeSources, isPrivileged, command, hostIPC, hostPID, seLinuxLabel, fsGroup)
|
||||
// Setting node
|
||||
pod.Spec.NodeName = node.Name
|
||||
pod.Spec.NodeSelector = node.Selector
|
||||
pod.Spec.Affinity = node.Affinity
|
||||
SetNodeSelection(pod, node)
|
||||
|
||||
pod, err := client.CoreV1().Pods(namespace).Create(context.TODO(), pod, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
|
@ -87,3 +87,19 @@ func SetNodeAffinity(pod *v1.Pod, nodeName string) {
|
||||
SetAffinity(nodeSelection, nodeName)
|
||||
pod.Spec.Affinity = nodeSelection.Affinity
|
||||
}
|
||||
|
||||
// SetNodeSelection modifies the given pod object with
|
||||
// the specified NodeSelection
|
||||
func SetNodeSelection(pod *v1.Pod, nodeSelection NodeSelection) {
|
||||
pod.Spec.NodeSelector = nodeSelection.Selector
|
||||
pod.Spec.Affinity = nodeSelection.Affinity
|
||||
// pod.Spec.NodeName should not be set directly because
|
||||
// it will bypass the scheduler, potentially causing
|
||||
// kubelet to Fail the pod immediately if it's out of
|
||||
// resources. Instead, we want the pod to remain
|
||||
// pending in the scheduler until the node has resources
|
||||
// freed up.
|
||||
if nodeSelection.Name != "" {
|
||||
SetNodeAffinity(pod, nodeSelection.Name)
|
||||
}
|
||||
}
|
||||
|
@ -988,7 +988,8 @@ func makeLocalPodWithNodeName(config *localTestConfig, volume *localTestVolume,
|
||||
if pod == nil {
|
||||
return
|
||||
}
|
||||
pod.Spec.NodeName = nodeName
|
||||
|
||||
e2epod.SetNodeAffinity(pod, nodeName)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -291,9 +291,6 @@ func StartInPodWithInlineVolume(c clientset.Interface, ns, podName, command stri
|
||||
},
|
||||
},
|
||||
Spec: v1.PodSpec{
|
||||
NodeName: node.Name,
|
||||
NodeSelector: node.Selector,
|
||||
Affinity: node.Affinity,
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Name: "csi-volume-tester",
|
||||
@ -304,6 +301,7 @@ func StartInPodWithInlineVolume(c clientset.Interface, ns, podName, command stri
|
||||
RestartPolicy: v1.RestartPolicyNever,
|
||||
},
|
||||
}
|
||||
e2epod.SetNodeSelection(pod, node)
|
||||
|
||||
for i, csiVolume := range csiVolumes {
|
||||
name := fmt.Sprintf("my-volume-%d", i)
|
||||
|
@ -567,9 +567,6 @@ func StartInPodWithVolume(c clientset.Interface, ns, claimName, podName, command
|
||||
},
|
||||
},
|
||||
Spec: v1.PodSpec{
|
||||
NodeName: node.Name,
|
||||
NodeSelector: node.Selector,
|
||||
Affinity: node.Affinity,
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Name: "volume-tester",
|
||||
@ -598,6 +595,7 @@ func StartInPodWithVolume(c clientset.Interface, ns, claimName, podName, command
|
||||
},
|
||||
}
|
||||
|
||||
e2epod.SetNodeSelection(pod, node)
|
||||
pod, err := c.CoreV1().Pods(ns).Create(context.TODO(), pod, metav1.CreateOptions{})
|
||||
framework.ExpectNoError(err, "Failed to create pod: %v", err)
|
||||
return pod
|
||||
|
@ -149,14 +149,17 @@ func (s *subPathTestSuite) DefineTests(driver TestDriver, pattern testpatterns.T
|
||||
framework.Failf("SubPath test doesn't support: %s", volType)
|
||||
}
|
||||
|
||||
nodeSelection := e2epod.NodeSelection{
|
||||
Name: l.config.ClientNodeName,
|
||||
Selector: l.config.ClientNodeSelector,
|
||||
}
|
||||
|
||||
subPath := f.Namespace.Name
|
||||
l.pod = SubpathTestPod(f, subPath, string(volType), l.resource.VolSource, true)
|
||||
l.pod.Spec.NodeName = l.config.ClientNodeName
|
||||
l.pod.Spec.NodeSelector = l.config.ClientNodeSelector
|
||||
e2epod.SetNodeSelection(l.pod, nodeSelection)
|
||||
|
||||
l.formatPod = volumeFormatPod(f, l.resource.VolSource)
|
||||
l.formatPod.Spec.NodeName = l.config.ClientNodeName
|
||||
l.formatPod.Spec.NodeSelector = l.config.ClientNodeSelector
|
||||
e2epod.SetNodeSelection(l.formatPod, nodeSelection)
|
||||
|
||||
l.subPathDir = filepath.Join(volumePath, subPath)
|
||||
l.filePathInSubpath = filepath.Join(volumePath, fileName)
|
||||
|
@ -183,7 +183,7 @@ func createFileSizes(maxFileSize int64) []int64 {
|
||||
func makePodSpec(config volume.TestConfig, initCmd string, volsrc v1.VolumeSource, podSecContext *v1.PodSecurityContext) *v1.Pod {
|
||||
var gracePeriod int64 = 1
|
||||
volName := fmt.Sprintf("io-volume-%s", config.Namespace)
|
||||
return &v1.Pod{
|
||||
pod := &v1.Pod{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Pod",
|
||||
APIVersion: "v1",
|
||||
@ -238,10 +238,14 @@ func makePodSpec(config volume.TestConfig, initCmd string, volsrc v1.VolumeSourc
|
||||
},
|
||||
},
|
||||
RestartPolicy: v1.RestartPolicyNever, // want pod to fail if init container fails
|
||||
NodeName: config.ClientNodeName,
|
||||
NodeSelector: config.NodeSelector,
|
||||
},
|
||||
}
|
||||
|
||||
e2epod.SetNodeSelection(pod, e2epod.NodeSelection{
|
||||
Name: config.ClientNodeName,
|
||||
Selector: config.NodeSelector,
|
||||
})
|
||||
return pod
|
||||
}
|
||||
|
||||
// Write `fsize` bytes to `fpath` in the pod, using dd and the `ddInput` file.
|
||||
|
@ -215,7 +215,7 @@ func (t *volumeModeTestSuite) DefineTests(driver TestDriver, pattern testpattern
|
||||
ginkgo.By("Creating pod")
|
||||
pod := e2epod.MakeSecPod(l.ns.Name, []*v1.PersistentVolumeClaim{l.Pvc}, nil, false, "", false, false, e2epv.SELinuxLabel, nil)
|
||||
// Setting node
|
||||
pod.Spec.NodeName = l.config.ClientNodeName
|
||||
e2epod.SetNodeSelection(pod, e2epod.NodeSelection{Name: l.config.ClientNodeName})
|
||||
pod, err = l.cs.CoreV1().Pods(l.ns.Name).Create(context.TODO(), pod, metav1.CreateOptions{})
|
||||
framework.ExpectNoError(err, "Failed to create pod")
|
||||
defer func() {
|
||||
|
@ -245,10 +245,12 @@ func testScriptInPod(
|
||||
},
|
||||
},
|
||||
RestartPolicy: v1.RestartPolicyNever,
|
||||
NodeSelector: config.ClientNodeSelector,
|
||||
NodeName: config.ClientNodeName,
|
||||
},
|
||||
}
|
||||
e2epod.SetNodeSelection(pod, e2epod.NodeSelection{
|
||||
Name: config.ClientNodeName,
|
||||
Selector: config.ClientNodeSelector,
|
||||
})
|
||||
ginkgo.By(fmt.Sprintf("Creating pod %s", pod.Name))
|
||||
f.TestContainerOutput("exec-volume-test", pod, 0, []string{fileName})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user