From 91f80072264b5b71bcefb7afa86b5b241ba72597 Mon Sep 17 00:00:00 2001 From: "catalin.apetrei" Date: Tue, 19 Mar 2024 09:34:44 +0200 Subject: [PATCH] check also for initcontianers in ShouldReap --- CHANGELOG.md | 3 +++ rules/container_status.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aed398..00c9b9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # pod-reaper: kills pods dead +### 2.13.0 +- the reaper checks now also the initContainerStatus + ### 2.7.0 - add `DRY_RUN` mode diff --git a/rules/container_status.go b/rules/container_status.go index 57fc7e0..64f7e7e 100644 --- a/rules/container_status.go +++ b/rules/container_status.go @@ -35,6 +35,16 @@ func (rule *containerStatus) ShouldReap(pod v1.Pod) (bool, string) { return true, fmt.Sprintf("has container status %s", reapStatus) } } + + // Check init containers + for _, initContainerStatus := range pod.Status.InitContainerStatuses { + state := initContainerStatus.State + // Check both waiting and terminated conditions for init containers + if (state.Waiting != nil && state.Waiting.Reason == reapStatus) || + (state.Terminated != nil && state.Terminated.Reason == reapStatus) { + return true, fmt.Sprintf("has init container status %s", reapStatus) + } + } } return false, "" }