diff --git a/pkg/checkup/pods.go b/pkg/checkup/pods.go index 63a7441..802f248 100644 --- a/pkg/checkup/pods.go +++ b/pkg/checkup/pods.go @@ -64,7 +64,7 @@ func CheckPods(resources *v1.PodList) (results symptoms.SymptomList) { } } - if scs.RestartCount != 0 { + if scs.RestartCount > 0 && scs.LastTerminationState.Terminated != nil { if time.Since(scs.LastTerminationState.Terminated.FinishedAt.Time).Hours() > 1 { results.Add(symptoms.Symptom{ Message: fmt.Sprintf("container '%s' has been restarted %d times", scs.Name, scs.RestartCount), diff --git a/pkg/checkup/pods_test.go b/pkg/checkup/pods_test.go index 70e3240..cad50db 100644 --- a/pkg/checkup/pods_test.go +++ b/pkg/checkup/pods_test.go @@ -224,6 +224,45 @@ func TestCheckPodsWithRestarts(t *testing.T) { assert.Equal(t, "critical", result.Symptoms[0].Severity) } +func TestCheckPodsWithRestartsAndRunning(t *testing.T) { + dummyResources := v1.PodList{ + Items: []v1.Pod{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "test", + OwnerReferences: []metav1.OwnerReference{ + { + Kind: "Deployment", + }, + }, + }, + Status: v1.PodStatus{ + StartTime: createNewTimeStampPtr(time.Now()), + Phase: "Running", + Conditions: []v1.PodCondition{}, + ContainerStatuses: []v1.ContainerStatus{ + { + Ready: true, + Name: "c1", + RestartCount: 1, + State: v1.ContainerState{ + Terminated: &v1.ContainerStateTerminated{ + ExitCode: 0, + Reason: "Completed", + }, + }, + }, + }, + }, + }, + }, + } + + result := CheckPods(&dummyResources) + + assert.Len(t, result.Symptoms, 0) +} + func TestCheckPodsNoOwner(t *testing.T) { dummyResources := v1.PodList{ Items: []v1.Pod{