Skip to content

fix(inplaceupdate): preserve injected resources during resize#537

Open
silver-chard wants to merge 1 commit into
openkruise:masterfrom
silver-chard:fix/preserve-injected-resources-on-resize
Open

fix(inplaceupdate): preserve injected resources during resize#537
silver-chard wants to merge 1 commit into
openkruise:masterfrom
silver-chard:fix/preserve-injected-resources-on-resize

Conversation

@silver-chard

Copy link
Copy Markdown

Ⅰ. 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:

  • builds resize resources from a deep copy of the live Pod resources;
  • merges desired template resources into the live resources;
  • preserves injected request/limit entries;
  • adds regression coverage for injected resources.

Ⅱ. 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.

@kruise-bot kruise-bot requested review from furykerry and zmberg June 13, 2026 13:39
@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 furykerry for approval by writing /assign @furykerry 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

@kruise-bot

Copy link
Copy Markdown

Welcome @silver-chard! It looks like this is your first PR to openkruise/agents 🎉

@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.81%. Comparing base (0e58df8) to head (a10a15c).
⚠️ Report is 22 commits behind head on master.

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     
Flag Coverage Δ
unittests 79.81% <100.00%> (+0.33%) ⬆️

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

☔ 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.

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(),

@PersistentJZH PersistentJZH Jun 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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>
@silver-chard silver-chard force-pushed the fix/preserve-injected-resources-on-resize branch from 6f366d8 to a10a15c Compare June 25, 2026 14:35
@kruise-bot kruise-bot added size/L and removed size/M labels Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants