Skip to content

Commit b199b5e

Browse files
committed
refactor(platform): stamp cozystack-version via shared helper in migrations
Migrations 42, 43 and 44 each carried a copy-pasted heredoc that applied the labeled cozystack-version ConfigMap. Source the shared helper and call it instead, so the labeled manifest has a single definition and future migrations cannot reintroduce a label-less apply. Behavior-preserving: the rendered manifest is byte-identical to the previous heredocs. Migration 42 keeps its MIGRATION_DRY_RUN path, now building its manifest from the helper's pure renderer. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 50344f1 commit b199b5e

3 files changed

Lines changed: 20 additions & 53 deletions

File tree

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

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,20 @@
1414
# the next chart-driven apply sees no diff.
1515
#
1616
# 3-way-merge note: this apply records the no-delete label in the kubectl
17-
# last-applied-configuration annotation under the default field manager.
18-
# Any future migration that re-stamps cozystack-version via the same field
19-
# manager MUST include the label inline (matching the chart template at
20-
# templates/cozystack-version.yaml) — a label-less apply by the same field
21-
# manager would strip it.
17+
# last-applied-configuration annotation under the default field manager. A
18+
# label-less apply by the same field manager would strip it, so the manifest
19+
# is rendered by the shared helper (lib/cozystack-version.sh) that every
20+
# migration sources rather than a hand-copied heredoc.
2221

2322
set -euo pipefail
2423

24+
# shellcheck source=lib/cozystack-version.sh
25+
. "$(dirname "$0")/lib/cozystack-version.sh"
26+
2527
NAMESPACE="${NAMESPACE:-cozy-system}"
2628
DRY_RUN="${MIGRATION_DRY_RUN:-0}"
2729

28-
MANIFEST=$(cat <<EOF
29-
apiVersion: v1
30-
kind: ConfigMap
31-
metadata:
32-
name: cozystack-version
33-
namespace: ${NAMESPACE}
34-
labels:
35-
platform.cozystack.io/no-delete: "true"
36-
data:
37-
version: "43"
38-
EOF
39-
)
30+
MANIFEST=$(render_cozystack_version_manifest 43)
4031

4132
if [ "$DRY_RUN" = "1" ]; then
4233
echo "[dry-run] would apply:"

‎packages/core/platform/images/migrations/migrations/43‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
set -euo pipefail
1414

15+
# shellcheck source=lib/cozystack-version.sh
16+
. "$(dirname "$0")/lib/cozystack-version.sh"
17+
1518
# Iterate every namespace that has a Cluster named "seaweedfs-db".
1619
for ns in $(kubectl get cluster.postgresql.cnpg.io -A \
1720
-o jsonpath='{range .items[?(@.metadata.name=="seaweedfs-db")]}{.metadata.namespace}{"\n"}{end}'); do
@@ -27,21 +30,6 @@ for ns in $(kubectl get cluster.postgresql.cnpg.io -A \
2730
fi
2831
done
2932

30-
# Stamp version.
31-
# Mirror migration 42's labeled manifest. A label-less apply by the same field
32-
# manager (kubectl create | kubectl apply) would strip the
33-
# platform.cozystack.io/no-delete label migration 42 added, dropping
34-
# cozystack-version out of the cozystack-no-delete-guardrail
35-
# ValidatingAdmissionPolicy. templates/cozystack-version.yaml only re-renders the
36-
# labeled ConfigMap on first install, so the label must be carried inline here.
37-
kubectl apply --filename - <<EOF
38-
apiVersion: v1
39-
kind: ConfigMap
40-
metadata:
41-
name: cozystack-version
42-
namespace: cozy-system
43-
labels:
44-
platform.cozystack.io/no-delete: "true"
45-
data:
46-
version: "44"
47-
EOF
33+
# Stamp version. The labeled manifest lives in the shared helper so it cannot
34+
# drift back to a label-less apply that strips platform.cozystack.io/no-delete.
35+
stamp_cozystack_version 44

‎packages/core/platform/images/migrations/migrations/44‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
set -euo pipefail
1212

13+
# shellcheck source=lib/cozystack-version.sh
14+
. "$(dirname "$0")/lib/cozystack-version.sh"
15+
1316
if kubectl get deployment flux-tenants -n cozy-fluxcd >/dev/null 2>&1; then
1417
# No early-close (head) in the pipe: under pipefail a large name list would
1518
# SIGPIPE kubectl and abort the migration.
@@ -23,21 +26,6 @@ if kubectl get deployment flux-tenants -n cozy-fluxcd >/dev/null 2>&1; then
2326
fi
2427
fi
2528

26-
# Stamp version.
27-
# Mirror migration 43's labeled manifest. A label-less apply by the same field
28-
# manager would strip the platform.cozystack.io/no-delete label, dropping
29-
# cozystack-version out of the cozystack-no-delete-guardrail
30-
# ValidatingAdmissionPolicy. templates/cozystack-version.yaml only re-renders
31-
# the labeled ConfigMap on first install, so the label must be carried inline
32-
# here.
33-
kubectl apply --filename - <<EOF
34-
apiVersion: v1
35-
kind: ConfigMap
36-
metadata:
37-
name: cozystack-version
38-
namespace: cozy-system
39-
labels:
40-
platform.cozystack.io/no-delete: "true"
41-
data:
42-
version: "45"
43-
EOF
29+
# Stamp version. The labeled manifest lives in the shared helper so it cannot
30+
# drift back to a label-less apply that strips platform.cozystack.io/no-delete.
31+
stamp_cozystack_version 45

0 commit comments

Comments
 (0)