fix(daemon): resolve runtime panic by using existing container ID instead of hardcoded index#2452
Conversation
Signed-off-by: rakshaak29 <rakshaak29@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
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-emptyContainerID) 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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: rakshaak29 <rakshaak29@gmail.com>
Signed-off-by: rakshaak29 <rakshaak29@gmail.com>
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
getRuntimeForPodfunction correctly iterated overpod.Status.ContainerStatusesto find the first initialized container ID and stored it in theexistingIDvariable. However, it subsequently ignoredexistingIDand attempted to parsepod.Status.ContainerStatuses[0].ContainerIDinstead.If the 0-th container (e.g., an
initContainer) had not fully initialized and had an emptyContainerID,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 validatedexistingIDvariable.Why is this PR needed?
Without this fix,
kruise-daemonwill 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?
kruise-daemonlogs do not throw afailed to parse containerIDerror, and that it successfully parses the runtime for subsequent containers that have valid IDs.Does this PR introduce a breaking change?
Checklist