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

🌱 Enable optionalorrequired linter #11909

Merged

Conversation

sivchari
Copy link
Member

What this PR does / why we need it:

Part of #11834

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

/area api

@k8s-ci-robot k8s-ci-robot added area/api Issues or PRs related to the APIs cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 27, 2025
@JoelSpeed JoelSpeed mentioned this pull request Feb 27, 2025
16 tasks
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 28, 2025
@sivchari sivchari force-pushed the enable-optionalorrequired branch from b85a8d2 to d26f462 Compare February 28, 2025 02:24
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Feb 28, 2025
@sivchari sivchari force-pushed the enable-optionalorrequired branch from d26f462 to 7e640c3 Compare March 10, 2025 03:46
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 10, 2025
@sivchari sivchari force-pushed the enable-optionalorrequired branch 3 times, most recently from 7931667 to df77f96 Compare March 10, 2025 04:30
@sivchari
Copy link
Member Author

Hi @sbueringer
I'm ready for review, thanks :)

Copy link
Contributor

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

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

Reviewing the additions of markers, everything here looks in order as far as I can tell. Just one nit about making sure we have the order of the enabled linters correct, and then good to go, thanks @sivchari

metav1.ListMeta `json:"metadata,omitempty"`
// items is the list of Clusters.
// +optional
Items []Cluster `json:"items"`
Copy link
Member

Choose a reason for hiding this comment

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

Why are we making this optional? Shouldn't this be required? (see also the delta in zz_generated.openapi.go)

(cc @JoelSpeed)

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly, thanks.

Copy link
Member

Choose a reason for hiding this comment

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

What do you mean with exactly? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Edited comments were not reflected.
required is correct here, ideally zz_generated_api.go should not be changed!

Copy link
Contributor

Choose a reason for hiding this comment

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

In general, the List version of a resource doesn't matter too much, it doesn't effect the generated CRD or behaviour of the cluster, but does affect the openapi as you've seen.

I'm intending to check with API machinery folks about their expectations here, whether this should be optional or required and from there will set up the linters to ensure consistency.

Copy link
Member

@sbueringer sbueringer Mar 11, 2025

Choose a reason for hiding this comment

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

If getting that feedback from apimachinery takes too long I would suggest to drop all the markers for the Items field for now. Then we can get at least everything else done for the code freeze

(I don't want to block everything else on this PR just for a marker that don't have any impact anywhere (not in CRDs and the generated OpenAPI code is as far as I know only used to generate some specs for Runtime Extensions that don't even use lists)

Copy link
Member

@sbueringer sbueringer Mar 11, 2025

Choose a reason for hiding this comment

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

Thinking a bit about it. @sivchari Can we directly remove the markers from the Items fields on this PR, add an exclude and follow-up? I have multiple other PRs with potential merge conflicts that I have to coordinate with this PR

(adding the Items markers later is trivial)

Copy link
Member Author

Choose a reason for hiding this comment

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

@sbueringer
Make sense to me, thanks.
I fixed them.

Copy link
Member

Choose a reason for hiding this comment

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

Thx!

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 10, 2025
@sivchari sivchari force-pushed the enable-optionalorrequired branch from df77f96 to f8c8a78 Compare March 11, 2025 09:54
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 11, 2025
@sivchari sivchari force-pushed the enable-optionalorrequired branch 2 times, most recently from bc94f70 to 5a1745d Compare March 11, 2025 10:00
@sivchari
Copy link
Member Author

sivchari commented Mar 11, 2025

Deletion line is 1.
It means we enable this linter and there are no breaking changes. 👍
It seems to be good.

@sivchari sivchari force-pushed the enable-optionalorrequired branch from 5a1745d to 08fe0ad Compare March 11, 2025 15:48
Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

@sivchari Thx! Last round of nits. Sorry these non-CRD API types are a bit strange and there's a lot of nuance

Basically optional/required has no impact on them as they are not used for CRDs, but I still don't want to declare fields as required that are actually optional (adding omitempty to a bunch of these won't change their behavior at runtime)

But I think even though these are not used in CRDs it's good to explicitly declare if the fields are optional or required.

@sivchari sivchari force-pushed the enable-optionalorrequired branch from 08fe0ad to 0fe20eb Compare March 11, 2025 17:00
@sivchari
Copy link
Member Author

I fixed all them that you commented!

@sivchari sivchari force-pushed the enable-optionalorrequired branch 2 times, most recently from 7db7cda to 91c760d Compare March 11, 2025 17:03
@sbueringer
Copy link
Member

Seems like the exclude doesn't cover the Provider CRD + we need regen (the diff there is fine)

@sivchari sivchari force-pushed the enable-optionalorrequired branch from 91c760d to ac2d1c7 Compare March 11, 2025 17:15
@sivchari
Copy link
Member Author

sivchari commented Mar 11, 2025

I edited exclude ranges and did re-gen 👍

@sivchari sivchari force-pushed the enable-optionalorrequired branch from ac2d1c7 to c2e43bb Compare March 11, 2025 17:17
@sbueringer
Copy link
Member

Thank you!

Really appreciate the work on this. I know it was a lot of work :)

/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 Mar 11, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: f9db9a4d11dae5fdba7fe62d3023cef0fb9ea98a

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbueringer

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 Mar 11, 2025
@k8s-ci-robot k8s-ci-robot merged commit a093b06 into kubernetes-sigs:main Mar 11, 2025
18 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.10 milestone Mar 11, 2025
@sbueringer
Copy link
Member

I added a sub-task on #11834 to track the Items work. Feel free to continue with that one :)

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/api Issues or PRs related to the APIs cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants