Skip to content

🌱 Add an api convention doc #385

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

Merged

Conversation

qiujian16
Copy link
Member

@qiujian16 qiujian16 commented Jul 24, 2025

Summary

Related issue(s)

Fixes #

Summary by CodeRabbit

  • Documentation
    • Added a new guide outlining API conventions, including guidelines for configuration and workload APIs, defaulting behaviors, struct usage, discriminated unions, and best practices for API design.

@openshift-ci openshift-ci bot requested review from deads2k and mdelder July 24, 2025 08:41
Copy link
Contributor

openshift-ci bot commented Jul 24, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiujian16

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

Copy link

coderabbitai bot commented Jul 24, 2025

Walkthrough

A new documentation file, docs/api-conventions.md, has been added. This document outlines OCM API conventions, referencing Kubernetes and OpenShift practices, and provides guidelines on API categorization, defaulting behavior, pointer usage, discriminated unions, annotation-based extensions, documentation comments, object references, and Boolean field usage.

Changes

Files Change Summary
docs/api-conventions.md Added new documentation detailing OCM API conventions, including design and usage guidelines.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
docs/api-conventions.md (5)

3-4: Fix typos and refine wording in introduction header.

Minor editorial nits:
• “guidlines” → “guidelines”
• “inspired from” → “inspired by”

-OCM APIs follow the [Kubernetes API conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md)
-with some additional guidlines inspired from [OpenShift API Convention](https://github.com/openshift/enhancements/blob/master/dev-guide/api-conventions.md).
+OCM APIs follow the [Kubernetes API conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md)
+with additional guidelines inspired by the [OpenShift API Convention](https://github.com/openshift/enhancements/blob/master/dev-guide/api-conventions.md).

49-50: Use “incompatible” for conciseness.

The phrase “not compatible with” can be shortened.

-The JSON tag `omitempty` is not compatible with struct references.
+The JSON tag `omitempty` is incompatible with struct references.

75-77: Tighten language around annotation-based APIs.

“Seem as” → “seem like”; “usually never happens” is a double negative—prefer “rarely happens”.

-Do not use annotations for extending an API. Annotations may seem as a good candidate for introducing experimental/new
-API. Nevertheless, migration from annotations to formal schema usually never happens as it requires breaking changes
-in customer deployments.
+Do not use annotations to extend an API. Annotations may seem like a good vehicle for introducing experimental or new
+functionality, but migration from annotations to a formal schema rarely occurs because it requires breaking changes
+in customer deployments.

82-82: Replace “can not” with “cannot”.

-4. Hard to extend. An annotation value (a string) can not be extended with additional fields under a parent.
+4. Hard to extend. An annotation value (a string) cannot be extended with additional fields under a parent.

88-90: Capitalize “GoDoc” and clarify guidance.

Small stylistic tweak and clearer phrasing.

-Ensure that the godoc for a field name matches the JSON name, not the Go name,
-in Go definitions for API objects.  In particular, this means that the godoc for
-field names should use an initial lower-case letter.
+Ensure that the GoDoc comment for a field matches its JSON name, not the Go struct field name.
+Specifically, the comment should start with the JSON name (initial lower-case letter).
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 779879f and 3658671.

📒 Files selected for processing (1)
  • docs/api-conventions.md (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
docs/api-conventions.md (1)

Learnt from: qiujian16
PR: #380
File: client/work/clientset/versioned/fake/clientset_generated.go:40-40
Timestamp: 2025-07-02T14:09:55.079Z
Learning: Generated code files marked with "Code generated by client-gen. DO NOT EDIT." should not be manually edited as they are automatically generated by Kubernetes code-generator tools and any changes would be overwritten.

🪛 LanguageTool
docs/api-conventions.md

[style] ~49-~49: Consider using “incompatible” to avoid wordiness.
Context: ... be unset. The JSON tag omitempty is not compatible with struct references. Meaning any str...

(NOT_ABLE_PREMIUM)


[style] ~75-~75: Consider using a different adjective in this context to strengthen your wording.
Context: ...nding an API. Annotations may seem as a good candidate for introducing experimental/...

(GOOD_ALTERNATIVE)


[style] ~79-~79: To elevate your writing, try using a synonym here.
Context: ...n. User set values can be too broad and hard to limit later on. 2. Lack of discovera...

(HARD_TO)


[style] ~82-~82: Unless you want to emphasize “not”, use “cannot” which is more common.
Context: ... extend. An annotation value (a string) can not be extended with additional fields unde...

(CAN_NOT_PREMIUM)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: verify

@zhujian7
Copy link
Member

Thanks for adding this, very very informative and helpful!
/lgtm
/hold in case other reviewers want to take a look.

@xuezhaojun
Copy link
Member

xuezhaojun commented Jul 29, 2025

/lgtm

Looks good to me! we could have some examples in this doc, but it can be done in another follow-up PR.

@qiujian16
Copy link
Member Author

/unhold

@openshift-merge-bot openshift-merge-bot bot merged commit e861393 into open-cluster-management-io:main Jul 29, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants