mirror of https://github.com/k3s-io/k3s
Merge pull request #57849 from dashpole/eviction_test_event
Automatic merge from submit-queue (batch tested with PRs 63865, 57849, 63932, 63930, 63936). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Eviction Node e2e test checks for eviction reason **What this PR does / why we need it**: Currently, the eviction test simply ensures that pods are marked `Failed`. However, this could occur because of an OOM, rather than an eviction. To ensure that pods are actually being evicted, check for the Reason in the pod status to ensure it is evicted. **Release note**: ```release-note NONE ``` cc @kubernetes/sig-node-pr-reviewspull/8/head
commit
2accf11f1a
|
@ -156,7 +156,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)
|
||||
return lifecycle.PodAdmitResult{
|
||||
Admit: false,
|
||||
Reason: reason,
|
||||
Reason: Reason,
|
||||
Message: fmt.Sprintf(message, m.nodeConditions),
|
||||
}
|
||||
}
|
||||
|
@ -608,10 +608,10 @@ func (m *managerImpl) evictPod(pod *v1.Pod, gracePeriodOverride int64, evictMsg
|
|||
status := v1.PodStatus{
|
||||
Phase: v1.PodFailed,
|
||||
Message: evictMsg,
|
||||
Reason: reason,
|
||||
Reason: Reason,
|
||||
}
|
||||
// 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.
|
||||
err := m.killPodFunc(pod, status, &gracePeriodOverride)
|
||||
if err != nil {
|
||||
|
|
|
@ -38,8 +38,8 @@ import (
|
|||
|
||||
const (
|
||||
unsupportedEvictionSignal = "unsupported eviction signal %v"
|
||||
// the reason reported back in status.
|
||||
reason = "Evicted"
|
||||
// Reason is the reason reported back in status.
|
||||
Reason = "Evicted"
|
||||
// the message associated with the reason.
|
||||
message = "The node was low on resource: %v. "
|
||||
// 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.
|
||||
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.
|
||||
|
|
|
@ -128,6 +128,7 @@ go_test(
|
|||
"//pkg/kubelet/cm/cpumanager:go_default_library",
|
||||
"//pkg/kubelet/cm/cpuset:go_default_library",
|
||||
"//pkg/kubelet/container:go_default_library",
|
||||
"//pkg/kubelet/eviction:go_default_library",
|
||||
"//pkg/kubelet/images:go_default_library",
|
||||
"//pkg/kubelet/kubeletconfig:go_default_library",
|
||||
"//pkg/kubelet/kubeletconfig/status:go_default_library",
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/features"
|
||||
"k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig"
|
||||
stats "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
|
||||
"k8s.io/kubernetes/pkg/kubelet/eviction"
|
||||
kubeletmetrics "k8s.io/kubernetes/pkg/kubelet/metrics"
|
||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
|
@ -505,6 +506,8 @@ func verifyEvictionOrdering(f *framework.Framework, testSpecs []podEvictSpec) er
|
|||
}
|
||||
}
|
||||
Expect(priorityPod).NotTo(BeNil())
|
||||
Expect(priorityPod.Status.Phase).NotTo(Equal(v1.PodSucceeded),
|
||||
fmt.Sprintf("pod: %s succeeded unexpectedly", priorityPod.Name))
|
||||
|
||||
// Check eviction ordering.
|
||||
// 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
|
||||
if priorityPodSpec.evictionPriority == 0 {
|
||||
Expect(priorityPod.Status.Phase).NotTo(Equal(v1.PodFailed),
|
||||
|
|
Loading…
Reference in New Issue