Skip to content

docs(tenants): document namespace layout and parent/child derivation#479

Merged
lexfrei merged 1 commit intomainfrom
docs/tenant-namespace-naming-convention
Apr 15, 2026
Merged

docs(tenants): document namespace layout and parent/child derivation#479
lexfrei merged 1 commit intomainfrom
docs/tenant-namespace-naming-convention

Conversation

@lexfrei
Copy link
Copy Markdown
Contributor

@lexfrei lexfrei commented Apr 11, 2026

What

Adds two new sections to the Tenant System guide (/docs/v1/guides/tenants/) that document how tenant workload namespace names are constructed and how downstream integrations should walk the tenant tree without string-parsing namespace names.

Why

Tenant workload namespaces follow two different rules depending on depth: tenants created directly under tenant-root get a flat name (tenant-alpha), while tenants created at any deeper level get a hierarchical name (tenant-alpha-beta, tenant-alpha-beta-gamma). This split is not documented anywhere in content/en/docs/v1/, so anyone building dashboards, audit tooling, cost-allocation jobs, or policy engines on top of Cozystack has to infer it from the chart templates. The natural first attempt — strings.Split(namespace, "-") to derive a parent — is wrong for one of the two cases regardless of which heuristic you pick, and integrations that try it run into silent breakage on root-level or deep-level tenants.

The new material:

  • Tenant Namespace Layout — states the two rules plainly, shows a four-row lookup table from root down to root/alpha/beta/gamma, and links to the two source-of-truth files (packages/apps/tenant/templates/_helpers.tpl and pkg/registry/apps/application/rest.go::computeTenantNamespace) so a reader can audit the claim against the implementation.
  • Deriving Parent and Child Relationships — explains why string-parsing the namespace is unreliable and documents the Tenant CR fields that should be used instead: metadata.namespace always equals the parent's workload namespace, status.namespace equals the tenant's own workload namespace, and listing children of a tenant with workload namespace N is list Tenants where metadata.namespace == N. This pattern is stable regardless of whether the tenant is a direct child of tenant-root or a deeper descendant.

No existing content is moved or rewritten; the sections are inserted between Tenant Naming Limitations and Reference, where readers looking for naming details will naturally land.

Verification

  • hugo builds cleanly; the tenants guide renders with both new sections.
  • Table entries cross-checked against packages/apps/tenant/templates/_helpers.tpl::tenant.name in the current cozystack tree (the helper fails the Helm release if the tenant name itself contains a dash, which is why the "namespace fragments never contain tenant-internal dashes" note is accurate).
  • The "metadata.namespace equals the parent's workload namespace" claim matches Kubernetes semantics — Tenant CRs are namespace-scoped and stored in the parent's workload namespace by construction.
  • The aggregated API code path (pkg/registry/apps/application/rest.go::computeTenantNamespace) implements the same flat/hierarchical split, so status.namespace on a Tenant CR is a reliable mirror of the workload namespace.

Summary by CodeRabbit

  • Documentation
    • Added a tenant namespace layout describing deterministic derivation with an example table
    • Guidance for integrations on determining parent vs tenant workload namespaces, plus a kubectl example
    • Documented RFC‑1123 naming constraints, a 63‑character limit for deeper names, and the failure mode when derivation is rejected
    • Minor formatting and cleanup for clarity

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 11, 2026

Deploy Preview for cozystack ready!

Name Link
🔨 Latest commit d37bf26
🔍 Latest deploy log https://app.netlify.com/projects/cozystack/deploys/69df99b2cb46a9000818f430
😎 Deploy Preview https://deploy-preview-479--cozystack.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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ac28b1bb-cfb9-4b7f-a7cc-48183ab15895

📥 Commits

Reviewing files that changed from the base of the PR and between 60ce6f9 and 886743d.

📒 Files selected for processing (1)
  • content/en/docs/v1/guides/tenants/_index.md

📝 Walkthrough

Walkthrough

Documentation adds a deterministic mapping from tenant hierarchy to Kubernetes workload namespaces, documents RFC 1123 and 63-character limits and failure mode, ties the Helm helper _helpers.tpl and API function computeTenantNamespace to Tenant.status.namespace, and instructs using Tenant.metadata.namespace and Tenant.status.namespace to determine parent/child relationships.

Changes

Cohort / File(s) Summary
Tenant Namespace Documentation
content/en/docs/v1/guides/tenants/_index.md
Added "Tenant Namespace Layout" with deterministic namespace derivation rules (tenant-root, tenant-<name>, <parent-workload-namespace>-<name>), example table, RFC 1123 / 63-char warning and failure mode, references to Helm _helpers.tpl and API computeTenantNamespace publishing Tenant.status.namespace, and a "Deriving Parent and Child Relationships" section instructing use of Tenant.metadata.namespace (parent) and Tenant.status.namespace (tenant). Normalized whitespace and list formatting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I map the roots and branches true,

tenant-root, then names that glue,
RFC-safe hops, sixty-three to keep,
status and metadata guide the leap,
I tidy docs and tiptoe through.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately reflects the main changes: documentation additions about tenant namespace layout rules and parent/child relationship derivation, matching the PR's primary objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 docs/tenant-namespace-naming-convention

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

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 updates the tenant documentation by adding sections on the tenant namespace layout and the recommended method for deriving parent-child relationships using the Tenant custom resource. The feedback suggests highlighting the 63-character limit for Kubernetes namespace names to avoid issues with deep hierarchies and including a kubectl command example to help users list child tenants more easily.

Comment on lines +89 to +90
- Tenants created at any deeper level get a **hierarchical** namespace of
the form `<parent-workload-namespace>-<name>`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since the namespace name is constructed hierarchically by appending the tenant name to the parent's workload namespace, it is possible to exceed the Kubernetes limit of 63 characters for namespace names. This is especially relevant for deeply nested hierarchies or long tenant names. It would be beneficial to mention this constraint here to guide users in planning their tenant structure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied — added a warning callout in the Tenant Namespace Layout section about the 63-character RFC 1123 label limit, how deep hierarchies accumulate the ancestor chain into the namespace name, and practical guidance (short tenant names at deeper levels, shallower trees when long names are unavoidable). Also noted that Kubernetes surfaces the rejection through the containing tenant Helm release as a reconcile failure.

Comment on lines +129 to +130
- To list the direct children of a tenant with workload namespace `N`, list
`Tenant` CRs whose `metadata.namespace == N`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To make this guide more actionable for administrators and developers, consider providing the specific kubectl command used to list children. For example: kubectl get tenants -n <parent-workload-namespace>. This directly illustrates the relationship between the parent's workload namespace and the children's metadata namespace described in the text.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied — added an explicit kubectl get tenants --namespace <parent-workload-namespace> example inside the Deriving Parent and Child Relationships section, plus a note that the tenants resource is served by the Cozystack aggregated API (apps.cozystack.io/v1alpha1) and requires cozystack-api to be reachable, with kubectl api-resources --api-group apps.cozystack.io suggested as a quick sanity check.

@lexfrei lexfrei marked this pull request as ready for review April 11, 2026 16:55
@lexfrei lexfrei requested review from kvaps and lllamnyp as code owners April 11, 2026 16:55
Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
content/en/docs/v1/guides/tenants/_index.md (1)

94-99: Consider using explicit table separator for consistency.

The table uses a simplified header separator (---) which is valid Markdown, but explicit column separators (| --- | --- |) might improve consistency with other tables in the documentation.

📝 Proposed formatting enhancement
 | Tenant path             | Workload namespace         |
-| ---                     | ---                        |
+| ----------------------- | -------------------------- |
 | `root`                  | `tenant-root`              |
 | `root/alpha`            | `tenant-alpha`             |
 | `root/alpha/beta`       | `tenant-alpha-beta`        |
 | `root/alpha/beta/gamma` | `tenant-alpha-beta-gamma`  |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@content/en/docs/v1/guides/tenants/_index.md` around lines 94 - 99, The
Markdown table header uses a simplified separator; update the header separator
row so each column has explicit pipe boundaries (e.g. replace the current `---`
row under "Tenant path" and "Workload namespace" with a row that has `| --- |
--- |`) to match the other tables and preserve consistent formatting for the
table containing the rows `root`, `root/alpha`, `root/alpha/beta`, and
`root/alpha/beta/gamma`.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@content/en/docs/v1/guides/tenants/_index.md`:
- Around line 94-99: The Markdown table header uses a simplified separator;
update the header separator row so each column has explicit pipe boundaries
(e.g. replace the current `---` row under "Tenant path" and "Workload namespace"
with a row that has `| --- | --- |`) to match the other tables and preserve
consistent formatting for the table containing the rows `root`, `root/alpha`,
`root/alpha/beta`, and `root/alpha/beta/gamma`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 683cccc1-44af-476d-9d58-3ae6579d14f1

