Skip to content

DOC-1387 Add Kubernetes automations to the CLI #103

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

JakeSCahill
Copy link
Contributor

@JakeSCahill JakeSCahill commented May 15, 2025

This pull request introduces two new utility functions for handling documentation-related tasks and updates the package version to reflect these additions. The key changes include a function to convert documentation URLs into Antora xref resource IDs, another to determine the appropriate documentation branch based on an operator tag, and a version bump in package.json.

New CLI commands

Added two new CLI commands for generating the Helm spec docs and the CRD docs for Kubernetes.

New utility functions:

  • cli-utils/convert-doc-links.js: Added urlToXref function to convert docs.redpanda.com URLs into Antora xref resource IDs, preserving optional labels. This includes validation and parsing of the URL structure.
  • cli-utils/self-managed-docs-branch.js: Added fetchRemoteAntoraVersion to retrieve the latest documented Self-Managed version from a remote antora.yml file, and determineDocsBranch to decide the appropriate documentation branch based on an operator tag and the Antora version. Includes branch existence verification.

Version update:

  • package.json: Updated the package version from 4.4.2 to 4.5.0 to reflect the addition of new features.

Test the new commands

Clone this repo or pull the latest:

git pull

Check out the branch:

git checkout k8s-cli

Run the commands:

doc-tools generate crd-spec -t release/v2.4.x 
doc-tools generate helm-spec -t release/v2.4.x 

Copy link

netlify bot commented May 15, 2025

Deploy Preview for docs-extensions-and-macros ready!

Name Link
🔨 Latest commit e7ae313
🔍 Latest deploy log https://app.netlify.com/projects/docs-extensions-and-macros/deploys/682b54321baa6b0008f7342b
😎 Deploy Preview https://deploy-preview-103--docs-extensions-and-macros.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

coderabbitai bot commented May 15, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The changes introduce significant enhancements and new features to the documentation tooling scripts. The main CLI script (bin/doc-tools.js) is refactored to standardize dependency checks and error handling, and several new CLI commands are added, including link-readme, fetch, and new subcommands under generate for producing Helm chart and CRD documentation from local or GitHub sources. Two new utility modules are introduced: one for converting Redpanda documentation URLs to Antora xref IDs, and another for determining the correct documentation branch based on operator tags and remote Antora versions. The package version is incremented to 4.5.0.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI (doc-tools.js)
    participant GitHub
    participant LocalFS
    participant UtilityModules

    User->>CLI (doc-tools.js): Run "generate helm-spec" or "generate crd-spec"
    CLI (doc-tools.js)->>UtilityModules: Verify dependencies (requireTool, requireCmd, etc.)
    CLI (doc-tools.js)->>GitHub: (If GitHub source) Clone repo/fetch files
    CLI (doc-tools.js)->>LocalFS: Run tool (helm-docs/crd-ref-docs), process files
    CLI (doc-tools.js)->>UtilityModules: Convert output (Markdown to AsciiDoc, post-process)
    CLI (doc-tools.js)->>LocalFS: Write results, clean up temp files
    CLI (doc-tools.js)->>User: Print completion message/instructions
Loading

Possibly related PRs

Suggested reviewers

  • asimms41

🪧 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 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.

coderabbitai bot added a commit that referenced this pull request May 15, 2025
Docstrings generation was requested by @JakeSCahill.

* #103 (comment)

The following files were modified:

* `bin/doc-tools.js`
* `cli-utils/convert-doc-links.js`
* `cli-utils/self-managed-docs-branch.js`
Copy link
Contributor

coderabbitai bot commented May 15, 2025

Note

Generated docstrings for this pull request at #104

Copy link
Contributor

@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: 6

🧹 Nitpick comments (8)
cli-utils/self-managed-docs-branch.js (3)

56-60: Document or rethink the hard-coded 2.4 → 24.3 exception

The special-case mapping from v2.4 to v/24.3 (or main) is opaque. New
contributors will not know why 2.4 maps to 24.3, and future version bumps may
break silently.

Action items
• Add a code comment that links to the policy/decision doc.
• Consider externalising the mapping to a JSON or env-driven config so unusual
rules don’t require code changes.


70-72: Synchronous git call blocks the event loop

spawnSync freezes the entire Node process while the network call to the
remote Git repo runs. For CLI tools invoked in scripts this can add noticeable
latency, and in long-running processes it can starve the event loop.

