Skip to content

Commit fe3ecda

Browse files
feat(platform): migration 40 backfills no-delete label on cozystack-version
Address review feedback from coderabbitai on packages/core/platform/templates/cozystack-version.yaml:10: existing clusters skipped the label because the template's `lookup`+`if not $configMap` guard never re-renders the ConfigMap on upgrade (the skip is intentional — it prevents helm from clobbering the data.version that the migration controller writes from its pre-upgrade hook). A one-shot migration is the correct mechanism here: - Migration 40 in packages/core/platform/images/migrations/migrations/40 runs `kubectl label --overwrite configmap cozystack-version platform.cozystack.io/no-delete=true` and stamps version=41. - Bump migrations.targetVersion 40 -> 41 so the hook fires on the next platform upgrade. Idempotent: --overwrite is a no-op when the label is already at the target value, MIGRATION_DRY_RUN=1 prints without applying, and the script aborts before stamping if the kubectl label call fails. Assisted-By: Claude <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent c8ff3cc commit fe3ecda

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
# Migration 40 --> 41
3+
# Backfill the platform.cozystack.io/no-delete=true label on the
4+
# cozystack-version ConfigMap so the deletion-protection
5+
# ValidatingAdmissionPolicy guards it on upgraded clusters.
6+
#
7+
# On first install the chart template renders the ConfigMap with the
8+
# label inline. On upgrades the template skips re-rendering (lookup-if-not
9+
# preserves migration-managed data.version), so the label needs an
10+
# explicit one-shot backfill here.
11+
#
12+
# Idempotent: kubectl label --overwrite is a no-op when the label is
13+
# already at the target value.
14+
15+
set -euo pipefail
16+
17+
NAMESPACE="${NAMESPACE:-cozy-system}"
18+
DRY_RUN="${MIGRATION_DRY_RUN:-0}"
19+
20+
if [ "$DRY_RUN" = "1" ]; then
21+
echo "[dry-run] would label configmap $NAMESPACE/cozystack-version with platform.cozystack.io/no-delete=true"
22+
echo "Dry-run complete; version stamp not advanced"
23+
exit 0
24+
fi
25+
26+
kubectl label --namespace "$NAMESPACE" --overwrite configmap cozystack-version \
27+
platform.cozystack.io/no-delete=true
28+
echo "Labeled configmap $NAMESPACE/cozystack-version"
29+
30+
kubectl create configmap --namespace "$NAMESPACE" cozystack-version \
31+
--from-literal=version=41 --dry-run=client --output yaml \
32+
| kubectl apply --filename -

‎packages/core/platform/values.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sourceRef:
66
migrations:
77
enabled: false
88
image: ghcr.io/cozystack/cozystack/platform-migrations:v1.4.0-rc.1@sha256:17390197a9b11d76a8dd1b24c6d1512adb7d3226b28b5bcba8551b14b1ec4be0
9-
targetVersion: 40
9+
targetVersion: 41
1010
# Bundle deployment configuration
1111
bundles:
1212
system:

0 commit comments

Comments
 (0)