Skip to content

Commit ae7a711

Browse files
authored
fix(harbor-rd): carry the release prefix in the resource selectors (#4170)
<!-- Thank you for making a contribution! Here are some tips for you: - Use Conventional Commits for the PR title: `type(scope): description` - Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore - Scopes are not an exhaustive list — pick the most specific scope for the change and extend the list when a genuinely new area appears. Examples: - System components: dashboard, platform, operator, cilium, kube-ovn, linstor, fluxcd, cluster-api - Managed apps: postgres, mariadb, redis, kafka, clickhouse, virtual-machine, kubernetes - Development and maintenance: api, hack, tests, ci, docs, maintenance - Breaking changes: append `!` after type/scope (`feat(api)!: ...`) or add a `BREAKING CHANGE:` footer - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `kind/backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does `harbor` declares `release.prefix: "harbor-"` and then selects its Secret, Service and Ingress without it, so all three `resourceNames` selectors match nothing. This corrects the three names and adds a guard so the next omission fails a test instead of passing silently. ### Why they never matched Release names are `<prefix><app name>`, but the lineage webhook evaluates selectors against `{kind, name, namespace}`, where `name` is the custom resource's name and carries no prefix. Every definition therefore spells the prefix out itself, and the others do — `postgres-{{ .name }}-credentials`, `bucket-{{ .name }}-credentials`, and so on. `harbor` is the only one that does not. A selector that matches nothing raises no error: the webhook labels the object `internal.cozystack.io/tenantresource=false` and continues, which is indistinguishable from a selector that legitimately has nothing to match. That is why this survived. ### What actually changes at runtime Close to nothing, and that is the point — the manifest was wrong, not the behaviour: - the Secret already reaches tenants, because #2541 worked around this exact mismatch by stamping `apps.cozystack.io/user-secret: "true"` on it and matching by label. That workaround is deliberately left in place; - the Service and Ingress labels flip from `false` to `true`, which nothing consumes: `spec.services` and `spec.ingresses` are read only by the webhook that computes the label, and the label's only consumer is the TenantSecret registry, which handles Secrets. The dashboard reaches both through the per-release Role, which names them correctly. So this closes a latent defect before it bites, rather than fixing an outage. ### The guard `hack/check-rd-release-prefix.bats` asserts that every `resourceNames` entry in `packages/system/*-rd/cozyrds/*.yaml` contains `<prefix>{{ .name }}`. `hack/*.bats` is auto-discovered by `BATS_UNIT_FILES`, so it runs under `make unit-tests` with no registration. The assertion is "contains", not "starts with", because operator-created objects legitimately carry leading words of their own: mongodb excludes `internal-mongodb-{{ .name }}-users`, which is correct and stays green. Definitions with an empty prefix are skipped, since `hack/update-crd.sh` generates the definitions for `packages/extra` charts with `PREFIX=""`. A selector that is correct and still fails the check can opt out on its own with a trailing `# cozy-lint:ignore rd-release-prefix -- <reason>` comment. A directive without a reason does not count. Verified by mutation: the guard fails on the three harbor selectors before the fix and passes after. Across the rest of the tree `harbor` was the only violation. ### What this PR does not do It does not settle whether the prefix belongs in the template context instead. That would remove the duplication, but it requires migrating the definitions that spell the prefix out today, or they would double it. The guard is the cheaper half and closes the class either way. ### Screenshots <!-- REQUIRED for UI changes: attach screenshots or screen recordings demonstrating the visual impact of your changes. PRs with UI changes without screenshots will not be merged. --> ### Downstream repositories <!-- Cozystack is upstream for repositories that are NOT kept in sync with it automatically, and nothing in CI compares the two sides, so a change here can break them silently. Which change forces what, and which file to touch, is the trigger map in docs/agents/contributing.md under "Downstream Repositories". Walk it before you tick anything. IF YOU ARE AN AI AGENT OR AN LLM, THIS IS PART OF THE TASK, NOT A FORM TO FILL IN: 1. Walk the trigger map against the actual diff of this PR, file by file. Do not decide from the PR title or from your memory of what you changed. 2. For every repository you tick, open the follow-up PR there and link it on the same line. A ticked box with no link claims work that does not exist, which is worse than an empty box. Search that repository for an open PR or issue covering it first, and link that instead of filing a duplicate. 3. When the follow-up is out of scope, or needs a decision that is not yours to make, open an issue in that repository instead, link that, and say so in the PR body. Do not push a speculative PR into another repository just to fill a line here. 4. Do not tick "No downstream repository is affected" to make the checklist go away. If you are unsure, leave every box empty and say so in the PR body, so a human decides. --> - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: Trigger map walked against the diff, which touches `packages/system/harbor-rd/cozyrds/harbor.yaml` and adds `hack/check-rd-release-prefix.bats`. The two nearest entries were checked and neither fires: - **terraform-provider-cozystack** lists "change `release.prefix`, or rename an output Secret or Service". Neither happens here: `release.prefix` is untouched and no object is renamed. The provider concatenates the prefix itself to derive names, so it was already computing the correct ones — it is this definition's selectors that were wrong. - **ccp** lists "rename `packages/system/<name>-rd/cozyrds/<name>.yaml`" and "move or rename anything under `hack/`". The file is edited, not renamed, and the new bats file is an addition; no make target changes behaviour. **website** would fire on a change to `ApplicationDefinition` semantics. Semantics are unchanged — one definition's data is corrected — and `content/en/docs/next/cozystack-api/application-definitions.md` documents neither `resourceNames` nor the prefix rule, so there is nothing there to bring in step. ### Release note <!-- Write a release note: - Explain what has changed internally and for users. - Start with the same `type(scope):` prefix as in the PR title - Follow the guidelines at https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md. --> ```release-note fix(harbor-rd): the ApplicationDefinition selectors for Harbor's Secret, Service and Ingress now carry the release prefix, so they match the objects the chart creates. No user-visible change — the Secret already reached tenants through a label-based workaround, and nothing consumes the Service and Ingress labels. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Updated Harbor resource naming patterns to consistently include the `harbor-` prefix for credentials, services, and ingress resources. - Improved alignment between Harbor resource names and their configured release prefixes. - **Tests** - Added validation to detect missing release prefixes in secret, service, and ingress resource selectors across system application definitions. - Validation reports all affected selectors and supports documented exceptions where necessary. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 79602e9 + 9111202 commit ae7a711

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

‎hack/check-rd-release-prefix.bats‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bats
2+
# "contains <prefix>{{ .name }}" rather than a prefix match: operator-created
3+
# objects carry their own leading words, such as redis's "rfs-redis-{{ .name }}"
4+
# and mongodb's excluded "internal-mongodb-{{ .name }}-users".
5+
#
6+
# An empty spec.release.prefix is skipped: hack/update-crd.sh generates the
7+
# definitions for packages/extra charts with PREFIX="".
8+
9+
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
10+
11+
@test "every resourceNames selector carries its release prefix" {
12+
command -v yq >/dev/null || { echo "yq (mikefarah v4+) is required" >&2; exit 1; }
13+
14+
violations=""
15+
total=0
16+
for f in "$REPO_ROOT"/packages/system/*-rd/cozyrds/*.yaml; do
17+
[ -f "$f" ] || continue
18+
prefix="$(yq -r '.spec.release.prefix // ""' "$f")"
19+
[ -n "$prefix" ] || continue
20+
21+
# One "<section>.<include|exclude> TAB <name> TAB <line comment>" row per
22+
# selector entry. yq sees the comment only on a block-style entry: on a
23+
# flow sequence ("[a, b] # ...") it belongs to the list, not to an entry.
24+
rows="$(yq -r '
25+
.spec | (.secrets, .services, .ingresses) | select(. != null)
26+
| (.include, .exclude) | select(. != null) | .[]
27+
| .resourceNames | select(. != null) | .[]
28+
| [(path | .[1] + "." + .[2]), ., (line_comment // "")] | @tsv
29+
' "$f")"
30+
[ -n "$rows" ] || continue
31+
total=$(( total + $(printf '%s\n' "$rows" | grep -c .) ))
32+
33+
bad="$(printf '%s\n' "$rows" | awk -F '\t' -v needle="${prefix}{{ .name }}" -v file="${f#"$REPO_ROOT"/}" '
34+
$3 ~ /cozy-lint:ignore rd-release-prefix/ {
35+
if ($3 !~ /cozy-lint:ignore rd-release-prefix -- [^ ]/) print file ": " $1 ": " $2 " (exempted without a reason)"
36+
next
37+
}
38+
index($2, needle) == 0 { print file ": " $1 ": " $2 }
39+
')"
40+
[ -z "$bad" ] || violations="$violations$bad
41+
"
42+
done
43+
44+
# A glob that matched nothing, or a yq that stopped returning names, would
45+
# otherwise pass silently.
46+
[ "$total" -ge 1 ] || { echo "inspected zero selectors; this test is broken" >&2; exit 1; }
47+
48+
if [ -n "$violations" ]; then
49+
echo "resourceNames selectors that can never match the object their chart creates:" >&2
50+
printf '%s' "$violations" >&2
51+
echo "Fix: spell the release prefix out, e.g. \"harbor-{{ .name }}-credentials\"." >&2
52+
echo "A name deliberately not derived from the release takes a trailing comment on its entry:" >&2
53+
echo " # cozy-lint:ignore rd-release-prefix -- <reason>" >&2
54+
exit 1
55+
fi
56+
}

‎packages/system/harbor-rd/cozyrds/harbor.yaml‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)