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

Move some helper functions from api/v1 to component-helpers #124609

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

AxeZhan
Copy link
Member

@AxeZhan AxeZhan commented Apr 29, 2024

What type of PR is this?

/kind cleanup
/kind feature

What this PR does / why we need it:

We currently have some functions which are used by many components,
for example:

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

It would be useful to have them in a library package.

Which issue(s) this PR fixes:

Part of #124537

Special notes for your reviewer:

First commit moves the file.
Second commit only do the rename.

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/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 29, 2024
@k8s-ci-robot
Copy link
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.

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Apr 29, 2024
@k8s-ci-robot k8s-ci-robot added area/kubelet area/test sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. sig/network Categorizes an issue or PR as relevant to SIG Network. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. sig/windows Categorizes an issue or PR as relevant to SIG Windows. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 29, 2024
@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 Apr 30, 2024
@AxeZhan AxeZhan force-pushed the refac branch 2 times, most recently from 33c6589 to b9d1030 Compare April 30, 2024 05:53

// AllFeatureEnabledContainers returns a ContainerType mask which includes all container
// types except for the ones guarded by feature gate.
func AllFeatureEnabledContainers() ContainerType {
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove this function. It's probably legacy from the time when ephemeral containers were still alpha/beta.

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Member

Choose a reason for hiding this comment

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

@SergeyKanzhelev I'm not sure who should own this.

WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

sig node is a good here. InPlace and Sidecar are both driven by SIG Node and making changes to this. But we can share with the sig scheduling.

Copy link
Member

Choose a reason for hiding this comment

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

I am thinking if this must be considered a public API and api-approvers needs to be notified for changes here

Copy link
Member

Choose a reason for hiding this comment

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

@kubernetes/api-reviewers should we add api review label for changes in these files? Or need to add it manually?

(we added the note The computation is part of the API and must be reviewed as an API change. to the function, but not sure if this is enough)

Copy link
Member

@liggitt liggitt Apr 30, 2024

Choose a reason for hiding this comment

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

Yeah, not just notified, but approval constrained to API review. We've intentionally avoided relocating API validation functions and functions used by validation out of API packages for that reason in the past before… it's too easy to accidentally tighten or loosen validation in ways that cause issues without realizing it when the functions are in packages with more broad approval.

That's not to say that relocation can't happen here (I haven't looked through it yet to know what the exposure is), we just need to make sure changes are done as carefully as needed

Copy link
Member

Choose a reason for hiding this comment

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

is there a diff of the content in the old location and new location to make sure no functionality is changing in the move for pkg/api/v1/resource/helpers.go and pkg/api/v1/resource/helpers_test.go?

Copy link
Member Author

@AxeZhan AxeZhan May 9, 2024

Choose a reason for hiding this comment

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

here're the diff links:
helpers.go
helpers_test.go

Also, I split the commits by file. But git diff seems not very useful :(

Copy link
Member Author

Choose a reason for hiding this comment

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

@liggitt Can you review again? Diff files seem fine.
But notice that I move ContainerType from pkg/api/pod/util.go to component-helpers/resource/helpers.go too. Becuase PodRequests function uses ContainerType, and import pkg v1 in staging is not allowed.

@cici37
Copy link
Contributor

cici37 commented Apr 30, 2024

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Apr 30, 2024
@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label May 1, 2024
pkg/kubelet/container/helpers.go Outdated Show resolved Hide resolved
}

for _, container := range pod.Spec.Containers {
containerReqs := container.Resources.Requests
Copy link
Member

Choose a reason for hiding this comment

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

Question for @liggitt: would it be fine to also incorporate the logic of "requests = limits, when not defined".

func SetDefaults_Pod(obj *v1.Pod) {

Copy link
Member

Choose a reason for hiding this comment

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

two thoughts:

  1. don't mix relocation and modification into the same PR
  2. why would we need to duplicate API defaulting logic here? admission / controllers / clients reading from the API will already see pods with the defaults applied

Copy link
Member

Choose a reason for hiding this comment

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

  1. I agree.
  2. Because users of this helper might be using a Pod template that didn't pass through the apiserver yet. For example, when using an external CRD such as a kubeflow TFJob.

Copy link
Member

Choose a reason for hiding this comment

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

but... the input to this function is Pod, not PodTemplate

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but one can easily convert one to the other in order to get a resource calculation.

@cici37
Copy link
Contributor

cici37 commented May 2, 2024

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label May 2, 2024
@haircommander haircommander moved this from Triage to Archive-it in SIG Node CI/Test Board May 8, 2024
Copy link
Member

Choose a reason for hiding this comment

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

is there a diff of the content in the old location and new location to make sure no functionality is changing in the move for pkg/api/v1/resource/helpers.go and pkg/api/v1/resource/helpers_test.go?

pkg/api/pod/util.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label May 9, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: AxeZhan
Once this PR has been reviewed and has the lgtm label, please assign deads2k, kerthcet, msau42, sjenning for approval. For more information see the Kubernetes Code Review Process.

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

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

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented May 9, 2024

@AxeZhan: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-e2e-autoscaling-hpa-cpu 1ef33db link false /test pull-kubernetes-e2e-autoscaling-hpa-cpu

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@fedebongio
Copy link
Contributor

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubelet area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. sig/network Categorizes an issue or PR as relevant to SIG Network. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. sig/windows Categorizes an issue or PR as relevant to SIG Windows. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
Status: Needs Triage
Status: Needs Triage
Status: not-only-sig-node
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

8 participants