Skip to content

fix: Fill container statuses panic#1488

Open
dbudziwojskiNR wants to merge 4 commits into
mainfrom
fix-fillContainerStatuses-panic
Open

fix: Fill container statuses panic#1488
dbudziwojskiNR wants to merge 4 commits into
mainfrom
fix-fillContainerStatuses-panic

Conversation

@dbudziwojskiNR

Copy link
Copy Markdown
Contributor

Description

Internal recreation of PR #1412

We have a pod restarting with panic logs:

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/newrelic/nri-kubernetes/v3/src/kubelet/metric.fillContainerStatuses(0xc0000e6738, 0xc0000e6590)
/home/runner/work/nri-kubernetes/nri-kubernetes/src/kubelet/metric/pods.go:249 +0x103d
github.com/newrelic/nri-kubernetes/v3/src/kubelet/metric.(*PodsFetcher).fetchContainersData(0x13aa020?, 0xc0000e6738)
/home/runner/work/nri-kubernetes/nri-kubernetes/src/kubelet/metric/pods.go:181 +0xb7
github.com/newrelic/nri-kubernetes/v3/src/kubelet/metric.(*PodsFetcher).fillGaps(0xc0001369a0, 0xc0017e6660, {{{0xc001369558, 0x7}, {0xc001369570, 0x2}}, {{0x0, 0x0}, {0x0, 0x0}, ...}, ...})
/home/runner/work/nri-kubernetes/nri-kubernetes/src/kubelet/metric/pods.go:102 +0x4e5
github.com/newrelic/nri-kubernetes/v3/src/kubelet/metric.(*PodsFetcher).DoPodsFetch(0xc0001369a0)
/home/runner/work/nri-kubernetes/nri-kubernetes/src/kubelet/metric/pods.go:78 +0x4ca
github.com/newrelic/nri-kubernetes/v3/src/kubelet/grouper.(*grouper).Group(0xc00015c320, 0xc001a819e0?)
/home/runner/work/nri-kubernetes/nri-kubernetes/src/kubelet/grouper/group.go:71 +0x1c7
github.com/newrelic/nri-kubernetes/v3/src/scrape.(*Job).Populate(0xc000565d00, 0xc000136580, {0xc00005207b, 0x6}, 0x1fb4040, 0xc00001c750)
/home/runner/work/nri-kubernetes/nri-kubernetes/src/scrape/scrape_job.go:56 +0x5f
github.com/newrelic/nri-kubernetes/v3/src/kubelet.(*Scraper).Run(0xc00023b7c0, 0xc000136580)
/home/runner/work/nri-kubernetes/nri-kubernetes/src/kubelet/scraper.go:111 +0x44e
main.runScrapers(0xc00038ef08, 0x0?, 0xc00023b7c0, 0x0, 0xc000136580)
/home/runner/work/nri-kubernetes/nri-kubernetes/cmd/nri-kubernetes/main.go:228 +0xb6
main.main.func1()
/home/runner/work/nri-kubernetes/nri-kubernetes/cmd/nri-kubernetes/main.go:175 +0x39
main.measureTime(0xc001221ed0)
/home/runner/work/nri-kubernetes/nri-kubernetes/cmd/nri-kubernetes/main.go:215 +0x31
main.main()
/home/runner/work/nri-kubernetes/nri-kubernetes/cmd/nri-kubernetes/main.go:174 +0xf16

  • The panic is caused by indexing pod.Status.InitContainerStatuses by idx when that slice can be shorter than pod.Spec.InitContainers.

  • Put a for check to make sure the initContainerName is matching the status container name.

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • New feature / enhancement (non-breaking change which adds functionality)
  • Security fix
  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • Add changelog entry following the contributing guide
  • Documentation has been updated
  • This change requires changes in testing:
    • unit tests
    • E2E tests

@dbudziwojskiNR dbudziwojskiNR requested a review from a team as a code owner June 23, 2026 23:51
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.89%. Comparing base (e19d9dd) to head (1ca47dc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1488      +/-   ##
==========================================
+ Coverage   76.87%   76.89%   +0.01%     
==========================================
  Files          53       53              
  Lines        3784     3787       +3     
==========================================
+ Hits         2909     2912       +3     
  Misses        708      708              
  Partials      167      167              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants