Skip to content

fix(daemon): resolve runtime panic by using existing container ID instead of hardcoded index#2452

Open
rakshaak29 wants to merge 3 commits into
openkruise:masterfrom
rakshaak29:fix/containermeta-getruntime-index-bug
Open

fix(daemon): resolve runtime panic by using existing container ID instead of hardcoded index#2452
rakshaak29 wants to merge 3 commits into
openkruise:masterfrom
rakshaak29:fix/containermeta-getruntime-index-bug

Conversation

@rakshaak29

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR resolves an array index and parsing bug in pkg/daemon/containermeta/container_meta_controller.go.
Previously, the getRuntimeForPod function correctly iterated over pod.Status.ContainerStatuses to find the first initialized container ID and stored it in the existingID variable. However, it subsequently ignored existingID and attempted to parse pod.Status.ContainerStatuses[0].ContainerID instead.
If the 0-th container (e.g., an initContainer) had not fully initialized and had an empty ContainerID, containerID.ParseString("") would fail and cause the entire container meta sync logic to prematurely abort for the Pod. This PR correctly replaces the hardcoded [0] index with the validated existingID variable.

Why is this PR needed?

Without this fix, kruise-daemon will fail to extract metadata for pods where the first container in the status array is uninitialized (such as long-running init containers). This breaks the sync loop and delays necessary container operations (like in-place updates) until the 0-th container finally gets a runtime ID.

How to test this PR?

  • Deploy Kruise daemon.
  • Schedule a Pod with multiple containers where the first container in the array experiences a startup delay.
  • Ensure that kruise-daemon logs do not throw a failed to parse containerID error, and that it successfully parses the runtime for subsequent containers that have valid IDs.

Does this PR introduce a breaking change?

  • Yes
  • No

Checklist

  • I have read the Contributing Guidelines.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes (N/A).
  • All new and existing tests passed.
  • My commits are signed (DCO).

Signed-off-by: rakshaak29 <rakshaak29@gmail.com>
Copilot AI review requested due to automatic review settings May 10, 2026 06:32
@kruise-bot kruise-bot requested review from Fei-Guo and furykerry May 10, 2026 06:32
@kruise-bot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign fei-guo for approval by writing /assign @fei-guo in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a runtime selection bug in the kruise-daemon container meta controller where getRuntimeForPod could parse an empty/incorrect container ID by always using pod.Status.ContainerStatuses[0] instead of the first available, non-empty ID found during iteration.

Changes:

  • Use the already-discovered existingID (first non-empty ContainerID) when parsing the container runtime type.
  • Update related error messages to reference existingID, avoiding misleading logs and preventing aborts caused by empty [0] container IDs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented May 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.06%. Comparing base (749e8f2) to head (a2d3737).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2452      +/-   ##
==========================================
+ Coverage   48.77%   49.06%   +0.28%     
==========================================
  Files         324      325       +1     
  Lines       27928    28032     +104     
==========================================
+ Hits        13623    13755     +132     
+ Misses      12775    12723      -52     
- Partials     1530     1554      +24     
Flag Coverage Δ
unittests 49.06% <100.00%> (+0.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

Signed-off-by: rakshaak29 <rakshaak29@gmail.com>
@kruise-bot kruise-bot added size/L size/L: 100-499 and removed size/XS size/XS: 0-9 labels May 10, 2026
Signed-off-by: rakshaak29 <rakshaak29@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L size/L: 100-499

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants