Skip to content

Commit

Permalink
Fix OOMKilled check and update OOMKilled log (#531)
Browse files Browse the repository at this point in the history
* Fix OOMKilled check and update OOMKilled log

* Change log fields
  • Loading branch information
JacobValdemar authored Mar 14, 2024
1 parent df08094 commit 61392b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/daemon/kubernetes/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (p *PodInformer) handle(e interface{}) {
}

if isPodOOMKilled(pod) {
log.Infof("Pod: %s was OOMKilled owned by squad %s", pod.Name, getCodeOwnerSquad(pod.Labels))
log.With("targetPodNamespace", pod.Namespace, "targetPodName", pod.Name, "targetPodSquad", getCodeOwnerSquad(pod.Labels)).Infof("Pod: %s was OOMKilled owned by squad %s", pod.Name, getCodeOwnerSquad(pod.Labels))
var errorContainers []http.ContainerError
for _, cst := range pod.Status.ContainerStatuses {
if isContainerOOMKilled(cst) {
Expand Down Expand Up @@ -187,7 +187,7 @@ func isPodOOMKilled(pod *corev1.Pod) bool {
}

func isContainerOOMKilled(containerStatus corev1.ContainerStatus) bool {
if containerStatus.State.Terminated != nil && containerStatus.State.Terminated.Reason == "OOMKilled" {
if containerStatus.LastTerminationState.Terminated != nil && containerStatus.LastTerminationState.Terminated.Reason == "OOMKilled" {
return true
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/daemon/kubernetes/pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestIsPodOOMKilled(t *testing.T) {
Status: corev1.PodStatus{
ContainerStatuses: []corev1.ContainerStatus{
{
State: corev1.ContainerState{
LastTerminationState: corev1.ContainerState{
Terminated: &corev1.ContainerStateTerminated{},
},
},
Expand All @@ -204,7 +204,7 @@ func TestIsPodOOMKilled(t *testing.T) {
Phase: corev1.PodRunning,
ContainerStatuses: []corev1.ContainerStatus{
{
State: corev1.ContainerState{
LastTerminationState: corev1.ContainerState{
Terminated: &corev1.ContainerStateTerminated{
Reason: "OOMKilled",
},
Expand Down

0 comments on commit 61392b0

Please sign in to comment.