Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A library function to calculate Pod resource utilization #124537

Open
alculquicondor opened this issue Apr 25, 2024 · 13 comments
Open

A library function to calculate Pod resource utilization #124537

alculquicondor opened this issue Apr 25, 2024 · 13 comments
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@alculquicondor
Copy link
Member

What would you like to be added?

We currently have this function

func PodRequests(pod *v1.Pod, opts PodResourcesOptions) v1.ResourceList {

It is used by both kube-scheduler and kubelet to calculate resource utilization.

It would be useful to have it in a library package, such as k8s.io/component-helpers.

Why is this needed?

Multiple downstream projects need to calculate resource utilization, for quota management, billing, etc.

The resource calculation might always change, so these projects always have to catch up. The most recent change that I'm aware of is sidecar containers.

@alculquicondor alculquicondor added the kind/feature Categorizes issue or PR as related to a new feature. label Apr 25, 2024
@k8s-ci-robot k8s-ci-robot added needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 25, 2024
@alculquicondor
Copy link
Member Author

/sig scheduling

@k8s-ci-robot k8s-ci-robot added sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 25, 2024
@alculquicondor
Copy link
Member Author

cc @liggitt for any concerns

@bobbypage
Copy link
Member

bobbypage commented Apr 25, 2024

+1, I think this would be helpful to have as a generic library function to generate resource requirements for pods.

@kannon92
Copy link
Contributor

/sig node

cc @SergeyKanzhelev @gjkim42

@k8s-ci-robot k8s-ci-robot added the sig/node Categorizes an issue or PR as relevant to SIG Node. label Apr 25, 2024
@kannon92
Copy link
Contributor

I think the hard part of this would be the same as why we can't move validation into staging. Some of those fields may not belong in staging like pod validation opts.

@alculquicondor
Copy link
Member Author

This one is easier. It's based on versioned types.

@AxeZhan
Copy link
Member

AxeZhan commented Apr 26, 2024

I think the hard part of this would be the same as why we can't move validation into staging. Some of those fields may not belong in staging like pod validation opts.

+1
This function relies /pkg/api/v1/pod and PodResourcesOptions and both of them are not in staging.

I'm +1 for having this but I think maybe we need to move both /pkg/api/v1/pod and /pkg/api/v1/resource to component-helpers

@SergeyKanzhelev
Copy link
Member

We also wanted to implement this: #115643

Those are not mutually exclusive, just pointing that for many use cases reading pod status may be a better idea.

@SergeyKanzhelev
Copy link
Member

btw, this function by itself was a result of the big effort: #115367

@AxeZhan
Copy link
Member

AxeZhan commented Apr 28, 2024

I think kubectl also faces this problem:

func podRequests(pod *corev1.Pod) corev1.ResourceList {

and also in admission:
func podRequests(pod *api.Pod, opts podResourcesOptions) api.ResourceList {

We now maintain this same function in three different places, I'll try if we can merge these three function into one in pkg component-helpers.

@ffromani
Copy link
Contributor

/triage accepted

Reusing the same code in scheduler and kubelet would be highly beneficial in quite a few flows

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 29, 2024
@AxeZhan
Copy link
Member

AxeZhan commented Apr 29, 2024

/assign

@AxeZhan
Copy link
Member

AxeZhan commented Apr 29, 2024

I've created #124609 to simply move both /pkg/api/v1/pod and /pkg/api/v1/resource to component-helpers.

To fully solve this problem, we need to replace the function pointed out in #124537 (comment) with the function in component-helpers.

I tend to replace them after #124609 if we all agree the movement, to reduce the complexity of #124609.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

No branches or pull requests

7 participants