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

🌱 Refactor godoc for API fields starting with field names #11273

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

tsuzu
Copy link
Contributor

@tsuzu tsuzu commented Oct 8, 2024

What this PR does / why we need it:

  • This PR fixes all field starting with field names to serialized names specified as json tag.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
This is a part of #11238

/area api

@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. area/api Issues or PRs related to the APIs cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 8, 2024
@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 8, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @tsuzu. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@tsuzu tsuzu marked this pull request as ready for review October 8, 2024 16:23
@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 8, 2024
Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

i disagree with

because it disagrees with how Go linters suggest comments for exported objects should be. k8s is quite inconsistent about its Go comments.

@JoelSpeed
Copy link
Contributor

Across kube, the godocs that we write on API fields become generated documentation for end users, sometimes in API references, sometimes via kubectl explain (which you can do on any field in any resource).

If we use the serialised version, then the field description will consistently start with the name of the field as it appears in the yaml, that the user interacts with. If we refer to fields by the Go standard, then the field name will not match what the user interacts with. Most of the time, this is just the case of capitalisation differences, but there are occasions where the serialised and Go field names differ by more than that.

k8s is quite inconsistent about its Go comments.

Looking through the core v1 APIs, the majority are actually following the pattern we are suggesting here. There are some exceptions where random fields are with capitals (like Go would expect) and some where they don't even start with the name at all, so fit neither convention.

When these APIs were written, the conventions were still being formulated. It's natural that there will be inconsistencies from the early days that haven't been fixed, or the odd occasion where a field was missed during review, but if you were to run an API through a core Kube API review now, all of the current reviewers would enforce this standard.

We are writing them with the serialised form to make this easier for the user, as is with most conventions.

@sbueringer
Copy link
Member

Makes sense to me. For what it's worth over the last few years when reviewing PRs I also tried to enforce that we always refer to fields via the "user-facing" names in error messages and logs.

@sbueringer sbueringer changed the title Refactor godoc for API fields starting with field names 🌱 Refactor godoc for API fields starting with field names Oct 9, 2024
@tsuzu
Copy link
Contributor Author

tsuzu commented Oct 14, 2024

The rule that comments should start with field names was enforced by golint, but it's archived.
Now it's also available with staticcheck, but disabled by default: https://staticcheck.dev/docs/checks/#ST1022

so I think that the rule may not be typical nowadays.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 18, 2024
@tsuzu tsuzu force-pushed the fix-godoc-comment-prefix branch from 600524b to aabde11 Compare October 22, 2024 16:25
@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 Oct 22, 2024
@tsuzu tsuzu force-pushed the fix-godoc-comment-prefix branch from aabde11 to a48520c Compare October 23, 2024 16: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 Oct 23, 2024
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.

Let's revert the changes to the kubeadm upstream types, regenerate CRDs and then merge directly

@@ -28,18 +28,18 @@ import (
type InitConfiguration struct {
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 not change the vendored upstream types in upstreamv1beta*

@sbueringer
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 25, 2024
@tsuzu tsuzu force-pushed the fix-godoc-comment-prefix branch from a48520c to 50a4f65 Compare October 31, 2024 02:59
@sbueringer
Copy link
Member

@tsuzu please run 'make generate-manifests generate-go-openapi'

@tsuzu tsuzu force-pushed the fix-godoc-comment-prefix branch from 50a4f65 to f85afdd Compare October 31, 2024 16:03
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 31, 2024
@tsuzu tsuzu force-pushed the fix-godoc-comment-prefix branch from f85afdd to f3d3974 Compare October 31, 2024 16:06
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 31, 2024
@sbueringer
Copy link
Member

Thx!

/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 1, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: d9810fbcab19cd52c4340432d0ab3f95ddbb080f

@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 Nov 1, 2024
@k8s-ci-robot k8s-ci-robot merged commit 9f5a94e into kubernetes-sigs:main Nov 1, 2024
18 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.9 milestone Nov 1, 2024
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants