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

Create HPA v2 Stable API #102534

Merged
merged 2 commits into from Nov 9, 2021
Merged

Conversation

wangyysde
Copy link
Member

@wangyysde wangyysde commented Jun 2, 2021

Signed-off-by: wangyysde net_use@bzhy.com

What type of PR is this?

/kind feature
/kind design

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #102362

Special notes for your reviewer:

I found that "list_type_missing,k8s.io/api/autoscaling/v2beta2" listed in the api/api-rules/violation_exceptions.list. So I generated code by run build/run.sh make UPDATE_API_KNOWN_VIOLATIONS=true.

Does this PR introduce a user-facing change?

Create HPA v2 from v2beta2 with some fields changed. 

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

- [KEP]: https://github.com/kubernetes/enhancements/tree/master/keps/sig-autoscaling/2702-graduate-hpa-api-to-GA

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. kind/design Categorizes issue or PR as related to design. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 2, 2021
@k8s-ci-robot k8s-ci-robot added area/apiserver kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 2, 2021
@fejta-bot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@wangyysde
Copy link
Member Author

/label api-review

@k8s-ci-robot k8s-ci-robot added the api-review Categorizes an issue or PR as actively needing an API review. label Jun 3, 2021
@fedebongio
Copy link
Contributor

/sig autoscaling

@k8s-ci-robot k8s-ci-robot added the sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. label Jun 3, 2021
@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 Jun 3, 2021
@josephburnett
Copy link
Member

/assign

Copy link
Contributor

@elmiko elmiko left a comment

Choose a reason for hiding this comment

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

this generally makes sense to me, but as i am newer to this code base i have a question.

pkg/apis/autoscaling/v2/conversion.go Show resolved Hide resolved
Copy link
Member

@josephburnett josephburnett left a comment

Choose a reason for hiding this comment

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

This is great! Thanks.

One request: can you please split this into two commits.

  1. just the API types (types.go) so we can review the API itself
  2. the rest of the conversion and registration mechanics

I think our API reviewer will only want to see the first commit.

pkg/apis/autoscaling/v2/conversion.go Outdated Show resolved Hide resolved
pkg/apis/autoscaling/v2/defaults.go Outdated Show resolved Hide resolved
staging/src/k8s.io/api/autoscaling/v2/types.go Outdated Show resolved Hide resolved
@wangyysde
Copy link
Member Author

@josephburnett Thanks! I will split this into two commits and modify the files following your reviews.

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jun 9, 2021
@josephburnett
Copy link
Member

I'm unable to get a v2 HPA object when I set this up with kubetest --build --up.

josephburnett@josephburnett:~/go/src/k8s.io/kubernetes$ kubectl get hpa.v2beta2.autoscaling
Warning: autoscaling/v2beta2 HorizontalPodAutoscaler is deprecated in v1.22+, unavailable in v1.25+
NAME         REFERENCE               TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
php-apache   Deployment/php-apache   <unknown>/50%   1         10        1          35s
josephburnett@josephburnett:~/go/src/k8s.io/kubernetes$ kubectl get hpa.v2.autoscaling
error: the server doesn't have a resource type "hpa"

@josephburnett
Copy link
Member

PR to fix the build rule violation list: https://github.com/wangyysde/kubernetes/pull/1

However I would prefer we fix the violation in the new API so this isn't necessary.

@wangyysde
Copy link
Member Author

/test pull-kubernetes-unit

@wangyysde
Copy link
Member Author

/label api-review

@wangyysde
Copy link
Member Author

rebase on latest master and rerun, and you'll get a diff

@liggitt @josephburnett @fedebongio Thanks. The all tests have passed after I rebased on master. Coult you review this PR?

@liggitt liggitt moved this from Changes requested to In progress in API Reviews Nov 9, 2021
@liggitt liggitt added this to the v1.23 milestone Nov 9, 2021
@josephburnett
Copy link
Member

/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 Nov 9, 2021
@liggitt
Copy link
Member

liggitt commented Nov 9, 2021

/approve

for API changes

