Skip to content

Conversation

krikera
Copy link

@krikera krikera commented Jul 20, 2025

Motivation

This PR implements the resize subresource for Kubernetes Pods as requested in issue #1793. The resize subresource is a new feature introduced in Kubernetes 1.33 that allows users to modify resource requirements (CPU and memory limits/requests) for containers in running pods without having to restart the pod.

Solution

This implementation adds complete support for the resize subresource following existing patterns in the kube-rs codebase:

Core Changes

  • kube-core/src/subresource.rs: Added Request::resize() method that constructs PATCH requests to the /resize endpoint, following the same pattern as other subresources like evict() and scale()
  • kube-client/src/api/subresource.rs: Added Resize marker trait and Api::resize() method with proper version gating using k8s_if_ge_1_33! macro
  • Test coverage: Included resize_path test to verify correct URL construction
  • Example: Added examples/pod_resize.rs demonstrating practical usage with resource limit modifications

Usage

let pods: Api<Pod> = Api::namespaced(client, "default");
let mut pod = pods.get("my-pod").await?;

// Modify resource requirements
// ... update pod.spec.containers[0].resources ...

let pp = PostParams::default();
let updated_pod = pods.resize("my-pod", &pp, &pod).await?;

Implement the resize subresource for Kubernetes Pods as specified in GitHub issue kube-rs#1793.

The resize subresource allows changing resource requirements (CPU/memory limits and requests)
for containers in running pods, available in Kubernetes 1.33+.

Changes:
- Add Request::resize method in kube-core for PATCH requests to /resize endpoint
- Add Resize marker trait and Api::resize method in kube-client with k8s_if_ge_1_33 version gating
- Include test for resize URL construction
- Add pod_resize example demonstrating usage with resource limit modifications

Closes kube-rs#1793

Signed-off-by: Krishna Ketan Rai <[email protected]>
Copy link

codecov bot commented Jul 20, 2025

Codecov Report

Attention: Patch coverage is 57.89474% with 8 lines in your changes missing coverage. Please review.

Project coverage is 75.1%. Comparing base (6590ea9) to head (8b0fccd).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
kube-client/src/api/subresource.rs 20.0% 8 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1794     +/-   ##
=======================================
- Coverage   75.2%   75.1%   -0.0%     
=======================================
  Files         84      84             
  Lines       7791    7809     +18     
=======================================
+ Hits        5853    5859      +6     
- Misses      1938    1950     +12     
Files with missing lines Coverage Δ
kube-core/src/subresource.rs 83.6% <100.0%> (+1.0%) ⬆️
kube-client/src/api/subresource.rs 49.7% <20.0%> (-2.0%) ⬇️

... and 4 files with indirect coverage changes

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

Implements the resize subresource for Kubernetes Pods following the same
patterns as other subresources in kube-rs.

Changes:
- Add Request::resize method in kube-core for PATCH requests to /resize
- Add Resize trait and Api::resize method in kube-client (gated on k8s_if_ge_1_33)
- Add resize URL construction test
- Add pod_resize example demonstrating usage

The resize subresource allows updating pod resource requests/limits
and is available in Kubernetes 1.33+.

Fixes kube-rs#1793

Signed-off-by: Krishna Ketan Rai <[email protected]>
@clux
Copy link
Member

clux commented Jul 21, 2025

hey, thanks for this. Very quick response to this issue :-)

travelling today, but should be able to review later

@clux clux linked an issue Jul 21, 2025 that may be closed by this pull request
@clux clux added the changelog-add changelog added category for prs label Jul 21, 2025
Copy link
Member

@clux clux left a comment

Choose a reason for hiding this comment

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

thanks for this. example is sensible, and the method you have for one of the verbs seems sensible. it's missing the 2 other verbs which should be a similar job. you can look at how scale or ephemeral_containers is set up for multiple verbs.

left some minor comments, but documentation and general pattern is nice.

let pods: Api<Pod> = Api::default_namespaced(client);

// Resize is only available in Kubernetes 1.33+
k8s_openapi::k8s_if_ge_1_33! {
Copy link
Member

Choose a reason for hiding this comment

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

we don't need to gate the example on 1_33 because the we have latest as a required feature

Comment on lines +645 to +646
/// This works similarly to [`Api::replace`] but uses the resize subresource.
/// Takes a full Pod object to specify the new resource requirements.
Copy link
Member

Choose a reason for hiding this comment

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

Should link to limitations

/// # Ok(())
/// # }
/// ```
pub async fn resize(&self, name: &str, pp: &PostParams, data: &K) -> Result<K>
Copy link
Member

Choose a reason for hiding this comment

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

misses support for the other verbs get/patch. need to rename this to replace_resize to make room for patch_resize and get_resize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-add changelog added category for prs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add resize subresource on Pod
2 participants