diff --git a/packages/core/platform/images/migrations/Dockerfile b/packages/core/platform/images/migrations/Dockerfile index f3a745841..232b4f5e9 100644 --- a/packages/core/platform/images/migrations/Dockerfile +++ b/packages/core/platform/images/migrations/Dockerfile @@ -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`. diff --git a/packages/core/platform/images/migrations/migrations/64 b/packages/core/platform/images/migrations/migrations/64 index 8b5ecf80e..ea37d1c9d 100755 --- a/packages/core/platform/images/migrations/migrations/64 +++ b/packages/core/platform/images/migrations/migrations/64 @@ -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 \ diff --git a/packages/core/platform/images/migrations/migrations/lib/credential-crd.sh b/packages/core/platform/images/migrations/migrations/lib/credential-crd.sh new file mode 100644 index 000000000..7d4a16ef5 --- /dev/null +++ b/packages/core/platform/images/migrations/migrations/lib/credential-crd.sh @@ -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 +}