refactor(platform): share the CredentialTemplate CRD apply

The bucket conversion adds fields to the CredentialTemplate CRD, so its
migration has to apply the baked CRD for the same reason migration 64
does: cozystack-controller can upgrade after the tenant charts switch.
Move 64's apply, label, annotate and wait into a lib helper, the way
the version stamp is shared, so both run the identical sequence and a
later fix reaches both.

Assisted-by: LLM
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
This commit is contained in:
Andrei Kvapil committed 2026-12-02 20:38:26 +01:00
1 parent d2bd291a10
commit b089c8bee6
3 files changed
+37 -12

No files matched your search

@@ -55,9 +55,10 @@ RUN mkdir /strimzi-crds && \
https://github.com/strimzi/strimzi-kafka-operator/releases/download/0.51.0/strimzi-crds-0.51.0.yaml && \
echo "a11257e67985a946a6facfb17d729aac5670b89675d410d13162fe455a5ac7a8 /strimzi-crds/strimzi-crds-0.51.0.yaml" | sha256sum -c -
# The CredentialTemplate CRD, which migration 64 applies before the converted
# charts render templates: it ships with cozystack-controller, whose release
# can upgrade after the tenant releases switch charts.
# The CredentialTemplate CRD, which the credentials conversions apply (see
# migrations/lib/credential-crd.sh) before the converted charts render
# templates: it ships with cozystack-controller, whose release can upgrade
# after the tenant releases switch charts.
COPY packages/system/cozystack-controller/definitions/cozystack.io_credentialtemplates.yaml /credential-crds/
COPY packages/core/platform/images/migrations/migrations /migrations
# v1alpha2 etcd CRDs, vendored into the build context by `make image-migrations`.
@@ -48,21 +48,16 @@ set -euo pipefail
# shellcheck source=lib/cozystack-version.sh
. "$(dirname "$0")/lib/cozystack-version.sh"
# shellcheck source=lib/credential-crd.sh
. "$(dirname "$0")/lib/credential-crd.sh"
NAMESPACE="${NAMESPACE:-cozy-system}"
# The converted postgres chart renders CredentialTemplates, whose CRD ships
# with cozystack-controller. That release can upgrade minutes after the tenant
# releases switch charts, and every render in between fails on the unknown
# kind, so apply the CRD baked into this image first, owned by the
# cozystack-controller release as its later upgrade expects to find it.
CRD_FILE="${CREDENTIAL_CRD_FILE:-/credential-crds/cozystack.io_credentialtemplates.yaml}"
kubectl apply --server-side --force-conflicts --filename "$CRD_FILE"
kubectl label crd credentialtemplates.cozystack.io app.kubernetes.io/managed-by=Helm --overwrite
kubectl annotate crd credentialtemplates.cozystack.io \
meta.helm.sh/release-name=cozystack-controller \
meta.helm.sh/release-namespace=cozy-system --overwrite
kubectl wait --for=condition=established crd/credentialtemplates.cozystack.io --timeout=60s
# kind, so apply the CRD baked into this image first.
apply_credential_crd
credentials-migrate seed \
--migration 64 \
@@ -0,0 +1,29 @@
# shellcheck shell=sh
# Shared helper for applying the CredentialTemplate CRD during migrations.
#
# The CRD ships with cozystack-controller, whose release can upgrade minutes
# after the tenant releases switch charts. A converted chart that renders a
# CredentialTemplate, or a field the installed CRD does not have yet, fails
# (or has the field pruned) in between, so a conversion that needs the CRD
# applies the copy baked into the migrations image before any chart
# switches. It is labelled and annotated as owned by the cozystack-controller
# release, as that release's later upgrade expects to find it.
#
# Sourced, not executed. A migration that needs it does:
# . "$(dirname "$0")/lib/credential-crd.sh"
# apply_credential_crd
# apply_credential_crd
# Server-side apply the baked CRD, hand it to the cozystack-controller Helm
# release, and wait until it is established. $CREDENTIAL_CRD_FILE overrides
# the path, for the tests. Every step fails the migration on error, under the
# caller's set -e.
apply_credential_crd() {
_crd_file="${CREDENTIAL_CRD_FILE:-/credential-crds/cozystack.io_credentialtemplates.yaml}"
kubectl apply --server-side --force-conflicts --filename "$_crd_file"
kubectl label crd credentialtemplates.cozystack.io app.kubernetes.io/managed-by=Helm --overwrite
kubectl annotate crd credentialtemplates.cozystack.io \
meta.helm.sh/release-name=cozystack-controller \
meta.helm.sh/release-namespace=cozy-system --overwrite
kubectl wait --for=condition=established crd/credentialtemplates.cozystack.io --timeout=60s
}