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

Volume resource requirements #118653

Merged
merged 2 commits into from Aug 21, 2023

Conversation

pohly
Copy link
Contributor

@pohly pohly commented Jun 14, 2023

What type of PR is this?

/kind cleanup
/kind api-change
/sig storage

What this PR does / why we need it:

PVC and containers shared the same ResourceRequirements struct to define their
API. When resource claims were added, that struct got extended, which
accidentally also changed the PVC API. To avoid such a mistake from happening
again, PVC now uses its own VolumeResourceRequirements struct.

Which issue(s) this PR fixes:

Fixes #115845

Special notes for your reviewer:

The struct has to have a Claims field because someone might have added it to
some YAML file for use with Kubernetes 1.28 even though it didn't do
anything. Removing the field in Kubernetes 1.29 would cause OpenAPI-based
validation in kubectl to reject such a YAML file.

Does this PR introduce a user-facing change?

Go API: the ResourceRequirements struct needs to be replaced with VolumeResourceRequirements for use with volumes.

@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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/storage Categorizes an issue or PR as relevant to SIG Storage. 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/code-generation area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework 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/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Jun 14, 2023
@k8s-triage-robot
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.

@pohly pohly force-pushed the volume-resource-requirements branch from 7f58541 to 150bbe9 Compare June 14, 2023 10:04
// field. It got added by accident, has no meaning here and gets ignored
// silently.
// +optional
Claims []ResourceClaim
Copy link
Member

Choose a reason for hiding this comment

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

Mark it as deprecated? And throw a warning when user set it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mark as deprecated how? A free-form comment?

Do Go linters recognize // Deprecated: for fields? That's worth checking.

For the warning, that would be a server-side warning, right? I know those exist, but don't know how they are implemented. Do you have a pointer for me?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do Go linters recognize // Deprecated: for fields?

No, staticcheck only detects usage of deprecated structs. It still makes sense to use the Deprecated comment because it makes the intent clearer.

For the warning, that would be a server-side warning, right?

https://kubernetes.io/blog/2020/09/03/warnings/#future-possibilities mentions "warnings about fields" as a future extension. I've asked on #sig-api-machinery whether it is possible today.

Copy link
Member

Choose a reason for hiding this comment

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

@pohly a server-side warning example

