Use NodeSelector instead of NodeName in hostexec Pod so that the Pod runs through the scheduler

Change-Id: Ia2f7ad39af318bbe707b43dfea706293ecdf5203
This commit is contained in:
Michelle Au 2020-02-05 17:43:49 -08:00
parent 845b232321
commit 1ee35e788e
2 changed files with 14 additions and 1 deletions

View File

@ -79,3 +79,11 @@ func SetAffinity(nodeSelection *NodeSelection, nodeName string) {
func SetAntiAffinity(nodeSelection *NodeSelection, nodeName string) {
setNodeAffinityRequirement(nodeSelection, v1.NodeSelectorOpNotIn, nodeName)
}
// SetNodeAffinity modifies the given pod object with
// NodeAffinity to the given node name.
func SetNodeAffinity(pod *v1.Pod, nodeName string) {
nodeSelection := &NodeSelection{}
SetAffinity(nodeSelection, nodeName)
pod.Spec.Affinity = nodeSelection.Affinity
}

View File

@ -71,9 +71,14 @@ func (h *hostExecutor) launchNodeExecPod(node string) *v1.Pod {
f := h.Framework
cs := f.ClientSet
ns := f.Namespace
hostExecPod := e2epod.NewExecPodSpec(ns.Name, "", true)
hostExecPod.GenerateName = fmt.Sprintf("hostexec-%s-", node)
hostExecPod.Spec.NodeName = node
// Use NodeAffinity instead of NodeName so that pods will not
// be immediately Failed by kubelet if it's out of space. Instead
// Pods will be pending in the scheduler until there is space freed
// up.
e2epod.SetNodeAffinity(hostExecPod, node)
hostExecPod.Spec.Volumes = []v1.Volume{
{
// Required to enter into host mount namespace via nsenter.