Skip to content

feat: add policy namespaces as direct subcommand of policy#789

Merged
jakedoublev merged 5 commits intomainfrom
feat/ns
Apr 1, 2026
Merged

feat: add policy namespaces as direct subcommand of policy#789
jakedoublev merged 5 commits intomainfrom
feat/ns

Conversation

@jakedoublev
Copy link
Copy Markdown
Contributor

@jakedoublev jakedoublev commented Apr 1, 2026

Summary

  • Moves namespace docs from policy/attributes/namespaces to policy/namespaces
  • Registers policy namespaces as a direct subcommand alongside the existing policy attributes namespaces path
  • DRYs up command init via shared buildNamespacesCommandTree() builder
  • Adds BATs test coverage for the direct policy namespaces path

Summary by CodeRabbit

  • New Features

    • Added direct path support for policy namespaces commands alongside the existing attribute-based access; both paths behave consistently.
  • Documentation

    • Updated CLI examples to use the direct policy namespaces command path across namespace-related docs.
  • Tests

    • Added end-to-end tests covering policy namespaces operations (create, get, list, delete) via the direct command path.

@jakedoublev jakedoublev requested a review from a team as a code owner April 1, 2026 18:27
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9e80e673-da1f-46ef-ab14-9260ea4c0e13

📥 Commits

Reviewing files that changed from the base of the PR and between 84a36b2 and 0344e9c.

📒 Files selected for processing (10)
  • docs/man/policy/namespaces/create.md
  • docs/man/policy/namespaces/deactivate.md
  • docs/man/policy/namespaces/get.md
  • docs/man/policy/namespaces/key/assign.md
  • docs/man/policy/namespaces/key/remove.md
  • docs/man/policy/namespaces/list.md
  • docs/man/policy/namespaces/unsafe/delete.md
  • docs/man/policy/namespaces/unsafe/reactivate.md
  • docs/man/policy/namespaces/unsafe/update.md
  • docs/man/policy/namespaces/update.md
✅ Files skipped from review due to trivial changes (10)
  • docs/man/policy/namespaces/create.md
  • docs/man/policy/namespaces/update.md
  • docs/man/policy/namespaces/get.md
  • docs/man/policy/namespaces/unsafe/delete.md
  • docs/man/policy/namespaces/key/remove.md
  • docs/man/policy/namespaces/unsafe/reactivate.md
  • docs/man/policy/namespaces/unsafe/update.md
  • docs/man/policy/namespaces/key/assign.md
  • docs/man/policy/namespaces/deactivate.md
  • docs/man/policy/namespaces/list.md

📝 Walkthrough

Walkthrough

Replaced a shared package-level Cobra command with a builder that constructs independent policy namespaces command trees; initNamespacesCommands() now registers two separate trees (for Cmd and AttributesCmd). Added an e2e test exercising the direct policy namespaces command path and updated man pages to use the shorter command path.

Changes