// WarningsOnCreate returns warnings for the creation of the given object.
func (persistentvolumeStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
return pvutil.GetWarningsForPersistentVolume(obj.(*api.PersistentVolume))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was already wired up for PersistentVolumeClaimSpec, so all I had to do was add a new if check there - done.

Copy link
Member

Choose a reason for hiding this comment

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

I actually think we should drop the field (with an appropriate tombstone comment recording the json field name and protobuf tag used)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Drop the field" as in "not have it in the struct at all" (except for the comments)?

So breaking client-side validation (= YAML file has it, kubectl complains about unknown field) would be acceptable?

If we can do that, then let's remove the field. It would be cleaner. I just didn't dare... 😅

Copy link
Member

Choose a reason for hiding this comment

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

it was added in 1.27 documented as alpha, right? I'd drop the field in 1.28 and backport a change to 1.27 to clear the field on write from PVCs as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clearing on write was already implemented in 1.27: #115928.

Sounds like dropping the field is acceptable. I'll change this PR accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

New version pushed which no longer has the field, only a comment about it in core/v1/types.go.

@SergeyKanzhelev SergeyKanzhelev moved this from Triage to Archive-it in SIG Node CI/Test Board Jun 14, 2023
@pohly pohly force-pushed the volume-resource-requirements branch from 150bbe9 to 016db7f Compare June 15, 2023 10:45
@jiahuif
Copy link
Member

jiahuif commented Jun 15, 2023

/label api-review
/assign @SataQiu
Thank you!
/triage accepted

@k8s-ci-robot k8s-ci-robot added the triage/accepted Indicates an issue or PR is ready to be actively worked on. label Jun 15, 2023
@pohly pohly force-pushed the volume-resource-requirements branch from 8517761 to fd79a15 Compare August 18, 2023 07:03
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 18, 2023
@liggitt
Copy link
Member

liggitt commented Aug 21, 2023

needs rebase/regen now that the 1.28.0 API fixtures have been captured and 1.26.0 fixtures dropped

@pohly
Copy link
Contributor Author

pohly commented Aug 21, 2023

I had already rebased? Should be okay right now.

PVC and containers shared the same ResourceRequirements struct to define their
API. When resource claims were added, that struct got extended, which
accidentally also changed the PVC API. To avoid such a mistake from happening
again, PVC now uses its own VolumeResourceRequirements struct.

The `Claims` field gets removed because risk of breaking someone is low:
theoretically, YAML files which have a claims field for volumes now
get rejected when validating against the OpenAPI. Such files
have never made sense and should be fixed.

Code that uses the struct definitions needs to be updated.
@pohly pohly force-pushed the volume-resource-requirements branch from fd79a15 to b8b9e53 Compare August 21, 2023 13:32
@pohly
Copy link
Contributor Author

pohly commented Aug 21, 2023

Ah, I see - there was no merge conflict anymore, but staging/src/k8s.io/api/testdata had to be refreshed nonetheless to cover 1.28.0 - done.

@pohly pohly force-pushed the volume-resource-requirements branch from b8b9e53 to f20fc24 Compare August 21, 2023 13:34
@@ -0,0 +1,77 @@
apiVersion: v1
Copy link
Member

Choose a reason for hiding this comment

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

drop all the v1.26.0 files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@pohly pohly force-pushed the volume-resource-requirements branch from f20fc24 to c1eb18c Compare August 21, 2023 15:08
@liggitt
Copy link
Member

liggitt commented Aug 21, 2023

/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 Aug 21, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: b7eda65dfb9fbd07d1c874788a80f6578f0dfd83

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, pohly

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

@pohly
Copy link
Contributor Author

pohly commented Aug 21, 2023

/retest

@k8s-ci-robot k8s-ci-robot merged commit f852d7f into kubernetes:master Aug 21, 2023
17 checks passed
SIG Node PR Triage automation moved this from Needs Reviewer to Done Aug 21, 2023
@k8s-ci-robot k8s-ci-robot modified the milestones: next-candidate, v1.29 Aug 21, 2023
jrvaldes added a commit to jrvaldes/windows-machine-config-operator that referenced this pull request Jan 4, 2024
ResourceRequirements struct was replaced with VolumeResourceRequirements for
use with volumes. kubernetes/kubernetes#118653
jrvaldes added a commit to jrvaldes/windows-machine-config-operator that referenced this pull request Jan 17, 2024
ResourceRequirements struct was replaced with VolumeResourceRequirements for
use with volumes. kubernetes/kubernetes#118653
@@ -486,7 +486,7 @@ type PersistentVolumeClaimSpec struct {
// status field of the claim.
// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#resources
// +optional
Resources ResourceRequirements `json:"resources,omitempty" protobuf:"bytes,2,opt,name=resources"`
Resources VolumeResourceRequirements `json:"resources,omitempty" protobuf:"bytes,2,opt,name=resources"`
Copy link
Member

Choose a reason for hiding this comment

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

this is a breaking change for consumers of the Go struct.
while we care more to not break the serializable API, the change should have had an action-required in the release note.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we have documentation on when to use "action-required"? Would it have helped you in this case?

I keep hearing all kinds of opinions about whether Go API changes need to be mentioned at all. I added a release note, but not the "action required" because I assumed that this is reserved for changes that otherwise might silently break users on upgrades. This PR is breaking compilation in an obvious way, so developers will notice that they need to take some action.

Copy link
Member

Choose a reason for hiding this comment

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

I think a release note is sufficient. People who happen to be using this alpha field in their go structs (who I expect will be vanishingly small) will know they need to take action when they update and their code needs a change before it will compile.

I think action required should be reserved for changes which will surprise or break people if they don't read the release notes, or which they can prepare their cluster or workloads for in advance. This is not such a change.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, the label is documented as "Denotes a PR that introduces potentially breaking changes that require user action.".
as far as my interpretation goes, it should be added to breaking changes of any kind that require user action.

i was pinged downstream about this, not on a urgent note, and while a go build will catch the problem of the go struct that did not change for 7 years, similar would apply to a client trying to reach a REST API that changed, the user can find right away.

might be worthwhile for us to document some of these aspects in API docs.

Copy link
Member

@liggitt liggitt Feb 7, 2024

Choose a reason for hiding this comment

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

it should be added to breaking changes of any kind that require user action

If we expand that section of the release notes to include every signature change of every go function in a staging library, that section of the release notes will be so noisy it will be useless. I think it should be reserved for things which require configuration or API changes, would cause problems if they were missed, and could be missed in a cluster upgrade. This is not a change like that.

Upgrading a cluster to the release that included this change does not require people to update their client-go libraries, so I really don't think action is required here.

while a go build will catch the problem of the go struct that did not change for 7 years

to be fair, this was a brand new alpha field, not one that had existed for years, so I sincerely doubt anyone was using it in a way that would require action on a cluster upgrade

edit: my mistake, I mixed this up with a different fixup to a recent alpha field. This field was not alpha.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As much as I'd like to believe that the impact was low, unfortunately that's not the case here: this is a change in PersistentVolumeClaimSpec, which is a GA API. I can understand that consumers of our Go API are upset because this causes them work, but I still think it was the right thing to do because accidentally changing the Kubernetes API by sharing the same struct is worse.

Copy link
Member

Choose a reason for hiding this comment

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

on my end it was more of a short discussion in the lines of - "is it OK to change the Go structs of a GA API like that?". i responded that for k8s and some other REST APIs projects out there it's not considered an issue. EOD, it depends on what rules a project has.

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/code-generation area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework area/kubelet 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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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/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. 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.28
Archived in project
Archived in project
Archived in project
Development

Successfully merging this pull request may close these issues.

API: ResourceRequirements usage in Container and PVC
10 participants