You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(pod): show NoReady instead of Running when a completed pod is not ready - #4312
When some of a pod's containers have completed and another is still running and ready, Pod.Phase (the STATUS column) always turns Completed into Running, even if the pod's Ready condition is false. Example: a still-running container whose readiness depends on a container that has exited.
kubectl only reports Running in this case when the pod is ready, and NotReady otherwise:
k9s's own PodStatus helper already does this, using PhaseNotReady. Pod.Phase didn't, so the two code paths disagreed.
Fix
Pod.Phase now checks the pod's Ready condition before turning Completed into Running, and returns PhaseNotReady otherwise, the same as PodStatus.
Tests
Two new TestCheckPhase cases: one container running and ready, one completed, with and without the Ready condition. The not-ready case returned Running before the fix and returns NoReady now. go test ./internal/render/... ./internal/view/... ./internal/dao/... passes.
AI-assisted: I directed the investigation and reviewed and verified the change myself.
@kevin9327Phase is also used by podIsRunning to gate shell and attach. With this change a pod with one completed and one running container shows NoReady, so s and a would be refused. Before it showed Running and worked.
We need to check this before merging. Can you test shell on such a pod?
@uozalp You're right, thanks for catching that. With only the render change, podIsRunning would have refused s/a on a pod with one completed and one running container whenever the pod was not ready.
I don't have a live cluster on this machine to try shell end to end, so I fixed it in code and added a unit test instead (4c6521a):
podIsRunning now calls a small isPodRunning(*v1.Pod) helper that accepts Running and NoReady. NoReady only comes out of Phase on the completed+running path, so it still means "at least one container is running", and shell/attach behave as before.
TestIsPodRunning in internal/view/pod_int_test.go covers running, completed+running ready, completed+running not ready, pending and succeeded. The not-ready case fails without the helper change.
go test ./internal/view/ ./internal/render/ passes. If you'd rather keep the gate on the raw pod phase, or leave Phase alone and only change the rendered status, I can switch to that.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When some of a pod's containers have completed and another is still running and ready,
Pod.Phase(the STATUS column) always turnsCompletedintoRunning, even if the pod'sReadycondition is false. Example: a still-running container whose readiness depends on a container that has exited.kubectl only reports
Runningin this case when the pod is ready, andNotReadyotherwise:k9s's own
PodStatushelper already does this, usingPhaseNotReady.Pod.Phasedidn't, so the two code paths disagreed.Fix
Pod.Phasenow checks the pod'sReadycondition before turningCompletedintoRunning, and returnsPhaseNotReadyotherwise, the same asPodStatus.Tests
Two new
TestCheckPhasecases: one container running and ready, one completed, with and without theReadycondition. The not-ready case returnedRunningbefore the fix and returnsNoReadynow.go test ./internal/render/... ./internal/view/... ./internal/dao/...passes.AI-assisted: I directed the investigation and reviewed and verified the change myself.