controller-tools icon indicating copy to clipboard operation
controller-tools copied to clipboard

:warning: Strip comments from CRD descriptions

Open tsaarni opened this issue 1 year ago • 8 comments

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 :warning: 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

tsaarni avatar Jan 24 '24 09:01 tsaarni

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 avatar Jan 24 '24 09:01 k8s-ci-robot

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. :smiley:

k8s-ci-robot avatar Jan 24 '24 09:01 k8s-ci-robot

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

tsaarni avatar Jan 24 '24 09:01 tsaarni

[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

k8s-ci-robot avatar Jan 24 '24 14:01 k8s-ci-robot

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

qinqon avatar Jan 24 '24 14:01 qinqon

LGTM label has been added.

Git tree hash: 037e0f10c0dbb0835758444fadb42fe99470ea1c

k8s-ci-robot avatar Jan 24 '24 14:01 k8s-ci-robot

/assign @vincepri

tsaarni avatar Feb 07 '24 10:02 tsaarni

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

tsaarni avatar Apr 17 '24 16:04 tsaarni