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

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

tsaarni
Copy link
Contributor

@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

@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
Contributor 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

@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
Contributor Author

tsaarni commented Feb 7, 2024

/assign @vincepri

@tsaarni
Copy link
Contributor 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 🙏

@vincepri
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 Jun 16, 2024
Comment on lines 103 to 104
// If we are not inside markdown code black, follow the Kubernetes formatting conventions:
// - Lines after --- are comments and should be ignored.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// If we are not inside markdown code black, follow the Kubernetes formatting conventions:
// - Lines after --- are comments and should be ignored.
// If we are not inside markdown code block, follow the Kubernetes formatting conventions:
// - Lines after --- are comments and should be ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

One minor comment, otherwise lgtm!

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 removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 17, 2024
@k8s-ci-robot k8s-ci-robot requested review from qinqon and vincepri June 17, 2024 06:05
@sbueringer
Copy link
Member

/lgtm

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

LGTM label has been added.

Git tree hash: 1ba4d5d7f9a835609602cfaf6af71fc535e56c34

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kaovilai, tsaarni, vincepri

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

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. 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/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
6 participants