feat: Add actual pod resources metrics
What this PR does / why we need it:
Starting from Kubernetes 1.33, kube_pod_container_resource_requests and kube_pod_container_actual_resource_limits reflect the desired state of the container resource requests/limits.
This PR adds 2 new metric families: kube_pod_container_actual_resource_requests and kube_pod_container_actual_resource_limits that expose values from status.containerStatuses[i].resources and reflect the current actual requests and limits of each container.
How does this change affect the cardinality of KSM: The PR adds 2 new metric families with the same cardinality as very similar already existing metric families.
Which issue(s) this PR fixes Fixes #2665
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: wardady / name: Hermann Yavorskyi (0c297ac0b3d7a6c402b67521502ff047d9e2e423, 422ba2ec77e473c8dc1b198e219f5622f251fd64, 609342e17baa5668ff6b97eac9663d536a34b490)
Welcome @wardady!
It looks like this is your first PR to kubernetes/kube-state-metrics 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.
You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.
You can also check if kubernetes/kube-state-metrics has its own contribution guidelines.
You may want to refer to our testing guide if you run into trouble with your tests not passing.
If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!
Thank you, and welcome to Kubernetes. :smiley:
/triage accepted /assign @CatherineF-dev
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: wardady Once this PR has been reviewed and has the lgtm label, please ask for approval from catherinef-dev. For more information see the Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
@dgrisonnet @logicalhan I adjusted the failing test and now it passes locally. Could you please approve the CI run?
@dgrisonnet @logicalhan would appreciate any review or feedback on this PR.
When will kube_pod_container_resource_requests and kube_pod_container_actual_resource_requests have different values?
When will kube_pod_container_resource_requests and kube_pod_container_actual_resource_requests have different values?
I assume this might be the case with https://kubernetes.io/blog/2025/05/16/kubernetes-v1-33-in-place-pod-resize-beta/ ?
@mrueg, right, that is the case with in-place pod resize. @CatherineF-dev For example, when you try to apply an in-place pod resize patch, which changed requests of a container to the value above node capacity or available resources:
kubectl patch pod pod-name --subresource resize --patch '{"spec":{"containers":[{"name":"container-name", "resources":{"requests":{"memory":<above-node-capacity>}}}]}}'
In this case, the value of kube_pod_container_resource_requests will be different from kube_pod_container_actual_resource_requests (kube_pod_container_resource_requests reports an updated value in this case, even though the container resources were not patched)
Hey, just checking up if anything else is missing to get the review for this PR?
As I've opened https://github.com/kubernetes/kube-state-metrics/pull/2773 here my 2 cents:
kube_pod_container_status_resource_*would be more consistent with the other metric names for container status metrics (seekube_pod_container_status_last_terminated_exitcode, etc.)- Extract the
ResourceListhandling into a function to avoid duplicating this code for the 6th time - unless you have differences (which could be valid given resizing is only supported for CPU & Memory, but likely doesn't hurt) - Add support for init containers as sidecars can be resized too
PR needs rebase.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
@CatherineF-dev @mrueg Do you happen to have some cycles to provide some feedback?
Ping @CatherineF-dev @mrueg
Ping @CatherineF-dev @mrueg