diff --git a/test/e2e/framework/pod/node_selection.go b/test/e2e/framework/pod/node_selection.go index 9931afa6566..01d1d4c165c 100644 --- a/test/e2e/framework/pod/node_selection.go +++ b/test/e2e/framework/pod/node_selection.go @@ -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 +} diff --git a/test/e2e/storage/utils/host_exec.go b/test/e2e/storage/utils/host_exec.go index 395065b43e1..7f5077888e3 100644 --- a/test/e2e/storage/utils/host_exec.go +++ b/test/e2e/storage/utils/host_exec.go @@ -73,9 +73,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.