If you don’t truly need strict serial execution, switch to the async variant:

-const ok = spawnSync('git', ['ls-remote', '--exit-code', '--heads', repo, ref], {
-  stdio: 'ignore'
-}).status === 0
+const ok = (await new Promise(r =>
+  spawn('git', ['ls-remote', '--exit-code', '--heads', repo, ref], { stdio: 'ignore' })
+    .on('exit', code => r(code === 0))
+))

(Or reuse an existing git-API package for cleaner code.)


41-45: Minor: broaden accepted prefixes

You strip only operator/ and release/. Tags like helm/ or chart/ would
fail even though they are version-qualified strings. Consider making the prefix
list configurable or defaulting to “trim anything before the first v”.

cli-utils/convert-doc-links.js (3)

18-22: Label-extraction regex is too greedy

/^(.*)\[([^\]]+)\]$/ will treat the last [ as the delimiter, so a URL
containing a real [ in its path (rare, but legal) mis-parses.
Use a non-greedy match or limit the character class before the label:

-const mLabel = input.match(/^(.*)\[([^\]]+)\]$/);
+const mLabel = input.match(/^(.*?)\s*\[([^\]]+)\]$/);

Alternatively split on the first [ from the right with
const idx = input.lastIndexOf('[').


31-33: Host validation blocks www.docs.redpanda.com & future sub-domains

The strict regex only allows the bare domain. If marketing switches to
www.docs.redpanda.com or a regional CNAME, the converter breaks.

-if (!/docs\.redpanda\.com$/.test(url.hostname)) {
+if (!/(\.)?docs\.redpanda\.com$/.test(url.hostname)) {

You might also want to allow staging domains behind a feature flag.


45-53: Edge-case: root-level pages lose their module

When the path is just a single segment (e.g. /legal/), moduleName and the
resulting file name are identical (legal.adoc). That’s fine if every module
has a root page named like itself; otherwise, you might want to default to
index.adoc.

Consider:

const fileName   = (pagePath || 'index') + '.adoc';
package.json (1)

3-3: Version bump acknowledged—don’t forget CHANGELOG

"version": "4.5.0" looks good. Ensure the accompanying CHANGELOG or release
notes capture the new Kubernetes CLI features so downstream consumers know what
changed.

bin/doc-tools.js (1)

548-552: Minor readability tweak: optional chaining simplifies the null-check

-const inDocs   = pkg.name === 'redpanda-docs-playbook'
-                   || (pkg.repository && pkg.repository.url.includes('redpanda-data/docs'));
+const inDocs = pkg.name === 'redpanda-docs-playbook'
+  || pkg.repository?.url?.includes('redpanda-data/docs');

Using optional chaining conveys intent and eliminates the manual && guard.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a3e7ce9 and 3b4b49c.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • bin/doc-tools.js (7 hunks)
  • cli-utils/convert-doc-links.js (1 hunks)
  • cli-utils/self-managed-docs-branch.js (1 hunks)
  • package.json (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
bin/doc-tools.js (3)
cli-utils/convert-doc-links.js (4)
  • require (1-1)
  • p (36-39)
  • moduleName (49-49)
  • url (25-25)
cli-utils/self-managed-docs-branch.js (5)
  • require (3-3)
  • repo (68-68)
  • ref (69-69)
  • ok (70-72)
  • url (10-10)
tools/fetch-from-github.js (2)
  • path (2-2)
  • fs (1-1)
🪛 Biome (1.9.4)
cli-utils/self-managed-docs-branch.js

[error] 21-21: Invalid typeof comparison value: this expression is not a string literal

not a string literal

(lint/suspicious/useValidTypeof)

bin/doc-tools.js

[error] 567-568: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - docs-extensions-and-macros
  • GitHub Check: Header rules - docs-extensions-and-macros
  • GitHub Check: Pages changed - docs-extensions-and-macros

coderabbitai bot and others added 3 commits May 15, 2025 11:48
Docstrings generation was requested by @JakeSCahill.

* #103 (comment)

The following files were modified:

* `bin/doc-tools.js`
* `cli-utils/convert-doc-links.js`
* `cli-utils/self-managed-docs-branch.js`

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@JakeSCahill JakeSCahill changed the title Add Kubernetes automations to the CLI DOC-1387 Add Kubernetes automations to the CLI May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant