[Backport release-1.5] fix(tenant): inherit full ancestor label chain from parent namespace - #3191
Conversation
|
Please cherry-pick the changes locally and resolve any conflicts. git fetch origin backport-2912-to-release-1.5
git worktree add --checkout .worktree/backport-2912-to-release-1.5 backport-2912-to-release-1.5
cd .worktree/backport-2912-to-release-1.5
git reset --hard HEAD^
git cherry-pick -x 59964043e390a7830f79c838cd754d7da0d066d4
git push --force-with-lease |
c17b64b to
50f78ce
Compare
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue where nested tenant namespaces were failing to inherit the full chain of ancestor labels, breaking network policies that rely on these labels for cross-tenant communication. By shifting to a deterministic label derivation based on namespace naming conventions and providing a backfill migration, the changes ensure consistent network reachability across the tenant hierarchy. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request improves how tenant namespace ancestor labels are derived by computing the full ancestor chain directly from the namespace name, resolving an issue where nested tenants at depth >= 2 dropped the tenant-root label and broke network policies. It also adds unit tests, updates the namespace template to support offline rendering, and introduces a migration script to backfill labels on existing namespaces. Feedback on this PR highlights a compatibility issue in the migration script, where set -o pipefail is used with a #!/bin/sh shebang (which will fail on systems using dash as the default shell), and notes that the PR description is missing the required release-note block specified in the style guide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| # kubectl label --overwrite only adds/refreshes the listed labels and never | ||
| # removes others. | ||
|
|
||
| set -euo pipefail |
There was a problem hiding this comment.
Using set -o pipefail (or set -euo pipefail) is a non-POSIX extension supported by shells like bash, zsh, and ksh, but it is not supported by standard POSIX sh (such as dash, which is the default /bin/sh on Debian/Ubuntu systems). Since the shebang of this script is #!/bin/sh, running this script on systems where /bin/sh is dash will result in a startup failure like set: Illegal option -o pipefail, which would block the entire platform migration.
Since there are no other pipelines in this script where pipefail is needed (the only pipeline at line 34-36 already has || true at the end), we can safely change this to set -eu to ensure POSIX compatibility.
| set -euo pipefail | |
| set -eu |
| enabled: false | ||
| image: ghcr.io/cozystack/cozystack/platform-migrations:v1.5.2@sha256:5d601b0709c578945f2e04d655b77d29008c94666a4350e67960c9f6bf9d2bde | ||
| targetVersion: 45 | ||
| targetVersion: 46 |
There was a problem hiding this comment.
The pull request description is missing the required release-note block. According to the Repository Style Guide, every PR must contain a release note block in its body to document changes for the changelog.
Please update the PR description to include the following block:
```release-note
fix(tenant): inherit full ancestor label chain from parent namespace
<details>
<summary>References</summary>
1. PR body must contain a release note block: ```release-note ... ```. Flag any PR whose commits lack the Conventional Commits format or signoff, or whose body has no release-note block. <sup>([link](https://github.com/cozystack/cozystack/blob/main/.gemini/styleguide.md))</sup>
</details>
50f78ce to
3b7c67d
Compare
Backfill tenant.cozystack.io/<ancestor> labels on existing tenant namespaces so clusters heal on upgrade without waiting on each tenant HelmRelease to re-reconcile (#2810/#2171). Backport of migration 49 from #2912, adapted for release-1.5: - migration file 49 -> 46. The existing backport PR #3191 renumbered it to 45, but the SeaweedFS repair migration backported alongside it (#3339 / #3370) claims 45 too, so the two collide. Whichever of those two PRs merges second has to take 46; here the SeaweedFS one keeps 45 because it is what the 1.5.x line is being cut for. - targetVersion 45 -> 47, covering both new migrations. #3191 alone bumps it to 46, and because the two backports agree on that value git merges them without a conflict — leaving targetVersion one short of the highest migration, which run-migrations.sh silently skips (its loop stops at TARGET-1). release-1.5 has no `migrations-target-check` to catch it; that guard arrived on main after v1.5.2 and was never backported. - stamp via the inline labeled-ConfigMap apply used by release-1.5 migrations, since lib/cozystack-version.sh does not exist on this branch Best-effort and idempotent: kubectl label --overwrite adds only the listed labels, and per-namespace failures are tolerated so a transient apiserver error cannot abort the platform upgrade. (cherry picked from commit 50f78ce) Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com> (cherry picked from commit aee9fa85b65d96dae1dff7e5044fd26ce710797e)
The tenant.cozystack.io/<ancestor> namespace labels drive the <ancestor>-egress CiliumClusterwideNetworkPolicy, which lets an ancestor tenant reach a descendant namespace only when the descendant carries tenant.cozystack.io/<ancestor>. namespace.yaml derived that chain by splitting .Release.Namespace, which only reached one level up: a direct child of tenant-root got tenant-root, but a grandchild (tenant-ktj-htdev under tenant-ktj) got only tenant-ktj and dropped tenant-root entirely. The root ingress controller in tenant-root then could not reach nested tenants, surfacing as upstream timeouts. Derive the chain deterministically from the namespace name instead. Every tenant descends from tenant-root, and tenant.name builds each child as <parent-namespace>-<word>, so every progressive dash-prefix of the name is a real ancestor namespace. This needs no cluster lookup, renders offline (so it is unit-testable), and converges on every reconcile regardless of parent/child HelmRelease ordering. The ownerReference lookup is made non-fatal so the template still renders when the parent namespace lookup is empty; in a real reconcile the parent always exists and the ownerReference is always emitted. Signed-off-by: IvanHunters <xorokhotnikov@gmail.com> (cherry picked from commit 1ac9398) (cherry picked from commit 6ce0907) (cherry picked from commit ac7176257b517cbb09fc1792f90ce1f2a18d89be)
3b7c67d to
55d6a5d
Compare
|
Rebased onto current The seaweedfs commits are gone. This branch carried four of them because it was stacked on the seaweedfs backport; those landed via #3370, so the rebase dropped them as already-applied. What remains is the tenant change this PR is actually about: Migration 46 and the Dropping the backfill costs little, on the migration's own terms: it exists only so clusters heal "without waiting on each tenant HelmRelease to re-reconcile", it is "best-effort by design", and it states that if a relabel is skipped the worst case "is strictly no worse than the status quo". The chart fix does the real work — every tenant namespace self-computes its full ancestor chain from its own name on the next reconcile. So on this branch the labels converge as tenant releases reconcile instead of being backfilled in one pass, and slot 46 stays aligned with
|
Description
Backport of #2912 to
release-1.5.