internal/render: prevent index out of range panic in initContainerStats#3870
Open
umut-polat wants to merge 1 commit intoderailed:masterfrom
Open
internal/render: prevent index out of range panic in initContainerStats#3870umut-polat wants to merge 1 commit intoderailed:masterfrom
umut-polat wants to merge 1 commit intoderailed:masterfrom
Conversation
initContainerStats iterates over InitContainerStatuses and accesses InitContainers at the same index. When the status list is longer than the container list (e.g. during pod initialization), this causes an index out of range panic. Add a bounds check to break early when the status index exceeds the container list length. Fixes derailed#3866
derailed
requested changes
Mar 6, 2026
| @@ -427,6 +427,9 @@ func (*Pod) ContainerStats(cc []v1.ContainerStatus) (readyCnt, terminatedCnt, re | |||
|
|
|||
| func (*Pod) initContainerStats(cc []v1.Container, cos []v1.ContainerStatus) (ready, total, restart int) { | |||
| for i := range cos { | |||
Owner
There was a problem hiding this comment.
I think best to match container names here and 'continue' not break if containerStatus is not present.
Also we should include some tests to make sure we handle this correctly.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
During pod initialization,
InitContainerStatusescan have more entries thanInitContainers(or they may temporarily be out of sync).initContainerStatsiterates over the status slice and directly indexes into the container slice at the same position, causing:Added a bounds check to break early when the status index exceeds the container list length.
Fixes #3866