mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
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. Without the migration hook the chart also refuses while any Strimzi CRD still stores v1beta2: the API server would reject the v1-only CRDs of Strimzi 1.2, and the new kafka chart rejects the Kafka 3.x versions that the migration moves. With the hook the check would block the migration that narrows the stored versions in the same upgrade. While v1beta2 is served the chart also refuses while a Kafka application sets a topic config Kafka 4 removed or a segment.bytes below the 1 MiB minimum of Kafka 4. The new kafka chart refuses to render such a topic, which would leave that application on its pre-upgrade spec, and a Kafka 4 broker whose log holds the small segment.bytes does not start. segment.bytes is read the way Kafka reads it: trimmed, with an optional sign, leading zeros decimal. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <f@lex.la>
This commit is contained in:
3 files changed
+782
No files matched your search
@@ -285,3 +285,148 @@ sliced into /24s ever allowed.
|
||||
{{- define "cozystack.platform.ciliumPoolRange" -}}
|
||||
{{- join ".." (splitList " " (include "cozystack.platform.ciliumPoolBounds" .)) -}}
|
||||
{{- end }}
|
||||
|
||||
{{- /*
|
||||
Refuse to move cozystack-packages while Strimzi still serves v1beta2 and any
|
||||
Kafka lacks KRaft evidence. Strimzi 1.2 runs no ZooKeeper, and helm-controller
|
||||
replaces the kafka-operator CRDs before Helm runs that chart's pre-upgrade
|
||||
hooks, so this render is the last point before the new operator arrives on a
|
||||
variant without the migration hook. Once only v1 is served the guard is off:
|
||||
a NotReady tenant Kafka must not block every platform reconcile.
|
||||
Without the migration hook, also refuse while any Strimzi CRD still stores a
|
||||
version other than v1: the API server rejects the v1-only CRDs then, and
|
||||
the new kafka chart rejects the Kafka 3.x values migration 61 rewrites.
|
||||
With the hook, migration 61 narrows the stored versions inside this same
|
||||
upgrade, after this render, so the check would block its own fix.
|
||||
|
||||
The evidence matches migration 61: no ZooKeeper section, a metadata version,
|
||||
and either the KRaft state, which Strimzi never leaves, or, once the v1
|
||||
conversion has deleted that state, Ready=True or the annotation migration 61
|
||||
records on every Kafka it accepts. Without the state Ready is required
|
||||
because Strimzi keeps the previous metadata version on a failed reconcile.
|
||||
*/ -}}
|
||||
{{- define "cozystack.platform.kafkaKRaftGuard" -}}
|
||||
{{- if not .Values.migrations.enabled -}}
|
||||
{{- /* STRIMZI_CRDS of migration 61. */ -}}
|
||||
{{- range $name := list "kafkas.kafka.strimzi.io" "kafkanodepools.kafka.strimzi.io" "kafkaconnects.kafka.strimzi.io" "kafkaconnectors.kafka.strimzi.io" "kafkabridges.kafka.strimzi.io" "kafkamirrormaker2s.kafka.strimzi.io" "kafkarebalances.kafka.strimzi.io" "kafkatopics.kafka.strimzi.io" "kafkausers.kafka.strimzi.io" "strimzipodsets.core.strimzi.io" -}}
|
||||
{{- range (dig "status" "storedVersions" list (lookup "apiextensions.k8s.io/v1" "CustomResourceDefinition" "" $name)) -}}
|
||||
{{- if ne (printf "%v" .) "v1" -}}
|
||||
{{- fail (printf "Strimzi still stores %v for %s, and the Strimzi 1.2 CRDs drop it. This platform variant runs no migration hook: run /migrations/61 from this release's platform-migrations image with cluster-admin credentials before upgrading." . $name) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $crd := lookup "apiextensions.k8s.io/v1" "CustomResourceDefinition" "" "kafkas.kafka.strimzi.io" -}}
|
||||
{{- if $crd -}}
|
||||
{{- $served := list -}}
|
||||
{{- range (dig "spec" "versions" list $crd) -}}
|
||||
{{- if and (kindIs "map" .) .served -}}
|
||||
{{- $served = append $served .name -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if has "v1beta2" $served -}}
|
||||
{{- $kafkas := lookup "kafka.strimzi.io/v1beta2" "Kafka" "" "" -}}
|
||||
{{- if not (and (kindIs "map" $kafkas) (kindIs "slice" (get $kafkas "items"))) -}}
|
||||
{{- fail "Cannot read the Strimzi Kafka list; refusing to upgrade the platform without checking every Kafka for KRaft" -}}
|
||||
{{- end -}}
|
||||
{{- $unproven := list -}}
|
||||
{{- range (get $kafkas "items") -}}
|
||||
{{- $meta := dig "metadata" dict . -}}
|
||||
{{- $id := printf "%v/%v" (get $meta "namespace") (get $meta "name") -}}
|
||||
{{- $release := dig "annotations" "meta.helm.sh/release-name" "" $meta -}}
|
||||
{{- if $release -}}
|
||||
{{- $id = printf "%s (Helm release: %v/%v)" $id (get $meta "namespace") $release -}}
|
||||
{{- end -}}
|
||||
{{- $status := get . "status" -}}
|
||||
{{- $reason := "" -}}
|
||||
{{- if dig "spec" "zookeeper" nil . -}}
|
||||
{{- $reason = "ZooKeeper section in spec" -}}
|
||||
{{- else if not (kindIs "map" $status) -}}
|
||||
{{- $reason = "no status" -}}
|
||||
{{- else -}}
|
||||
{{- $state := get $status "kafkaMetadataState" -}}
|
||||
{{- $hasState := and (hasKey $status "kafkaMetadataState") (not (kindIs "invalid" $state)) -}}
|
||||
{{- $version := get $status "kafkaMetadataVersion" -}}
|
||||
{{- if and $hasState (not (and (kindIs "string" $state) (eq $state "KRaft"))) -}}
|
||||
{{- $reason = printf "metadata state %v" $state -}}
|
||||
{{- else if not (and (kindIs "string" $version) (ne $version "")) -}}
|
||||
{{- $reason = "no kafkaMetadataVersion" -}}
|
||||
{{- else if not $hasState -}}
|
||||
{{- $ready := false -}}
|
||||
{{- $conditions := get $status "conditions" -}}
|
||||
{{- range (kindIs "slice" $conditions | ternary $conditions list) -}}
|
||||
{{- if and (kindIs "map" .) (eq (printf "%v" .type) "Ready") (eq (printf "%v" .status) "True") -}}
|
||||
{{- $ready = true -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $verified := dig "annotations" "cozystack.io/kraft-verified" "" $meta -}}
|
||||
{{- if not (or $ready (and (kindIs "string" $verified) (ne $verified ""))) -}}
|
||||
{{- $reason = "not Ready" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if $reason -}}
|
||||
{{- $unproven = append $unproven (printf "%s: %s" $id $reason) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if $unproven -}}
|
||||
{{- 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 let each Kafka finish its KRaft migration and report Ready. A Kafka created after migration 61 stopped the Strimzi operators has no status until the upgrade finishes: delete that application and create it again afterwards. On platform variants without the migration hook, run /migrations/61 from this release's platform-migrations image before upgrading." (join "; " $unproven)) -}}
|
||||
{{- end -}}
|
||||
{{- /*
|
||||
Kafka 4.2/4.3 reject these topic configs that Kafka 3.x accepted, and the
|
||||
new kafka chart refuses to render them, which would leave that application
|
||||
on its pre-upgrade spec; a broker whose log holds a segment.bytes below the
|
||||
floor does not start. The same limits are in
|
||||
packages/apps/kafka/templates/topics.yaml,
|
||||
packages/core/platform/images/migrations/migrations/61 and
|
||||
packages/system/backupstrategy-controller/files/kafka-backup.sh.
|
||||
Application values live in the HelmRelease, so this does not depend on the
|
||||
aggregated apps API being available.
|
||||
*/ -}}
|
||||
{{- $segmentBytesMin := 1048576 -}}
|
||||
{{- $releases := lookup "helm.toolkit.fluxcd.io/v2" "HelmRelease" "" "" -}}
|
||||
{{- $removed := list -}}
|
||||
{{- range (and (kindIs "map" $releases) (kindIs "slice" (get $releases "items")) | ternary (get $releases "items") list) -}}
|
||||
{{- $meta := dig "metadata" dict . -}}
|
||||
{{- if eq (dig "labels" "apps.cozystack.io/application.kind" "" $meta) "Kafka" -}}
|
||||
{{- $app := printf "%v/%v" (get $meta "namespace") (dig "labels" "apps.cozystack.io/application.name" (get $meta "name") $meta) -}}
|
||||
{{- $topics := dig "spec" "values" "topics" list . -}}
|
||||
{{- range (kindIs "slice" $topics | ternary $topics list) -}}
|
||||
{{- if kindIs "map" . -}}
|
||||
{{- $config := get . "config" -}}
|
||||
{{- $topic := get . "name" -}}
|
||||
{{- range $key := list "message.downconversion.enable" "message.format.version" "message.timestamp.difference.max.ms" -}}
|
||||
{{- if and (kindIs "map" $config) (hasKey $config $key) -}}
|
||||
{{- $removed = append $removed (printf "%s: topic %v sets %s" $app $topic $key) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $segmentBytes := and (kindIs "map" $config) (get $config "segment.bytes") -}}
|
||||
{{- if or (kindIs "float64" $segmentBytes) (kindIs "int64" $segmentBytes) (kindIs "int" $segmentBytes) -}}
|
||||
{{- $segmentBytes = printf "%d" (int64 $segmentBytes) -}}
|
||||
{{- end -}}
|
||||
{{- /*
|
||||
Kafka trims characters up to U+0020 and reads the rest with
|
||||
Integer.parseInt: a sign is allowed and leading zeros are decimal, where
|
||||
int64 would read them as octal. The digits are compared as text, so a
|
||||
string too long for int64 is not misread either.
|
||||
*/ -}}
|
||||
{{- $integer := `^[\x00-\x20]*(?:\+|(-))?0*([0-9]+)[\x00-\x20]*$` -}}
|
||||
{{- if and (kindIs "string" $segmentBytes) (regexMatch $integer $segmentBytes) -}}
|
||||
{{- $value := regexReplaceAll $integer $segmentBytes "${1}${2}" -}}
|
||||
{{- $min := toString $segmentBytesMin -}}
|
||||
{{- if or (hasPrefix "-" $value) (lt (len $value) (len $min)) (and (eq (len $value) (len $min)) (lt $value $min)) -}}
|
||||
{{- $removed = append $removed (printf "%s: topic %v sets segment.bytes=%s, below the Kafka 4 minimum of %d" $app $topic $value $segmentBytesMin) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if $removed -}}
|
||||
{{- fail (printf "Kafka 4 rejects topic configs these Kafka applications still set: %s. Remove the configs Kafka 4 removed and raise segment.bytes to the minimum in the topics' config before upgrading the platform." (join "; " $removed)) -}}
|
||||
{{- end -}}
|
||||
{{- else if not (has "v1" $served) -}}
|
||||
{{- fail (printf "kafkas.kafka.strimzi.io serves neither v1beta2 nor v1 (served: %v); refusing to upgrade the platform without checking Kafka for KRaft" $served) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
@@ -1,3 +1,4 @@
|
||||
{{- include "cozystack.platform.kafkaKRaftGuard" . }}
|
||||
{{- $sourceRef := .Values.sourceRef }}
|
||||
{{- $apiVersion := "source.toolkit.fluxcd.io/v1" }}
|
||||
{{- $kind := $sourceRef.kind }}
|
||||
|
||||
@@ -0,0 +1,636 @@
|
||||
suite: repository refuses to move cozystack-packages while a pre-1.2 Strimzi Kafka lacks KRaft evidence
|
||||
# The default variant renders no migration hook, and helm-controller applies the
|
||||
# kafka-operator CRDs before any Helm pre-upgrade hook runs. The root platform
|
||||
# render is the last point that sees every Kafka before the new chart arrives.
|
||||
# A pre-1.2 CRD with no Kafka at all is not covered here: the helm-unittest
|
||||
# fake client registers a list kind only from the objects it is given. The
|
||||
# empty-list case is covered by the migration 61 tests.
|
||||
templates:
|
||||
- templates/repository.yaml
|
||||
release:
|
||||
name: cozystack-platform
|
||||
namespace: cozy-system
|
||||
scheme: &scheme
|
||||
"source.toolkit.fluxcd.io/v1/OCIRepository":
|
||||
gvr:
|
||||
group: source.toolkit.fluxcd.io
|
||||
version: v1
|
||||
resource: ocirepositories
|
||||
namespaced: true
|
||||
"apiextensions.k8s.io/v1/CustomResourceDefinition":
|
||||
gvr:
|
||||
group: apiextensions.k8s.io
|
||||
version: v1
|
||||
resource: customresourcedefinitions
|
||||
namespaced: false
|
||||
"helm.toolkit.fluxcd.io/v2/HelmRelease":
|
||||
gvr:
|
||||
group: helm.toolkit.fluxcd.io
|
||||
version: v2
|
||||
resource: helmreleases
|
||||
namespaced: true
|
||||
"kafka.strimzi.io/v1beta2/Kafka":
|
||||
gvr:
|
||||
group: kafka.strimzi.io
|
||||
version: v1beta2
|
||||
resource: kafkas
|
||||
namespaced: true
|
||||
source: &source
|
||||
kind: OCIRepository
|
||||
apiVersion: source.toolkit.fluxcd.io/v1
|
||||
metadata:
|
||||
name: cozystack-platform
|
||||
namespace: cozy-system
|
||||
spec:
|
||||
url: oci://example.test/cozystack-packages
|
||||
crdPre: &crdPre
|
||||
kind: CustomResourceDefinition
|
||||
apiVersion: apiextensions.k8s.io/v1
|
||||
metadata:
|
||||
name: kafkas.kafka.strimzi.io
|
||||
spec:
|
||||
versions:
|
||||
- name: v1
|
||||
served: true
|
||||
storage: true
|
||||
- name: v1beta2
|
||||
served: true
|
||||
storage: false
|
||||
crdPost: &crdPost
|
||||
kind: CustomResourceDefinition
|
||||
apiVersion: apiextensions.k8s.io/v1
|
||||
metadata:
|
||||
name: kafkas.kafka.strimzi.io
|
||||
spec:
|
||||
versions:
|
||||
- name: v1
|
||||
served: true
|
||||
storage: true
|
||||
crdPreStoredV1beta2: &crdPreStoredV1beta2
|
||||
kind: CustomResourceDefinition
|
||||
apiVersion: apiextensions.k8s.io/v1
|
||||
metadata:
|
||||
name: kafkas.kafka.strimzi.io
|
||||
spec:
|
||||
versions:
|
||||
- name: v1
|
||||
served: true
|
||||
storage: true
|
||||
- name: v1beta2
|
||||
served: true
|
||||
storage: false
|
||||
status:
|
||||
storedVersions: [v1beta2, v1]
|
||||
legacyKRaft: &legacyKRaft
|
||||
kind: Kafka
|
||||
apiVersion: kafka.strimzi.io/v1beta2
|
||||
metadata:
|
||||
name: kafka-legacy
|
||||
namespace: tenant-a
|
||||
spec:
|
||||
kafka:
|
||||
version: 3.9.0
|
||||
status:
|
||||
kafkaMetadataState: KRaft
|
||||
kafkaMetadataVersion: 3.9-IV0
|
||||
conditions:
|
||||
- type: Ready
|
||||
status: "True"
|
||||
modernKRaft: &modernKRaft
|
||||
kind: Kafka
|
||||
apiVersion: kafka.strimzi.io/v1beta2
|
||||
metadata:
|
||||
name: kafka-modern
|
||||
namespace: tenant-b
|
||||
spec:
|
||||
kafka:
|
||||
version: 4.1.1
|
||||
status:
|
||||
kafkaMetadataVersion: 4.1-IV1
|
||||
conditions:
|
||||
- type: Ready
|
||||
status: "True"
|
||||
# The test client lists only the kinds it is given an object of.
|
||||
unrelatedRelease: &unrelatedRelease
|
||||
kind: HelmRelease
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2
|
||||
metadata:
|
||||
name: unrelated
|
||||
namespace: tenant-z
|
||||
spec: {}
|
||||
kafkaAppRemovedTopicConfig: &kafkaAppRemovedTopicConfig
|
||||
kind: HelmRelease
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2
|
||||
metadata:
|
||||
name: kafka-events
|
||||
namespace: tenant-a
|
||||
labels:
|
||||
apps.cozystack.io/application.kind: Kafka
|
||||
apps.cozystack.io/application.name: events
|
||||
spec:
|
||||
values:
|
||||
topics:
|
||||
- name: clicks
|
||||
- name: orders
|
||||
config:
|
||||
retention.ms: "86400000"
|
||||
message.format.version: 3.0-IV1
|
||||
tests:
|
||||
- it: renders the repository when Strimzi is not installed
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects: [*source]
|
||||
asserts:
|
||||
- containsDocument:
|
||||
apiVersion: source.toolkit.fluxcd.io/v1
|
||||
kind: OCIRepository
|
||||
name: cozystack-packages
|
||||
namespace: cozy-system
|
||||
|
||||
- it: renders the repository when every Kafka proves KRaft, including modern evidence without legacy state
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects: [*source, *unrelatedRelease, *crdPre, *legacyKRaft, *modernKRaft]
|
||||
asserts:
|
||||
- containsDocument:
|
||||
apiVersion: source.toolkit.fluxcd.io/v1
|
||||
kind: OCIRepository
|
||||
name: cozystack-packages
|
||||
namespace: cozy-system
|
||||
|
||||
# The kafka-operator release replaces these CRDs with v1-only ones, which the
|
||||
# API server refuses while v1beta2 is still stored.
|
||||
- it: fails with migrations disabled while Strimzi still stores v1beta2, even when every Kafka proves KRaft
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects: [*source, *unrelatedRelease, *crdPreStoredV1beta2, *legacyKRaft, *modernKRaft]
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: "still stores v1beta2"
|
||||
- failedTemplate:
|
||||
errorPattern: "/migrations/61"
|
||||
|
||||
# A partly finished conversion can narrow the Kafka CRD and leave another one
|
||||
# storing v1beta2, which the CRD replace refuses just the same.
|
||||
- it: fails with migrations disabled while any other Strimzi CRD still stores v1beta2
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects:
|
||||
- *source
|
||||
- *unrelatedRelease
|
||||
- *crdPre
|
||||
- *legacyKRaft
|
||||
- kind: CustomResourceDefinition
|
||||
apiVersion: apiextensions.k8s.io/v1
|
||||
metadata:
|
||||
name: kafkatopics.kafka.strimzi.io
|
||||
spec:
|
||||
versions:
|
||||
- name: v1
|
||||
served: true
|
||||
storage: true
|
||||
status:
|
||||
storedVersions: [v1beta2, v1]
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: "still stores v1beta2 for kafkatopics.kafka.strimzi.io"
|
||||
|
||||
# Migration 61 runs as this upgrade's pre-upgrade hook and narrows the stored
|
||||
# versions itself.
|
||||
- it: renders with migrations enabled while Strimzi still stores v1beta2
|
||||
set:
|
||||
migrations:
|
||||
enabled: true
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects: [*source, *unrelatedRelease, *crdPreStoredV1beta2, *legacyKRaft, *modernKRaft]
|
||||
asserts:
|
||||
- containsDocument:
|
||||
apiVersion: source.toolkit.fluxcd.io/v1
|
||||
kind: OCIRepository
|
||||
name: cozystack-packages
|
||||
namespace: cozy-system
|
||||
|
||||
- it: fails with migrations disabled and lists every Kafka without KRaft evidence
|
||||
set:
|
||||
migrations:
|
||||
enabled: false
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects:
|
||||
- *source
|
||||
- *unrelatedRelease
|
||||
- *crdPre
|
||||
- *legacyKRaft
|
||||
- kind: Kafka
|
||||
apiVersion: kafka.strimzi.io/v1beta2
|
||||
metadata:
|
||||
name: kafka-nostatus
|
||||
namespace: tenant-c
|
||||
annotations:
|
||||
meta.helm.sh/release-name: kafka-nostatus
|
||||
spec:
|
||||
kafka:
|
||||
version: 3.9.0
|
||||
- kind: Kafka
|
||||
apiVersion: kafka.strimzi.io/v1beta2
|
||||
metadata:
|
||||
name: kafka-mid
|
||||
namespace: tenant-d
|
||||
spec:
|
||||
kafka:
|
||||
version: 3.9.0
|
||||
status:
|
||||
kafkaMetadataState: KRaftPostMigration
|
||||
kafkaMetadataVersion: 3.9-IV0
|
||||
conditions:
|
||||
- type: Ready
|
||||
status: "True"
|
||||
- kind: Kafka
|
||||
apiVersion: kafka.strimzi.io/v1beta2
|
||||
metadata:
|
||||
name: kafka-zk
|
||||
namespace: tenant-e
|
||||
spec:
|
||||
kafka:
|
||||
version: 3.9.0
|
||||
zookeeper:
|
||||
storage:
|
||||
type: ephemeral
|
||||
status:
|
||||
kafkaMetadataState: KRaft
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: "tenant-c/kafka-nostatus \\(Helm release: tenant-c/kafka-nostatus\\): no status"
|
||||
- failedTemplate:
|
||||
errorPattern: "tenant-d/kafka-mid: metadata state KRaftPostMigration"
|
||||
- failedTemplate:
|
||||
errorPattern: "tenant-e/kafka-zk: ZooKeeper section"
|
||||
- failedTemplate:
|
||||
errorPattern: "created after migration 61 stopped the Strimzi operators"
|
||||
- failedTemplate:
|
||||
errorPattern: "/migrations/61"
|
||||
|
||||
- it: fails with migrations enabled on a NotReady Kafka without a KRaft state while v1beta2 is served
|
||||
set:
|
||||
migrations:
|
||||
enabled: true
|
||||
kubernetesProvider:
|
||||
scheme:
|
||||
<<: *scheme
|
||||
"v1/ConfigMap":
|
||||
gvr:
|
||||
version: v1
|
||||
resource: configmaps
|
||||
namespaced: true
|
||||
objects:
|
||||
- *source
|
||||
- *unrelatedRelease
|
||||
- *crdPre
|
||||
- kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: cozystack-version
|
||||
namespace: cozy-system
|
||||
data:
|
||||
version: "62"
|
||||
- kind: Kafka
|
||||
apiVersion: kafka.strimzi.io/v1beta2
|
||||
metadata:
|
||||
name: kafka-notready
|
||||
namespace: tenant-f
|
||||
spec:
|
||||
kafka:
|
||||
version: 4.1.1
|
||||
status:
|
||||
kafkaMetadataVersion: 4.1-IV1
|
||||
conditions:
|
||||
- type: NotReady
|
||||
status: "True"
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: "tenant-f/kafka-notready"
|
||||
|
||||
- it: ignores a NotReady Kafka once only the Strimzi 1.2 v1 API is served
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects:
|
||||
- *source
|
||||
- *unrelatedRelease
|
||||
- *crdPost
|
||||
- kind: Kafka
|
||||
apiVersion: kafka.strimzi.io/v1beta2
|
||||
metadata:
|
||||
name: kafka-notready
|
||||
namespace: tenant-f
|
||||
spec: {}
|
||||
status:
|
||||
conditions:
|
||||
- type: NotReady
|
||||
status: "True"
|
||||
asserts:
|
||||
- containsDocument:
|
||||
apiVersion: source.toolkit.fluxcd.io/v1
|
||||
kind: OCIRepository
|
||||
name: cozystack-packages
|
||||
namespace: cozy-system
|
||||
|
||||
- it: fails closed on a Kafka CRD that serves neither known version
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects:
|
||||
- *source
|
||||
- *unrelatedRelease
|
||||
- kind: CustomResourceDefinition
|
||||
apiVersion: apiextensions.k8s.io/v1
|
||||
metadata:
|
||||
name: kafkas.kafka.strimzi.io
|
||||
spec:
|
||||
versions:
|
||||
- name: v1beta1
|
||||
served: true
|
||||
storage: true
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: "kafkas.kafka.strimzi.io serves neither"
|
||||
|
||||
- it: lists a Kafka whose status carries a metadata version but no conditions
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects:
|
||||
- *source
|
||||
- *unrelatedRelease
|
||||
- *crdPre
|
||||
- kind: Kafka
|
||||
apiVersion: kafka.strimzi.io/v1beta2
|
||||
metadata:
|
||||
name: kafka-noconditions
|
||||
namespace: tenant-g
|
||||
spec:
|
||||
kafka:
|
||||
version: 4.1.1
|
||||
status:
|
||||
kafkaMetadataVersion: 4.1-IV1
|
||||
- kind: Kafka
|
||||
apiVersion: kafka.strimzi.io/v1beta2
|
||||
metadata:
|
||||
name: kafka-emptystatus
|
||||
namespace: tenant-h
|
||||
spec:
|
||||
kafka:
|
||||
version: 4.1.1
|
||||
status: {}
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: "KRaft is not confirmed for these Kafka clusters: .*tenant-g/kafka-noconditions"
|
||||
- failedTemplate:
|
||||
errorPattern: "tenant-h/kafka-emptystatus"
|
||||
|
||||
# KRaft is the final Strimzi metadata state, so with a metadata version it
|
||||
# proves KRaft on its own. The conversion deletes the state; migration 61
|
||||
# records the proof in an annotation first, so a retry accepts the same Kafka.
|
||||
- it: renders when a NotReady Kafka has an explicit KRaft state or the migration's KRaft annotation
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects:
|
||||
- *source
|
||||
- *unrelatedRelease
|
||||
- *crdPre
|
||||
- kind: Kafka
|
||||
apiVersion: kafka.strimzi.io/v1beta2
|
||||
metadata:
|
||||
name: kafka-kraft-notready
|
||||
namespace: tenant-i
|
||||
spec:
|
||||
kafka:
|
||||
version: 3.9.0
|
||||
status:
|
||||
kafkaMetadataState: KRaft
|
||||
kafkaMetadataVersion: 3.9-IV0
|
||||
conditions:
|
||||
- type: NotReady
|
||||
status: "True"
|
||||
- kind: Kafka
|
||||
apiVersion: kafka.strimzi.io/v1beta2
|
||||
metadata:
|
||||
name: kafka-converted-notready
|
||||
namespace: tenant-l
|
||||
annotations:
|
||||
cozystack.io/kraft-verified: 3.9-IV0
|
||||
spec:
|
||||
kafka:
|
||||
version: 3.9.0
|
||||
status:
|
||||
kafkaMetadataVersion: 3.9-IV0
|
||||
conditions:
|
||||
- type: NotReady
|
||||
status: "True"
|
||||
asserts:
|
||||
- containsDocument:
|
||||
apiVersion: source.toolkit.fluxcd.io/v1
|
||||
kind: OCIRepository
|
||||
name: cozystack-packages
|
||||
namespace: cozy-system
|
||||
|
||||
- it: lists a Kafka without a metadata version, or NotReady without a KRaft state or annotation
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects:
|
||||
- *source
|
||||
- *unrelatedRelease
|
||||
- *crdPre
|
||||
- kind: Kafka
|
||||
apiVersion: kafka.strimzi.io/v1beta2
|
||||
metadata:
|
||||
name: kafka-kraft-noversion
|
||||
namespace: tenant-j
|
||||
annotations:
|
||||
cozystack.io/kraft-verified: 3.9-IV0
|
||||
spec:
|
||||
kafka:
|
||||
version: 3.9.0
|
||||
status:
|
||||
kafkaMetadataState: KRaft
|
||||
conditions:
|
||||
- type: Ready
|
||||
status: "True"
|
||||
- kind: Kafka
|
||||
apiVersion: kafka.strimzi.io/v1beta2
|
||||
metadata:
|
||||
name: kafka-ready-false
|
||||
namespace: tenant-k
|
||||
annotations:
|
||||
cozystack.io/kraft-verified: ""
|
||||
spec:
|
||||
kafka:
|
||||
version: 4.1.1
|
||||
status:
|
||||
kafkaMetadataVersion: 4.1-IV1
|
||||
conditions:
|
||||
- type: Ready
|
||||
status: "False"
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: "tenant-j/kafka-kraft-noversion: no kafkaMetadataVersion"
|
||||
- failedTemplate:
|
||||
errorPattern: "tenant-k/kafka-ready-false: not Ready"
|
||||
|
||||
# Kafka 4 rejects these topic configs, and the kafka chart refuses to render
|
||||
# them; caught here, they stop the upgrade before any application moves.
|
||||
- it: fails while v1beta2 is served and a Kafka application sets a topic config Kafka 4 removed
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects: [*source, *unrelatedRelease, *crdPre, *legacyKRaft, *kafkaAppRemovedTopicConfig]
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: "tenant-a/events: topic orders sets message.format.version"
|
||||
|
||||
- it: fails while a Kafka application sets segment.bytes below the Kafka 4 floor
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects:
|
||||
- *source
|
||||
- *unrelatedRelease
|
||||
- *crdPre
|
||||
- *legacyKRaft
|
||||
- kind: HelmRelease
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2
|
||||
metadata:
|
||||
name: kafka-events
|
||||
namespace: tenant-a
|
||||
labels:
|
||||
apps.cozystack.io/application.kind: Kafka
|
||||
apps.cozystack.io/application.name: events
|
||||
spec:
|
||||
values:
|
||||
topics:
|
||||
# The fake client deep-copies only JSON number types, so the
|
||||
# number is written as a float, as decoded JSON arrives.
|
||||
- name: small
|
||||
config:
|
||||
segment.bytes: 524288.0
|
||||
- name: floor
|
||||
config:
|
||||
segment.bytes: "1048576"
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: "tenant-a/events: topic small sets segment.bytes=524288, below the Kafka 4 minimum of 1048576"
|
||||
|
||||
# Kafka trims the value and reads it with Integer.parseInt, which takes a
|
||||
# sign and reads leading zeros as decimal; what it cannot parse is left to it.
|
||||
- it: fails while a Kafka application sets segment.bytes below the floor padded or with a plus sign
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects:
|
||||
- *source
|
||||
- *unrelatedRelease
|
||||
- *crdPre
|
||||
- *legacyKRaft
|
||||
- kind: HelmRelease
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2
|
||||
metadata:
|
||||
name: kafka-events
|
||||
namespace: tenant-a
|
||||
labels:
|
||||
apps.cozystack.io/application.kind: Kafka
|
||||
apps.cozystack.io/application.name: events
|
||||
spec:
|
||||
values:
|
||||
topics:
|
||||
- name: padded
|
||||
config:
|
||||
segment.bytes: " 524288"
|
||||
- name: plus
|
||||
config:
|
||||
segment.bytes: "+100"
|
||||
- name: zeros
|
||||
config:
|
||||
segment.bytes: "02000000"
|
||||
- name: exp
|
||||
config:
|
||||
segment.bytes: "1e3"
|
||||
- name: negative
|
||||
config:
|
||||
segment.bytes: "-2000000"
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorPattern: "topic padded sets segment.bytes=524288, below the Kafka 4 minimum of 1048576; tenant-a/events: topic plus sets segment.bytes=100, below the Kafka 4 minimum of 1048576; tenant-a/events: topic negative sets segment.bytes=-2000000, below the Kafka 4 minimum of 1048576\\. Remove"
|
||||
|
||||
- it: renders when no Kafka application sets a removed topic config
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects:
|
||||
- *source
|
||||
- *unrelatedRelease
|
||||
- *crdPre
|
||||
- *legacyKRaft
|
||||
- kind: HelmRelease
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2
|
||||
metadata:
|
||||
name: kafka-events
|
||||
namespace: tenant-a
|
||||
labels:
|
||||
apps.cozystack.io/application.kind: Kafka
|
||||
apps.cozystack.io/application.name: events
|
||||
spec:
|
||||
values:
|
||||
topics:
|
||||
- name: orders
|
||||
config:
|
||||
retention.ms: "86400000"
|
||||
- kind: HelmRelease
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2
|
||||
metadata:
|
||||
name: other
|
||||
namespace: tenant-a
|
||||
labels:
|
||||
apps.cozystack.io/application.kind: Other
|
||||
spec:
|
||||
values:
|
||||
topics:
|
||||
- name: orders
|
||||
config:
|
||||
message.format.version: 3.0-IV1
|
||||
asserts:
|
||||
- containsDocument:
|
||||
apiVersion: source.toolkit.fluxcd.io/v1
|
||||
kind: OCIRepository
|
||||
name: cozystack-packages
|
||||
namespace: cozy-system
|
||||
|
||||
- it: ignores a removed topic config once only the Strimzi 1.2 v1 API is served
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects: [*source, *unrelatedRelease, *crdPost, *kafkaAppRemovedTopicConfig]
|
||||
asserts:
|
||||
- containsDocument:
|
||||
apiVersion: source.toolkit.fluxcd.io/v1
|
||||
kind: OCIRepository
|
||||
name: cozystack-packages
|
||||
namespace: cozy-system
|
||||
|
||||
- it: skips a topic entry that is not a map instead of failing the render
|
||||
kubernetesProvider:
|
||||
scheme: *scheme
|
||||
objects:
|
||||
- *source
|
||||
- *unrelatedRelease
|
||||
- *crdPre
|
||||
- *legacyKRaft
|
||||
- kind: HelmRelease
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2
|
||||
metadata:
|
||||
name: kafka-events
|
||||
namespace: tenant-a
|
||||
labels:
|
||||
apps.cozystack.io/application.kind: Kafka
|
||||
apps.cozystack.io/application.name: events
|
||||
spec:
|
||||
values:
|
||||
topics: ["orders"]
|
||||
asserts:
|
||||
- containsDocument:
|
||||
apiVersion: source.toolkit.fluxcd.io/v1
|
||||
kind: OCIRepository
|
||||
name: cozystack-packages
|
||||
namespace: cozy-system
|
||||
Reference in new issue
Block a user