Cohort / File(s) Summary
Command Construction Refactor
cmd/policy/namespaces.go
Removed exported NamespacesCmd. Added newCommandFromDoc and buildNamespacesCommandTree to create independent *cobra.Command instances; initNamespacesCommands() now registers two separate trees and sources metadata via man.Docs.GetDoc(...), assembling subcommands with AddCommand(...).
End-to-End Tests
e2e/namespaces.bats
Added run_otdfctl_nsd helper to invoke ./otdfctl policy namespaces. Added test "Direct path: policy namespaces commands are accessible" to create/get/list/delete a namespace using the direct command path.
Documentation Updates
docs/man/policy/namespaces/*, docs/man/policy/namespaces/key/*, docs/man/policy/namespaces/unsafe/*
Updated multiple man page examples to remove the attributes segment from otdfctl policy attributes namespaces ..., replacing with otdfctl policy namespaces ... across create/get/list/update/deactivate/unsafe/key examples.

Sequence Diagram(s)

(omitted — changes are refactor and documentation/test updates that do not introduce a new multi-actor runtime flow requiring visualization)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • elizabethhealy
  • c-r33d
  • alkalescent

Poem

🐇 I split the old shared branch into two,

Each command tree now wakes brand new.
Tests hopped in, checking names with delight,
Docs trimmed the path to keep things light.
A nibble of code, and off I chew. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding policy namespaces as a direct subcommand of policy, which aligns with the primary objective of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ns

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the namespace command structure to allow the command tree to be registered under multiple parent commands, specifically enabling access via both policy namespaces and policy attributes namespaces. It introduces a helper function to create commands from documentation metadata and adds end-to-end tests for the new direct path. The review feedback identifies several instances where subcommands (delete, reactivate, and unsafe update) incorrectly reference the documentation object of the deactivate command for their flag metadata instead of using their own, which could lead to inconsistencies.

Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
cmd/policy/namespaces.go (1)

414-445: Use each command's own doc for its id flag instead of deactivateDoc.

The deleteCmd, reactivateCmd, and unsafeUpdateCmd all reference deactivateDoc.GetDocFlag("id") instead of their respective doc variables. While the flag definitions may currently be identical, this coupling is fragile—if any command's doc evolves independently, this will silently use the wrong metadata. This pattern is handled correctly in attributes.go, where each command uses its own doc.

♻️ Suggested fix
 	deleteDoc := man.Docs.GetDoc("policy/namespaces/unsafe/delete")
 	deleteCmd := newCommandFromDoc(deleteDoc, unsafeDeleteAttributeNamespace)
 	deleteCmd.Flags().StringP(
-		deactivateDoc.GetDocFlag("id").Name,
-		deactivateDoc.GetDocFlag("id").Shorthand,
-		deactivateDoc.GetDocFlag("id").Default,
-		deactivateDoc.GetDocFlag("id").Description,
+		deleteDoc.GetDocFlag("id").Name,
+		deleteDoc.GetDocFlag("id").Shorthand,
+		deleteDoc.GetDocFlag("id").Default,
+		deleteDoc.GetDocFlag("id").Description,
 	)

 	reactivateDoc := man.Docs.GetDoc("policy/namespaces/unsafe/reactivate")
 	reactivateCmd := newCommandFromDoc(reactivateDoc, unsafeReactivateAttributeNamespace)
 	reactivateCmd.Flags().StringP(
-		deactivateDoc.GetDocFlag("id").Name,
-		deactivateDoc.GetDocFlag("id").Shorthand,
-		deactivateDoc.GetDocFlag("id").Default,
-		deactivateDoc.GetDocFlag("id").Description,
+		reactivateDoc.GetDocFlag("id").Name,
+		reactivateDoc.GetDocFlag("id").Shorthand,
+		reactivateDoc.GetDocFlag("id").Default,
+		reactivateDoc.GetDocFlag("id").Description,
 	)

 	unsafeUpdateDoc := man.Docs.GetDoc("policy/namespaces/unsafe/update")
 	unsafeUpdateCmd := newCommandFromDoc(unsafeUpdateDoc, unsafeUpdateAttributeNamespace)
 	unsafeUpdateCmd.Flags().StringP(
-		deactivateDoc.GetDocFlag("id").Name,
-		deactivateDoc.GetDocFlag("id").Shorthand,
-		deactivateDoc.GetDocFlag("id").Default,
-		deactivateDoc.GetDocFlag("id").Description,
+		unsafeUpdateDoc.GetDocFlag("id").Name,
+		unsafeUpdateDoc.GetDocFlag("id").Shorthand,
+		unsafeUpdateDoc.GetDocFlag("id").Default,
+		unsafeUpdateDoc.GetDocFlag("id").Description,
 	)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/policy/namespaces.go` around lines 414 - 445, The id flag for deleteCmd,
reactivateCmd, and unsafeUpdateCmd is incorrectly sourced from deactivateDoc;
update each flag call to use its own doc variable (use
deleteDoc.GetDocFlag("id") for deleteCmd, reactivateDoc.GetDocFlag("id") for
reactivateCmd, and unsafeUpdateDoc.GetDocFlag("id") for unsafeUpdateCmd) so each
command reads the id metadata from its corresponding doc object (leave the name
flag for unsafeUpdateCmd as-is using unsafeUpdateDoc).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmd/policy/namespaces.go`:
- Around line 414-445: The id flag for deleteCmd, reactivateCmd, and
unsafeUpdateCmd is incorrectly sourced from deactivateDoc; update each flag call
to use its own doc variable (use deleteDoc.GetDocFlag("id") for deleteCmd,
reactivateDoc.GetDocFlag("id") for reactivateCmd, and
unsafeUpdateDoc.GetDocFlag("id") for unsafeUpdateCmd) so each command reads the
id metadata from its corresponding doc object (leave the name flag for
unsafeUpdateCmd as-is using unsafeUpdateDoc).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8ab5977b-5366-4190-86b8-d5bcac8d0313

📥 Commits

Reviewing files that changed from the base of the PR and between e4f5f72 and 07c81e5.

📒 Files selected for processing (15)
  • cmd/policy/namespaces.go
  • docs/man/policy/namespaces/_index.md
  • docs/man/policy/namespaces/create.md
  • docs/man/policy/namespaces/deactivate.md
  • docs/man/policy/namespaces/get.md
  • docs/man/policy/namespaces/key/_index.md
  • docs/man/policy/namespaces/key/assign.md
  • docs/man/policy/namespaces/key/remove.md
  • docs/man/policy/namespaces/list.md
  • docs/man/policy/namespaces/unsafe/_index.md
  • docs/man/policy/namespaces/unsafe/delete.md
  • docs/man/policy/namespaces/unsafe/reactivate.md
  • docs/man/policy/namespaces/unsafe/update.md
  • docs/man/policy/namespaces/update.md
  • e2e/namespaces.bats

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Copy link
Copy Markdown

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/policy/namespaces.go`:
- Around line 321-338: The builder uses man.Docs.GetDoc(...) directly which
bypasses the man layer's CommandOpts processing (including recomputing Short
from DocSubcommands); change those calls to use man.Docs.GetCommand(...) before
cloning so the computed metadata is applied. In buildNamespacesCommandTree
replace the GetDoc("policy/namespaces") and the other GetDoc call sites (the
ones around lines building the "unsafe" and "key" subcommands) with
GetCommand("policy/namespaces")/GetCommand(...) and then clone or extract the
underlying Doc as needed so the CommandOpts and derived Short descriptions are
preserved when constructing nsCmd and its subcommands.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d51c17a8-00b4-42c5-afbb-71491baf4248

📥 Commits

Reviewing files that changed from the base of the PR and between 07c81e5 and 84a36b2.

📒 Files selected for processing (1)
  • cmd/policy/namespaces.go

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

@alkalescent alkalescent left a comment

Choose a reason for hiding this comment

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

lgtm

@jakedoublev jakedoublev merged commit 2d8a147 into main Apr 1, 2026
22 checks passed
@jakedoublev jakedoublev deleted the feat/ns branch April 1, 2026 21:09
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.

2 participants