Skip to content

Commit 572e08a

Browse files
fix(platform): migration 42 uses a single declarative apply
Address review feedback from @lllamnyp on packages/core/platform/images/ migrations/migrations/42: the previous version did `kubectl label --overwrite` then `kubectl apply` on a manifest with no labels, relying on `kubectl apply`'s 3-way strategic merge to leave the imperatively-set label intact. That works in the steady state but is fragile — the contract is "the label is preserved because it is never in last-applied-configuration" — and it is inconsistent with the helm template at templates/cozystack-version.yaml, which bakes the label inline. Replace the two-step dance with one declarative apply that includes the deletion-protection label, matching the chart template. One source of truth, no last-applied-merge subtlety. The script remains idempotent (apply is a no-op once the ConfigMap matches). Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
1 parent 84c2aaa commit 572e08a

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

  • packages/core/platform/images/migrations/migrations

packages/core/platform/images/migrations/migrations/42

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,34 @@
99
# preserves migration-managed data.version), so the label needs an
1010
# explicit one-shot backfill here.
1111
#
12-
# Idempotent: kubectl label --overwrite is a no-op when the label is
13-
# already at the target value.
12+
# Idempotent: kubectl apply re-runs are a no-op once the ConfigMap matches
13+
# the declared shape. One source of truth — same label set the chart bakes
14+
# in at install time, no 3-way-merge subtlety.
1415

1516
set -euo pipefail
1617

1718
NAMESPACE="${NAMESPACE:-cozy-system}"
1819
DRY_RUN="${MIGRATION_DRY_RUN:-0}"
1920

21+
MANIFEST=$(cat <<EOF
22+
apiVersion: v1
23+
kind: ConfigMap
24+
metadata:
25+
name: cozystack-version
26+
namespace: ${NAMESPACE}
27+
labels:
28+
platform.cozystack.io/no-delete: "true"
29+
data:
30+
version: "43"
31+
EOF
32+
)
33+
2034
if [ "$DRY_RUN" = "1" ]; then
21-
echo "[dry-run] would label configmap $NAMESPACE/cozystack-version with platform.cozystack.io/no-delete=true"
35+
echo "[dry-run] would apply:"
36+
printf '%s\n' "$MANIFEST"
2237
echo "Dry-run complete; version stamp not advanced"
2338
exit 0
2439
fi
2540

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=43 --dry-run=client --output yaml \
32-
| kubectl apply --filename -
41+
printf '%s\n' "$MANIFEST" | kubectl apply --filename -
42+
echo "Applied configmap $NAMESPACE/cozystack-version with deletion-protection label"

0 commit comments

Comments
 (0)