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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign sbueringer 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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api Issues or PRs related to the APIs cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants