fix(inplaceupdate): preserve injected resources during resize#537
fix(inplaceupdate): preserve injected resources during resize#537silver-chard wants to merge 1 commit into
Conversation
|
[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 |
|
Welcome @silver-chard! It looks like this is your first PR to openkruise/agents 🎉 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #537 +/- ##
==========================================
+ Coverage 79.48% 79.81% +0.33%
==========================================
Files 189 202 +13
Lines 13431 14782 +1351
==========================================
+ Hits 10675 11798 +1123
- Misses 2369 2553 +184
- Partials 387 431 +44
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| resizeBody.Spec.Containers[i] = corev1.Container{ | ||
| Name: pod.Spec.Containers[i].Name, | ||
| Resources: pod.Spec.Containers[i].Resources, | ||
| Resources: *pod.Spec.Containers[i].Resources.DeepCopy(), |
There was a problem hiding this comment.
Thanks @silver-chard for bringing this up. This is indeed a problem but I'm wondering if we could use Patch at:
https://github.com/openkruise/agents/blob/master/pkg/utils/inplaceupdate/inplace_update.go#L505
to solve this at the root.
The underlying issue: SubResource("resize").Update() is a PUT, so the body must include every resource key present on the pod — including ones injected by admission webhooks (e.g., nvidia.com/gpu, ephemeral-storage) or set outside the template (e.g., resizePolicy). That's what forces the deep-copy + merge dance. A Patch would avoid all of this since unmentioned keys are preserved automatically.
There was a problem hiding this comment.
Thanks for the suggestion. Updated the resize path to use a strategic merge patch on the resize subresource instead of Update.
The resize body now only contains desired resource changes for normal containers. Injected resource keys and ephemeral-storage are no longer copied into the request body; they are preserved by patch semantics instead.
I also updated the tests to cover the subresource patch path and verify injected resources are preserved.
Tested with:
go test -count=1 ./pkg/utils/inplaceupdate
Signed-off-by: xiezhida <xie.zhida@icloud.com>
6f366d8 to
a10a15c
Compare
Ⅰ. Describe what this PR does
This PR preserves live Pod resource entries that are not managed by the Sandbox
template when generating a resize subresource body.
Previously, the resize body could omit request/limit entries that exist on the
live Pod. If an admission plugin or runtime integration injects an extra
resource, the resize request may remove that key and be rejected by the API
server.
This change:
Ⅱ. Does this pull request fix one issue?
NONE
Ⅲ. Describe how to verify it
go test -count=1 ./pkg/utils/inplaceupdateⅣ. Special notes for reviews
No API, CRD, generated client, proto, or manifest changes.