From c1c8760a3dfd38fb0fb6d76194f0d220c9714f9a Mon Sep 17 00:00:00 2001 From: Annie Li Date: Fri, 6 Mar 2026 13:43:18 -0800 Subject: [PATCH] pod without status --- pkg/cluster/pod.go | 8 +++++++- pkg/cluster/pod_test.go | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/cluster/pod.go b/pkg/cluster/pod.go index c99c1c322..6658ba414 100644 --- a/pkg/cluster/pod.go +++ b/pkg/cluster/pod.go @@ -376,9 +376,15 @@ func (c *Cluster) getPatroniMemberData(pod *v1.Pod) (patroni.MemberData, error) return memberData, nil } -// podIsNotRunning returns true if a pod is not in a healthy running state, +// podIsNotRunning returns true if a pod is known to be in a non-running state, // e.g. stuck in CreateContainerConfigError, CrashLoopBackOff, ImagePullBackOff, etc. +// Pods with no status information are not considered non-running, as they may +// simply not have reported status yet. func podIsNotRunning(pod *v1.Pod) bool { + if pod.Status.Phase == "" { + // No status reported yet — don't treat as non-running + return false + } if pod.Status.Phase != v1.PodRunning { return true } diff --git a/pkg/cluster/pod_test.go b/pkg/cluster/pod_test.go index 18bfbc863..6ab3f9207 100644 --- a/pkg/cluster/pod_test.go +++ b/pkg/cluster/pod_test.go @@ -120,6 +120,13 @@ func TestPodIsNotRunning(t *testing.T) { pod v1.Pod expected bool }{ + { + subtest: "pod with no status reported yet", + pod: v1.Pod{ + Status: v1.PodStatus{}, + }, + expected: false, + }, { subtest: "pod running with all containers ready", pod: v1.Pod{ @@ -382,6 +389,18 @@ func TestAllPodsRunning(t *testing.T) { pods: []v1.Pod{}, expected: true, }, + { + subtest: "pods with no status reported yet", + pods: []v1.Pod{ + { + Status: v1.PodStatus{}, + }, + { + Status: v1.PodStatus{}, + }, + }, + expected: true, + }, } for _, tt := range tests {