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

⚠️ Strip comments from CRD descriptions #877

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

Conversation

tsaarni
Copy link

@tsaarni tsaarni commented Jan 24, 2024

This PR strips comments from the generated CRDs for clarity of the public API documentation.

The change aligns controller-tools with Kubernetes conventions for type descriptions:

  • Line that only contains --- separates the API description from comments. The leading lines are part of public documentation, the trailing lines are internal instructions such as code examples etc. As an example, see widely used type Condition that includes some example code that should not be considered as part of API documentation.
  • Line that begins with TODO is internal note for implementer, and not part of public documentation of the type. See LocalObjectReference for example.

Background information

When Kubernetes itself generates OpenAPI docs for its internal resources, it will strip the implementation related comments from the go docs. I believe it is done by this code.

However with controller-tools the implementation comments "leak" to public documentation. This causes confusion and usability issues since the users have no context to understand the implementation comments.

Google search for "Represents the observations of a foo's current state" shows that the problem is wide spread.

Limited compatibility with markdown formatting

I've marked the PR as ⚠️ breaking with following reasoning:

While I first thought it is very unlikely to bump into --- in type's documentation, I'm proven wrong by #870 which shows that sometimes markdown formatting is used inside go docs. kubectl explain will not understand how to format markdown, but the reasoning for markdown inside go docs might come from OpenAPI spec which supports "rich text formatting" with CommonMark 0.27

There is a limitation: There is no reliable way to know if go doc is in plain text or markdown, therefore --- could mean comment separator (according to Kubernetes convention) or alternatively thematic break or heading (according to markdown). The implementation takes an approach where --- inside markdown fenced code blocks is kept, but when seen in plain, it is considered as comment separator and rest of the doc is stripped. This might be wrong assumption in some corner cases. As result the description in the generated CRD will be cut short.

Fixes #649, #728, #875

Kubernetes has some conventions for type descriptions:

- Line that only contains --- separates the description from comments.
  The leading lines are part of public documentation, the trailing lines are
  internal instructions such as code examples etc.
- Line that begins with TODO are internal notes for implementers, and not
  part of public documentation of the type.

This change strips above informational text away from the generated CRDs
while keeping them if they appear inside markdown fenced code block.

Signed-off-by: Tero Saarni <tero.saarni@est.tech>
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 24, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @tsaarni. 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 24, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @tsaarni!

It looks like this is your first PR to kubernetes-sigs/controller-tools 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-tools has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 24, 2024
@tsaarni tsaarni changed the title Strip comments from CRD descriptions ⚠️ Strip comments from CRD descriptions Jan 24, 2024
@tsaarni
Copy link
Author

tsaarni commented Jan 24, 2024

I'm cc'ing @qinqon, @cbandy, @kaovilai in case you are interested to comment this PR as well.

Copy link

@kaovilai kaovilai left a comment

Choose a reason for hiding this comment

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

For my use this is lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kaovilai, tsaarni
Once this PR has been reviewed and has the lgtm label, please assign vincepri 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

@qinqon
Copy link
Contributor

qinqon commented Jan 24, 2024

Since it discriminates between code blocks and "normal" --- is fine by me
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 24, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 037e0f10c0dbb0835758444fadb42fe99470ea1c

@tsaarni
Copy link
Author

tsaarni commented Feb 7, 2024

/assign @vincepri

@tsaarni
Copy link
Author

tsaarni commented Apr 17, 2024

Hi @vincepri, If you have a moment, could you please take a look? Your feedback would be greatly appreciated 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. 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.

Imported descriptions do not match upstream
5 participants