/hold are the follow-up PRs switching the controller to use v2, and adding e2e CRUD coverage of the v2 API ready?

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 9, 2021
@liggitt liggitt moved this from In progress to API review completed, 1.23 in API Reviews Nov 9, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: josephburnett, liggitt, wangyysde

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

The pull request process is described 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 k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 9, 2021
@josephburnett
Copy link
Member

are the follow-up PRs switching the controller to use v2, and adding e2e CRUD coverage of the v2 API ready?

I sent the PR switching the controller to use v2 to @wangyysde directly (https://github.com/wangyysde/kubernetes/pull/2) which he merged into this PR. So this one has the horizontal.go changes to use the v2 API.

Regarding CRUD coverage, we already have E2E tests in horizontal_pod_autoscaling.go that exercise the v1 and v2beta2 APIs (see CreateCPUHorizontalPodAutoscaler and CreateContainerResourceCPUHorizontalPodAutoscaler respectively). And custom_metrics_stackdriver_autoscaling.go also covers v2beta2. So I would like to just change those tests to use the new v2 stable API. I can prepare the PR.

@liggitt
Copy link
Member

liggitt commented Nov 9, 2021

I sent the PR switching the controller to use v2 to @wangyysde directly (wangyysde#2) which he merged into this PR. So this one has the horizontal.go changes to use the v2 API.

It looks like the controller is still making v1 API requests, then internally converting to v2. I'd expect the controller to start using the v2 API directly and stop doing v1 <-> v2 conversions. That's fine to do in a follow-up PR.

@liggitt
Copy link
Member

liggitt commented Nov 9, 2021

/hold cancel

will look for the follow-up PR to switch the controller API calls to v2 and switch the e2e tests from v2beta2 to v2

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 9, 2021
@josephburnett
Copy link
Member

controller to start using the v2 API directly and stop doing v1 <-> v2 conversions

Why do we want to do this?

The data is stored on disk in v1 format so we would have to carefully migrate it. That would be costly. We aren't planning to deprecate the v1 API since it's GA and the v1 <--> v2 conversion is lossless.

We will deprecate the v2beta1 and v2beta2 APIs so we have to stop using those of course.

@josephburnett
Copy link
Member

switch the e2e tests from v2beta2 to v2

I'm working on this one right now and running the tests. So I should have this out in the next day or so.

@liggitt
Copy link
Member

liggitt commented Nov 9, 2021

controller to start using the v2 API directly and stop doing v1 <-> v2 conversions

Why do we want to do this?

Only kube-apiserver should be doing API conversions.

The data is stored on disk in v1 format so we would have to carefully migrate it. That would be costly.

Switching kube-controller-manager to use the v2 API is ~free, because kube-apiserver is already maintaining a cache of HPA objects in v2 format for the watch cache, so the v1<->v2 conversions will be done regardless of whether the controller uses v2 or not.

(separately, in 1.24, the storage version should switch to v2, which is more expressive and avoids needing to constantly do annotation serialization/deserialization in conversion like v1 does)

@josephburnett
Copy link
Member

Switching kube-controller-manager to use the v2 API is ~free

Got it. So I'll send a PR to remove the conversion too.

in 1.24, the storage version should switch to v2

And I'll prepare this follow PR too after 1.23 code freeze lifts.

Thanks!

@sftim
Copy link
Contributor

sftim commented Dec 8, 2021

Did we ever document which fields?

The release note says:

Create HPA v2 from v2beta2 with some fields changed. 

but I can't find confirmation of which those were.

@liggitt
Copy link
Member

liggitt commented Dec 8, 2021

no serialized fields changed, the name of a couple constants in the go files changed... the release note should have said "Promoted HPA v2beta2 to v2 with no schema changes."

@sftim
Copy link
Contributor

sftim commented Dec 8, 2021

Thanks @liggitt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver area/code-generation area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API 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-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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/testing Categorizes an issue or PR as relevant to SIG Testing. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: API review completed, 1.23
Development

Successfully merging this pull request may close these issues.

Create HPA v2 Stable API