Skip to content

Commit efb6de0

Browse files
committed
fix(nightly): rewrite an image host that is the whole scalar value
The nightly host rewrite is a literal "<src-registry>/" substring replace, so it only reaches a host sitting contiguously in front of the repository. kubeovn keeps its host in global.registry.address with the bare repository in a sibling key: no trailing slash, no match. The image was mirrored to the public registry and the tree kept pointing at the private build registry. The gap was dormant while kubeovn's image came from a separate repository, because the baked ref carried the public host and the ownership filter skipped it. Building the image in-tree stamps the build-registry host into that key and turns it live, so fix it here. Add an end-of-line-anchored expression that fires only when the source registry is the complete value; a contiguous ref continues past the host, so the two expressions cannot both fire on one reference. keycloak-operator splits at a different boundary and stays unfixed -- neither of its keys holds the source registry as a whole. Documented, and dormant while no CI path rebuilds it. Assisted-By: Claude Signed-off-by: Andrei Kvapil <[email protected]>
1 parent 4b82a5e commit efb6de0

3 files changed

Lines changed: 72 additions & 7 deletions

File tree

‎docs/agents/image-refs.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ If a package stamps a reference somewhere the two globs do not cover, add that f
6565

6666
These are real, currently unfixed, and predate the shared enumeration. They are recorded here so nobody rediscovers them as surprises.
6767

