Skip to content

Commit b17c43b

Browse files
committed
fix(clickhouse): guard migration when keeper CRD absent and quote hook scalars
Address CodeRabbit review on #3072: - Migration 45 now skips the backfill when the clickhousekeeperinstallations CRD is not installed. The migration runs platform-wide via targetVersion, so on clusters that never deployed ClickHouse the kubectl get would otherwise fail under set -euo pipefail and abort the whole upgrade. - Quote the templated name/label/serviceAccountName scalars in the cleanup hook so the source parses under YAMLlint; rendered output is unchanged. Assisted-By: Claude <[email protected]> Signed-off-by: Алексей Артамонов <[email protected]>
1 parent 6be0d86 commit b17c43b

2 files changed

Lines changed: 28 additions & 19 deletions

File tree

  • packages
    • apps/clickhouse/templates/hooks
    • core/platform/images/migrations/migrations

‎packages/apps/clickhouse/templates/hooks/cleanup-pvc.yaml‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
apiVersion: batch/v1
33
kind: Job
44
metadata:
5-
name: {{ .Release.Name }}-cleanup
5+
name: "{{ .Release.Name }}-cleanup"
66
labels:
7-
app.kubernetes.io/instance: {{ .Release.Name }}
7+
app.kubernetes.io/instance: "{{ .Release.Name }}"
88
annotations:
99
"helm.sh/hook": post-delete
1010
"helm.sh/hook-weight": "10"
@@ -13,10 +13,10 @@ spec:
1313
template:
1414
metadata:
1515
labels:
16-
app.kubernetes.io/instance: {{ .Release.Name }}
16+
app.kubernetes.io/instance: "{{ .Release.Name }}"
1717
policy.cozystack.io/allow-to-apiserver: "true"
1818
spec:
19-
serviceAccountName: {{ .Release.Name }}-cleanup
19+
serviceAccountName: "{{ .Release.Name }}-cleanup"
2020
restartPolicy: Never
2121
securityContext:
2222
runAsNonRoot: true
@@ -63,9 +63,9 @@ spec:
6363
apiVersion: v1
6464
kind: ServiceAccount
6565
metadata:
66-
name: {{ .Release.Name }}-cleanup
66+
name: "{{ .Release.Name }}-cleanup"
6767
labels:
68-
app.kubernetes.io/instance: {{ .Release.Name }}
68+
app.kubernetes.io/instance: "{{ .Release.Name }}"
6969
annotations:
7070
"helm.sh/hook": post-delete
7171
"helm.sh/hook-weight": "0"
@@ -74,9 +74,9 @@ metadata:
7474
apiVersion: rbac.authorization.k8s.io/v1
7575
kind: Role
7676
metadata:
77-
name: {{ .Release.Name }}-cleanup
77+
name: "{{ .Release.Name }}-cleanup"
7878
labels:
79-
app.kubernetes.io/instance: {{ .Release.Name }}
79+
app.kubernetes.io/instance: "{{ .Release.Name }}"
8080
annotations:
8181
"helm.sh/hook": post-delete
8282
"helm.sh/hook-weight": "5"
@@ -89,17 +89,17 @@ rules:
8989
apiVersion: rbac.authorization.k8s.io/v1
9090
kind: RoleBinding
9191
metadata:
92-
name: {{ .Release.Name }}-cleanup
92+
name: "{{ .Release.Name }}-cleanup"
9393
labels:
94-
app.kubernetes.io/instance: {{ .Release.Name }}
94+
app.kubernetes.io/instance: "{{ .Release.Name }}"
9595
annotations:
9696
"helm.sh/hook": post-delete
9797
"helm.sh/hook-weight": "5"
9898
"helm.sh/hook-delete-policy": before-hook-creation
9999
roleRef:
100100
apiGroup: rbac.authorization.k8s.io
101101
kind: Role
102-
name: {{ .Release.Name }}-cleanup
102+
name: "{{ .Release.Name }}-cleanup"
103103
subjects:
104104
- kind: ServiceAccount
105-
name: {{ .Release.Name }}-cleanup
105+
name: "{{ .Release.Name }}-cleanup"

‎packages/core/platform/images/migrations/migrations/45‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,22 @@
1515

1616
set -euo pipefail
1717

18-
# Each ClickHouseKeeperInstallation is named "<release>-keeper"; its PVCs are
19-
# created from the "default" volumeClaimTemplate and named
20-
# "default-chk-<release>-keeper-<cluster>-<shard>-<replica>-<ordinal>".
21-
# No early-close (head) in the pipe: under pipefail a large list would SIGPIPE
22-
# kubectl and abort the migration.
23-
chks=$(kubectl get clickhousekeeperinstallations.clickhouse-keeper.altinity.com -A \
24-
-o jsonpath='{range .items[*]}{.metadata.namespace}{" "}{.metadata.name}{"\n"}{end}')
18+
# This migration runs platform-wide (targetVersion bump), including on clusters
19+
# that never installed ClickHouse. Skip the backfill when the keeper CRD is
20+
# absent — otherwise the kubectl get below would fail under pipefail and abort
21+
# the whole upgrade.
22+
if ! kubectl get crd clickhousekeeperinstallations.clickhouse-keeper.altinity.com >/dev/null 2>&1; then
23+
echo "ClickHouse keeper CRD not present; skipping keeper PVC label backfill"
24+
chks=""
25+
else
26+
# Each ClickHouseKeeperInstallation is named "<release>-keeper"; its PVCs are
27+
# created from the "default" volumeClaimTemplate and named
28+
# "default-chk-<release>-keeper-<cluster>-<shard>-<replica>-<ordinal>".
29+
# No early-close (head) in the pipe: under pipefail a large list would SIGPIPE
30+
# kubectl and abort the migration.
31+
chks=$(kubectl get clickhousekeeperinstallations.clickhouse-keeper.altinity.com -A \
32+
-o jsonpath='{range .items[*]}{.metadata.namespace}{" "}{.metadata.name}{"\n"}{end}')
33+
fi
2534

2635
echo "$chks" | while read -r ns chk; do
2736
[ -n "${ns:-}" ] || continue

0 commit comments

Comments
 (0)