Skip to content

[FG:InPlacePodVerticalScaling] Rework handling of allocated resources#128269

Merged
k8s-ci-robot merged 8 commits intokubernetes:masterfrom
tallclair:allocated
Oct 25, 2024
Merged

[FG:InPlacePodVerticalScaling] Rework handling of allocated resources#128269
k8s-ci-robot merged 8 commits intokubernetes:masterfrom
tallclair:allocated

Conversation

@tallclair
Copy link
Copy Markdown
Member

What type of PR is this?

/kind feature

What this PR does / why we need it:

Improve the consistency of handling allocated vs. requested resources.

The previous implementation stored allocated resources in the pod status, but downstream consumers were inconsistent about when the spec resources vs allocated resources were used. Furthermore, it is often unclear from Kubelet code what version the pod.Status represents, and how up-to-date it is.

This change handles the resize logic at the beginning of the pod sync loop, and overwrites the pod spec with the allocated resources as necessary. As a result, downstream consumers do not need to worry about which resources to pull from (spec vs allocated) for the most part.

Which issue(s) this PR fixes:

For #128065
Related to #116971

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

/sig node
/priority important-soon
/milestone v1.32

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. labels Oct 22, 2024
@k8s-ci-robot k8s-ci-robot added this to the v1.32 milestone Oct 22, 2024
@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. sig/node Categorizes an issue or PR as relevant to SIG Node. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 22, 2024
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

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.

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 22, 2024
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 22, 2024
@knabben
Copy link
Copy Markdown
Member

knabben commented Oct 23, 2024

Hello @tallclair
The code freeze is starting 02:00 UTC Friday November 8th 2024 (about 2 weeks from now), and while there is still time, we want to ensure that each PR has a chance to be merged on time. Just a gently reminder of the date since PR is progressing.
Thank you!

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 24, 2024
@tallclair tallclair changed the title [FG:InPlacePodVerticalScaling] WIP: Rework handling of allocated resources [FG:InPlacePodVerticalScaling] Rework handling of allocated resources Oct 24, 2024
@tallclair tallclair marked this pull request as ready for review October 24, 2024 07:27
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 24, 2024
@tallclair
Copy link
Copy Markdown
Member Author

Thanks for the review, @vinaykul !

Copy link
Copy Markdown
Contributor

@yujuhong yujuhong left a comment

Choose a reason for hiding this comment

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

Looks good overall. Have some minor questions

Comment thread pkg/kubelet/kubelet.go
Comment thread pkg/kubelet/kubelet.go
}

if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) && isPodResizeInProgress(pod, &apiPodStatus) {
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) && isPodResizeInProgress(pod, podStatus) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see. The comment definitely helped. Do we plan to augment the generic PLEG to detect changes beyond state transition, or is the plan to rely on EventedPLEG in the future?

Comment thread pkg/kubelet/eviction/helpers.go
Comment thread pkg/kubelet/kuberuntime/kuberuntime_manager_test.go
Comment thread pkg/kubelet/qos/policy.go
Comment thread pkg/kubelet/kubelet.go Outdated
op := p.DeepCopy()
kl.updateContainerResourceAllocation(op)

op, _ := kl.statusManager.UpdatePodFromAllocation(p)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Enumerating the cases where the function is called is actually very helpful. Verifying my understanding below:

  • (1) and (3). Called in HandlePodAddition -- we look at the pod and its allocated resources (if it exists) and the desired spec (if it's considered new).
  • (2). Called in canResizePod -- we look at the pod's updated desired spec

Does that sound right to you?

Comment thread pkg/kubelet/kubelet.go Outdated
return nil, err
}
} else {
// If resize isn't immediately feasible, proceed with the allocated pod.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My mental model (which might be wrong):

  1. If resizing is feasible, update the allocated resources of the pod
  2. If resizing is not feasible, the allocated resources stays the same

Either way, we'd be looking at "(updated) allocated resources" of the pod. I think the naming of the variables here might be my source of confusion....

Another question I have is that do we always set "allocated resources" even when there's no resize request? If not, doing that might help simplify some logic in the code.

Comment thread pkg/kubelet/kubelet.go
}

if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) && isPodResizeInProgress(pod, &apiPodStatus) {
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) && isPodResizeInProgress(pod, podStatus) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add some way to indicate that a container is being "watched", and should be reinspected.

yeah marking it dirty and relying on the regular relisting seems to fit the existing design better (unless we want to go with (1)).

Comment thread pkg/kubelet/kubelet.go
updatedPod.Status.Resize = resizeStatus
}
kl.podManager.UpdatePod(updatedPod)
kl.statusManager.SetPodStatus(updatedPod, updatedPod.Status)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why was this needed previously?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Allocated resources were read from the pod status. Honestly it was very confusing, and there are a lot of bugs around inconsistent use of allocated vs desired. I don't fully understand what the implications of setting these were, but I'm confident they're no longer needed.

Comment thread pkg/kubelet/kubelet.go Outdated
return nil, err
}
} else {
// If resize isn't immediately feasible, proceed with the allocated pod.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The first part of the function gets the allocated pod, but if there's no resize (no update), it just returns early with that. Is that what you mean?

My bad. That was a more general question. When kubelet sees a pod for the first time with the desired spec (and no resize request yet), do we also set the allocated resources in the status?

(BTW, this question doesn't need to block the PR)

@yujuhong
Copy link
Copy Markdown
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 25, 2024
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: 4a16f5ed9e1b45e13fc9f7c0ef9946fed80772f9

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tallclair, yujuhong

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@tooptoop4
Copy link
Copy Markdown

any ideas for #124308

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Development

Successfully merging this pull request may close these issues.

6 participants