Skip to content

Commit 7190f3d

Browse files
committed
feat(platform): block the platform upgrade while a Kafka lacks KRaft
Only the isp-* variants run the platform migration hook, so on the default variant nothing checked the Kafka clusters before the new kafka-operator chart arrived. helm-controller replaces that chart's CRDs before Helm runs its pre-upgrade hooks, so a guard in the operator chart would come too late. The platform chart now refuses to render the cozystack-packages source while Strimzi still serves v1beta2 and any Kafka lacks KRaft evidence, with the same evidence rule as migration 61. The check stops once only the v1 API is served, so a NotReady tenant Kafka cannot block platform reconciles after the upgrade. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 9866a04 commit 7190f3d

3 files changed

Lines changed: 404 additions & 0 deletions

File tree

‎packages/core/platform/templates/_helpers.tpl‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,71 @@ sliced into /24s ever allowed.
285285
{{- define "cozystack.platform.ciliumPoolRange" -}}
286286
{{- join ".." (splitList " " (include "cozystack.platform.ciliumPoolBounds" .)) -}}
287287
{{- end }}
288+
289+
{{- /*
290+
Refuse to move cozystack-packages while Strimzi still serves v1beta2 and any
291+
Kafka lacks KRaft evidence. Strimzi 1.2 runs no ZooKeeper, and helm-controller
292+
replaces the kafka-operator CRDs before Helm runs that chart's pre-upgrade
293+
hooks, so this render is the last point before the new operator arrives on a
294+
variant without the migration hook. Once only v1 is served the guard is off:
295+
a NotReady tenant Kafka must not block every platform reconcile.
296+
Do not also refuse while storedVersions still lists v1beta2: on isp-*
297+
variants migration 61 moves storage to v1 inside this same upgrade, and on
298+
the default variant helm-controller already stops at the CRD replacement,
299+
recoverably, until /migrations/61 is run by hand.
300+
301+
The evidence matches migration 61: no ZooKeeper section, a KRaft state or
302+
none, a metadata version and Ready=True. The state alone is not enough
303+
because the v1 conversion deletes it, and Ready is required because Strimzi
304+
keeps the previous metadata version on a failed reconcile.
305+
*/ -}}
306+
{{- define "cozystack.platform.kafkaKRaftGuard" -}}
307+
{{- $crd := lookup "apiextensions.k8s.io/v1" "CustomResourceDefinition" "" "kafkas.kafka.strimzi.io" -}}
308+
{{- if $crd -}}
309+
{{- $served := list -}}
310+
{{- range (dig "spec" "versions" list $crd) -}}
311+
{{- if and (kindIs "map" .) .served -}}
312+
{{- $served = append $served .name -}}
313+
{{- end -}}
314+
{{- end -}}
315+
{{- if has "v1beta2" $served -}}
316+
{{- $kafkas := lookup "kafka.strimzi.io/v1beta2" "Kafka" "" "" -}}
317+
{{- if not (and (kindIs "map" $kafkas) (kindIs "slice" (get $kafkas "items"))) -}}
318+
{{- fail "Cannot read the Strimzi Kafka list; refusing to upgrade the platform without checking every Kafka for KRaft" -}}
319+
{{- end -}}
320+
{{- $unproven := list -}}
321+
{{- range (get $kafkas "items") -}}
322+
{{- $meta := dig "metadata" dict . -}}
323+
{{- $id := printf "%v/%v" (get $meta "namespace") (get $meta "name") -}}
324+
{{- $release := dig "annotations" "meta.helm.sh/release-name" "" $meta -}}
325+
{{- if $release -}}
326+
{{- $id = printf "%s (Helm release: %v/%v)" $id (get $meta "namespace") $release -}}
327+
{{- end -}}
328+
{{- $status := get . "status" -}}
329+
{{- $kraft := false -}}
330+
{{- if and (kindIs "map" $status) (not (dig "spec" "zookeeper" nil .)) -}}
331+
{{- $state := get $status "kafkaMetadataState" -}}
332+
{{- if or (not (hasKey $status "kafkaMetadataState")) (kindIs "invalid" $state) (and (kindIs "string" $state) (eq $state "KRaft")) -}}
333+
{{- $version := get $status "kafkaMetadataVersion" -}}
334+
{{- $ready := false -}}
335+
{{- $conditions := get $status "conditions" -}}
336+
{{- range (kindIs "slice" $conditions | ternary $conditions list) -}}
337+
{{- if and (kindIs "map" .) (eq (printf "%v" .type) "Ready") (eq (printf "%v" .status) "True") -}}
338+
{{- $ready = true -}}
339+
{{- end -}}
340+
{{- end -}}
341+
{{- $kraft = and (kindIs "string" $version) (ne $version "") $ready -}}
342+
{{- end -}}
343+
{{- end -}}
344+
{{- if not $kraft -}}
345+
{{- $unproven = append $unproven $id -}}
346+
{{- end -}}
347+
{{- end -}}
348+
{{- if $unproven -}}
349+
{{- fail (printf "KRaft is not confirmed for these Kafka clusters: %s. Strimzi 1.x cannot run ZooKeeper or an unfinished migration. Upgrade through Cozystack v1.7 and wait for each Kafka to finish its KRaft migration and report Ready. On platform variants without the migration hook, run /migrations/61 from this release's platform-migrations image before upgrading." (join ", " $unproven)) -}}
350+
{{- end -}}
351+
{{- else if not (has "v1" $served) -}}
352+
{{- fail (printf "kafkas.kafka.strimzi.io serves neither v1beta2 nor v1 (served: %v); refusing to upgrade the platform without checking Kafka for KRaft" $served) -}}
353+
{{- end -}}
354+
{{- end -}}
355+
{{- end }}

‎packages/core/platform/templates/repository.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- include "cozystack.platform.kafkaKRaftGuard" . }}
12
{{- $sourceRef := .Values.sourceRef }}
23
{{- $apiVersion := "source.toolkit.fluxcd.io/v1" }}
34
{{- $kind := $sourceRef.kind }}

0 commit comments

Comments
 (0)