From 1ee35e788e2510911b9775e959365c0cfab29f92 Mon Sep 17 00:00:00 2001 From: Michelle Au Date: Wed, 5 Feb 2020 17:43:49 -0800 Subject: [PATCH] Use NodeSelector instead of NodeName in hostexec Pod so that the Pod runs through the scheduler Change-Id: Ia2f7ad39af318bbe707b43dfea706293ecdf5203 --- test/e2e/framework/pod/node_selection.go | 8 ++++++++ test/e2e/storage/utils/host_exec.go | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) 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 906be96be7c..0a14cf8c9df 100644 --- a/test/e2e/storage/utils/host_exec.go +++ b/test/e2e/storage/utils/host_exec.go @@ -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.