eviction test ensures failed pods are evicted

This commit is contained in:
David Ashpole 2018-05-07 15:01:20 -07:00
parent 51d75a7b1e
commit a5df208866
4 changed files with 15 additions and 6 deletions

View File

@ -143,7 +143,7 @@ func (m *managerImpl) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAd
glog.Warningf("Failed to admit pod %s - node has conditions: %v", format.Pod(attrs.Pod), m.nodeConditions) glog.Warningf("Failed to admit pod %s - node has conditions: %v", format.Pod(attrs.Pod), m.nodeConditions)
return lifecycle.PodAdmitResult{ return lifecycle.PodAdmitResult{
Admit: false, Admit: false,
Reason: reason, Reason: Reason,
Message: fmt.Sprintf(message, m.nodeConditions), Message: fmt.Sprintf(message, m.nodeConditions),
} }
} }
@ -569,10 +569,10 @@ func (m *managerImpl) evictPod(pod *v1.Pod, gracePeriodOverride int64, evictMsg
status := v1.PodStatus{ status := v1.PodStatus{
Phase: v1.PodFailed, Phase: v1.PodFailed,
Message: evictMsg, Message: evictMsg,
Reason: reason, Reason: Reason,
} }
// record that we are evicting the pod // record that we are evicting the pod
m.recorder.Eventf(pod, v1.EventTypeWarning, reason, evictMsg) m.recorder.Eventf(pod, v1.EventTypeWarning, Reason, evictMsg)
// this is a blocking call and should only return when the pod and its containers are killed. // this is a blocking call and should only return when the pod and its containers are killed.
err := m.killPodFunc(pod, status, &gracePeriodOverride) err := m.killPodFunc(pod, status, &gracePeriodOverride)
if err != nil { if err != nil {

View File

@ -38,8 +38,8 @@ import (
const ( const (
unsupportedEvictionSignal = "unsupported eviction signal %v" unsupportedEvictionSignal = "unsupported eviction signal %v"
// the reason reported back in status. // Reason is the reason reported back in status.
reason = "Evicted" Reason = "Evicted"
// the message associated with the reason. // the message associated with the reason.
message = "The node was low on resource: %v. " message = "The node was low on resource: %v. "
// additional information for containers exceeding requests // additional information for containers exceeding requests
@ -1028,7 +1028,7 @@ func buildSignalToRankFunc(withImageFs bool) map[evictionapi.Signal]rankFunc {
// PodIsEvicted returns true if the reported pod status is due to an eviction. // PodIsEvicted returns true if the reported pod status is due to an eviction.
func PodIsEvicted(podStatus v1.PodStatus) bool { func PodIsEvicted(podStatus v1.PodStatus) bool {
return podStatus.Phase == v1.PodFailed && podStatus.Reason == reason return podStatus.Phase == v1.PodFailed && podStatus.Reason == Reason
} }
// buildSignalToNodeReclaimFuncs returns reclaim functions associated with resources. // buildSignalToNodeReclaimFuncs returns reclaim functions associated with resources.

View File

@ -128,6 +128,7 @@ go_test(
"//pkg/kubelet/cm/cpumanager:go_default_library", "//pkg/kubelet/cm/cpumanager:go_default_library",
"//pkg/kubelet/cm/cpuset:go_default_library", "//pkg/kubelet/cm/cpuset:go_default_library",
"//pkg/kubelet/container:go_default_library", "//pkg/kubelet/container:go_default_library",
"//pkg/kubelet/eviction:go_default_library",
"//pkg/kubelet/images:go_default_library", "//pkg/kubelet/images:go_default_library",
"//pkg/kubelet/kubeletconfig:go_default_library", "//pkg/kubelet/kubeletconfig:go_default_library",
"//pkg/kubelet/kubeletconfig/status:go_default_library", "//pkg/kubelet/kubeletconfig/status:go_default_library",

View File

@ -29,6 +29,7 @@ import (
"k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig" "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig"
stats "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1" stats "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
"k8s.io/kubernetes/pkg/kubelet/eviction"
kubeletmetrics "k8s.io/kubernetes/pkg/kubelet/metrics" kubeletmetrics "k8s.io/kubernetes/pkg/kubelet/metrics"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types" kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
@ -505,6 +506,8 @@ func verifyEvictionOrdering(f *framework.Framework, testSpecs []podEvictSpec) er
} }
} }
Expect(priorityPod).NotTo(BeNil()) Expect(priorityPod).NotTo(BeNil())
Expect(priorityPod.Status.Phase).NotTo(Equal(v1.PodSucceeded),
fmt.Sprintf("pod: %s succeeded unexpectedly", priorityPod.Name))
// Check eviction ordering. // Check eviction ordering.
// Note: it is alright for a priority 1 and priority 2 pod (for example) to fail in the same round, // Note: it is alright for a priority 1 and priority 2 pod (for example) to fail in the same round,
@ -524,6 +527,11 @@ func verifyEvictionOrdering(f *framework.Framework, testSpecs []podEvictSpec) er
} }
} }
if priorityPod.Status.Phase == v1.PodFailed {
Expect(priorityPod.Status.Reason, eviction.Reason, "pod %s failed; expected Status.Reason to be %s, but got %s",
priorityPod.Name, eviction.Reason, priorityPod.Status.Reason)
}
// EvictionPriority 0 pods should not fail // EvictionPriority 0 pods should not fail
if priorityPodSpec.evictionPriority == 0 { if priorityPodSpec.evictionPriority == 0 {
Expect(priorityPod.Status.Phase).NotTo(Equal(v1.PodFailed), Expect(priorityPod.Status.Phase).NotTo(Equal(v1.PodFailed),