fix(backups): re-render the default backup objects when the S3 endpoint changes

The S3 endpoint the platform backups use is copied twice and neither
copy is refreshed. The COSI sidecar writes BucketInfo once per
BucketAccess, so the credentials Secret rendered from it keeps its
endpoint, and the Velero BSL and the default Strategy CRs keep whatever
endpoint the last render of backupstrategy-controller saw. The default
objects gate only acted on objects that were missing, so after a
publishing.host change every backup kept going to the old host with
nothing reporting it.

The gate now also forces a render when a copy is stale: the bucket's
<bucket>-system release when the credentials Secret's endpoint differs
from the COSI Secret it is rendered from, and backupstrategy-controller
when the endpoint an object was rendered with differs from the
credentials Secret's. That endpoint sits at a different path in every
kind, in some only as a bare host, so the chart stamps the rendered
value on each object as backups.cozystack.io/endpoint and the gate
compares that. Objects rendered before the annotation existed count as
stale until one forced render has gone through, which stamps it.

The COSI Secret itself still holds the endpoint the BucketAccess was
granted with; it follows a host change only once the BucketAccess is
re-granted.

Assisted-by: LLM
Signed-off-by: Alexey Artamonov <aleksei.artamonov@aenix.io>
(cherry picked from commit cd91138f33)
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
Alexey Artamonov authored and Myasnikov Daniil committed 2026-11-10 12:40:53 +00:00
1 parent a14ad50b1e
commit e8fef61fa1
21 files changed
+678 -36

No files matched your search

+36
View File
@@ -133,3 +133,39 @@ $tpl: $obj does not gate on crdEstablished for $crd"
rm -rf "$tmp"
}
# The controller's DefaultObjectsGate tells an object rendered with a stale S3
# endpoint (publishing.host changed after the render) by the
# backups.cozystack.io/endpoint annotation, because the endpoint itself sits at
# a different path in every kind. An object the chart renders without it is
# forced once and then never compared again, so a new template that forgets it
# would silently keep a stale endpoint.
@test "every rendered Strategy CR and the Velero BSL carry the rendered endpoint annotation" {
tmp=$(mktemp -d)
helm template t "$CHART" -n cozy-backup-controller \
--set backupStorage.bucketNameOverride=ext-bucket \
--set backupStorage.endpoint=https://s3.example.org \
--output-dir "$tmp/open" >/dev/null
objs=$(find "$tmp/open" -name '*.yaml' | sort | while read -r f; do
yq eval-all "select((.apiVersion // \"\" | test(\"^${STRATEGY_API}\")) or .kind == \"BackupStorageLocation\") | .kind + \"/\" + .metadata.name + \" \" + (.metadata.annotations[\"backups.cozystack.io/endpoint\"] // \"<none>\")" "$f" \
| sed "s#^#$(basename "$f") #"
done)
if ! echo "$objs" | grep -q " BackupStorageLocation/"; then
echo "render produced no BSL; nothing was checked for it" >&2
false
fi
if ! echo "$objs" | grep -q " CNPG/"; then
echo "render produced no Strategy CR; nothing was checked" >&2
false
fi
bad=$(echo "$objs" | awk '$3 != "https://s3.example.org"')
if [ -n "$bad" ]; then
echo "objects without the rendered endpoint in backups.cozystack.io/endpoint:" >&2
echo "$bad" >&2
false
fi
rm -rf "$tmp"
}