📥 Commits

Reviewing files that changed from the base of the PR and between c6bcf59 and 9056c8c.

📒 Files selected for processing (1)
  • content/en/docs/v1/guides/tenants/_index.md

lexfrei added a commit that referenced this pull request Apr 11, 2026
- Add 63-character RFC 1123 limit warning for deep/long tenant hierarchies
  and describe how Kubernetes surfaces the rejection through the tenant
  Helm release (gemini-code-assist bot comment on #479).
- Add an explicit kubectl example for listing direct children of a tenant
  along with a note that the tenants resource is served by the aggregated
  API and requires cozystack-api to be reachable (gemini-code-assist bot
  comment on #479).
- Rework the Tenant Namespace Layout intro so the hardcoded tenant-root
  case is called out separately from the two derivation rules, reference
  the Helm helper and computeTenantNamespace by plain file + function
  names instead of the non-standard :: notation, and clarify that the
  Helm helper computes the namespace of the child release being installed.
- Rewrite the Deriving Parent and Child Relationships intro: naive string
  splitting actually works today because tenant names are alphanumeric,
  so the argument for preferring the Tenant CR is that parsing relies on
  implementation-detail invariants rather than on a stable contract, not
  that it is outright broken.
- Normalise list bullets (- with one space), drop trailing whitespace and
  duplicate blank lines across the whole file for markdownlint cleanliness.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
lexfrei added a commit that referenced this pull request Apr 12, 2026
- Add 63-character RFC 1123 limit warning for deep/long tenant hierarchies
  and describe how Kubernetes surfaces the rejection through the tenant
  Helm release (gemini-code-assist bot comment on #479).
- Add an explicit kubectl example for listing direct children of a tenant
  along with a note that the tenants resource is served by the aggregated
  API and requires cozystack-api to be reachable (gemini-code-assist bot
  comment on #479).
- Rework the Tenant Namespace Layout intro so the hardcoded tenant-root
  case is called out separately from the two derivation rules, reference
  the Helm helper and computeTenantNamespace by plain file + function
  names instead of the non-standard :: notation, and clarify that the
  Helm helper computes the namespace of the child release being installed.
- Rewrite the Deriving Parent and Child Relationships intro: naive string
  splitting actually works today because tenant names are alphanumeric,
  so the argument for preferring the Tenant CR is that parsing relies on
  implementation-detail invariants rather than on a stable contract, not
  that it is outright broken.
- Normalise list bullets (- with one space), drop trailing whitespace and
  duplicate blank lines across the whole file for markdownlint cleanliness.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
@lexfrei lexfrei force-pushed the docs/tenant-namespace-naming-convention branch from 60ce6f9 to 886743d Compare April 12, 2026 11:46
@lexfrei lexfrei self-assigned this Apr 12, 2026
Two new sections in the v1.2 Tenant System guide:

- Tenant Namespace Layout — states the two naming rules (direct child
  of tenant-root vs. deeper descendant), a lookup table, and links to
  the source-of-truth helper/function in cozystack.
- Deriving Parent and Child Relationships — why string-parsing the
  workload namespace is unreliable, and how to use metadata.namespace /
  status.namespace on the Tenant CR to walk the tree reliably.

Assisted-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>
@lexfrei lexfrei force-pushed the docs/tenant-namespace-naming-convention branch from 886743d to d37bf26 Compare April 15, 2026 13:59
Copy link
Copy Markdown
Member

@kvaps kvaps left a comment

Choose a reason for hiding this comment

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

LGTM

@lexfrei lexfrei merged commit c1a447b into main Apr 15, 2026
6 checks passed
@lexfrei lexfrei deleted the docs/tenant-namespace-naming-convention branch April 15, 2026 14:18
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