pod without status

This commit is contained in:
Annie Li 2026-03-06 13:43:18 -08:00
parent 27196f40f8
commit c1c8760a3d
No known key found for this signature in database
GPG Key ID: 03ABEE8E6189E333
2 changed files with 26 additions and 1 deletions

View File

@ -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
}

View File

@ -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 {