68-
**The nightly host rewrite cannot reach a split host.** It is a literal `<src-registry>/` substring replace, so it only rewrites a reference whose host sits contiguously in front of the repository. Two live layouts defeat it: `keycloak-operator` splits the host into a sibling `registry:` key, and `kubeovn` puts it in `global.registry.address` with no trailing slash. Collection understands both shapes — the host is rejoined, so a split-key ref carrying the source-registry host is still selected and mirrored. Today neither package's ref does: keycloak-operator is never rebuilt by any CI path (#3416), and kubeovn's image is built and pushed to the public registry by cozystack/kubeovn-chart, so both baked refs keep the committed public-registry host and the ownership filter skips them — stale, but resolvable. The gap turns live the moment either package flows through a CI build that stamps the build-registry host into those keys: the image would be mirrored, yet the host rewrite would miss it, and the published tree would keep pointing at the private build registry. Fixing it properly means structure-aware rewriting rather than a substring pass. This is a defect in the host dimension; the version dimension the promote rewrite handles is unaffected, because the version always lives in a `tag` key regardless of where the host is.
68+
**The nightly host rewrite cannot reach a host split across two keys.** The primary pass is a literal `<src-registry>/` substring replace, so it only rewrites a reference whose host sits contiguously in front of the repository. Two layouts defeat it, and only one is now handled.
69+
70+
`kubeovn` puts the whole host in `global.registry.address` with the bare repository in a sibling key, so there is no trailing slash to match. This one **is** rewritten now, by a second, end-of-line-anchored expression that fires only when the source registry is the complete scalar value — a contiguous `<src>/<repo>@<digest>` ref continues past the host, so the two expressions can never both fire on one reference. It had to be fixed when kubeovn's image build moved into this repository: until then the image was built and pushed to the public registry by cozystack/kubeovn-chart, the baked ref kept the committed public-registry host, and the ownership filter skipped it. The moment a CI build stamps the build-registry host into that key, the image is mirrored but the host is not rewritten, and the published tree points at the private build registry. Covered by `hack/nightly-mirror_test.bats`.
71+
72+
`keycloak-operator` remains unfixed. It splits at a different boundary — `registry: iad.ocir.io` beside `repository: idyksih5sir9/cozystack/<name>` — so neither key holds the source registry as a whole and no anchored replace can reach it; rewriting it needs a structure-aware pass that knows how the destination host splits. The gap stays dormant because no CI path rebuilds the package (#3416), and turns live the moment one does.
73+
74+
Collection understands both shapes — the host is rejoined, so a split-key ref carrying the source-registry host is still selected and mirrored. This is a defect in the host dimension; the version dimension the promote rewrite handles is unaffected, because the version always lives in a `tag` key regardless of where the host is.
6975

7076
**A reference inside a gzip is invisible.** `capi-providers-cpprovider` stamps its kamaji reference into `files/control-plane-components.yaml` and into the `files/components.gz` built from it, and the chart ships the `.gz`. Nothing enumerates either: declaring only the readable copy would rewrite what nothing consumes and diverge it from what does. Note the promote postcondition cannot catch this class at all — `grep -rIl` skips binary files — so it fails silently rather than loudly. No tag rewrite is owed (kamaji is component-versioned) and the image is still mirrored and retagged via its `.tag` file, so the residual is that a nightly's kamaji ConfigMap keeps the build-registry host. The fix is decompress, rewrite, recompress with `gzip -n` for reproducibility.
7177

‎hack/nightly-mirror.sh‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,26 @@ else
141141
# never pushed to DST_REGISTRY; scanning a file that is not rewritten leaves
142142
# the published tree pointing at the private CI registry. A `find -name
143143
# values.yaml` at any depth would do the former to vendored chart defaults.
144+
# The second expression reaches one shape the first cannot: a host that is the
145+
# *entire* scalar value, with the repository in a sibling key — kubeovn's
146+
# `global.registry.address`, now that its image is built here rather than in
147+
# cozystack/kubeovn-chart. There is no trailing slash for `<src>/` to match, so
148+
# the host survived the rewrite while the image itself was mirrored, publishing
149+
# a tree that points at the private CI registry. Anchoring on end-of-line means
150+
# it only fires when SRC_REGISTRY is the complete value: a contiguous
151+
# `<src>/<repo>@<digest>` ref continues past the host and is left to the first
152+
# expression, so the two cannot both fire on one reference.
153+
#
154+
# It deliberately does NOT fix keycloak-operator, whose host splits at a
155+
# different boundary (`registry: iad.ocir.io` + `repository:
156+
# idyksih5sir9/cozystack/<name>`): neither key holds SRC_REGISTRY as a whole,
157+
# so rewriting it needs the structure-aware pass docs/agents/image-refs.md
158+
# describes. That gap stays dormant while no CI path rebuilds the package.
144159
image_ref_files "$TREE" | while IFS= read -r f; do
145-
sed -i "s|${SRC_ESC}/|${DST_REGISTRY}/|g" "$f"
160+
sed -i \
161+
-e "s|${SRC_ESC}/|${DST_REGISTRY}/|g" \
162+
-e "s|\(:[[:space:]]*[\"']\?\)${SRC_ESC}\([\"']\?\)[[:space:]]*$|\1${DST_REGISTRY}\2|" \
163+
"$f"
146164
done
147165
fi
148166

‎hack/nightly-mirror_test.bats‎

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ _make_tree() {
230230
#
231231
# Scope, so the name does not overclaim: this pins WHICH FILES the rewrite
232232
# visits, not that every ref inside them is successfully rewritten. The sed
233-
# itself only runs outside --dry-run (it needs skopeo) and is a literal
234-
# "<src>/" substring replace, so it still cannot rewrite a host split into a
235-
# sibling `registry:` key (keycloak-operator) or one without a trailing slash
236-
# (kubeovn's global.registry.address). That is a known gap recorded in
237-
# docs/agents/image-refs.md, not something this test covers.
233+
# itself only runs outside --dry-run (it needs skopeo), so it still cannot
234+
# rewrite a host split into a sibling `registry:` key (keycloak-operator).
235+
# That is a known gap recorded in docs/agents/image-refs.md, not something
236+
# this test covers; the whole-value shape (kubeovn) is covered by the
237+
# dedicated test below.
238238
tmp=$(mktemp -d)
239239
trap 'rm -rf "$tmp"' EXIT
240240
_make_tree "$tmp/tree"
@@ -246,3 +246,44 @@ _make_tree() {
246246
echo "$files" | grep -q '/system/tagfile/images/thing.tag$'
247247
echo "$files" | grep -q '/system/multus/templates/multus-daemonset-thick.yml$'
248248
}
249+
250+
@test "the host rewrite reaches a host that is the whole scalar value" {
251+
# kubeovn keeps its host in global.registry.address with the repository in a
252+
# sibling key, so there is no trailing slash for the literal "<src>/" replace
253+
# to match. The image was mirrored, the host was not rewritten, and the
254+
# published tree kept pointing at the private CI registry. Dormant while the
255+
# image was built in cozystack/kubeovn-chart; live once it is built here.
256+
#
257+
# Needs a skopeo stub because the sed only runs outside --dry-run. Scope: this
258+
# covers the whole-value shape only. keycloak-operator splits the host at a
259+
# different boundary (`registry: iad.ocir.io`), where no single key holds
260+
# SRC_REGISTRY, and is still unfixed — see docs/agents/image-refs.md.
261+
tmp=$(mktemp -d)
262+
trap 'rm -rf "$tmp"' EXIT
263+
_make_tree "$tmp/tree"
264+
265+
# The stub must answer `inspect` with the source digest: the script verifies
266+
# every dest tag resolves to it and aborts before the rewrite otherwise.
267+
mkdir -p "$tmp/bin"
268+
{
269+
echo '#!/bin/sh'
270+
echo 'case "$1" in'
271+
printf ' inspect) echo "sha256:%s" ;;\n' "$D"
272+
echo ' *) exit 0 ;;'
273+
echo 'esac'
274+
} > "$tmp/bin/skopeo"
275+
chmod +x "$tmp/bin/skopeo"
276+
277+
PATH="$tmp/bin:$PATH" hack/nightly-mirror.sh 0.0.0-nightly.test "$tmp/tree"
278+
279+
# the whole-value host is rewritten, and the repository beside it is untouched
280+
grep -q '^ address: ghcr.io/cozystack/cozystack$' "$tmp/tree/system/globalreg/values.yaml"
281+
grep -q '^ repository: globalreg$' "$tmp/tree/system/globalreg/values.yaml"
282+
! grep -q 'iad.ocir.io' "$tmp/tree/system/globalreg/values.yaml"
283+
284+
# a contiguous ref is still rewritten exactly once, not double-prefixed
285+
grep -q '^image: ghcr.io/cozystack/cozystack/foo:main@sha256:' "$tmp/tree/system/foo/values.yaml"
286+
287+
# third-party hosts are left alone
288+
grep -q 'docker.io/clastix/kubectl' "$tmp/tree/system/third/values.yaml"
289+
}

0 commit comments

Comments
 (0)