mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 20:23:39 +09:00
Fresh KRaft clusters no longer need to be alone in a namespace. Their node pools get short, release-hashed names — "b-<hash>" for brokers, "c-<hash>" for controllers — instead of the fixed "kafka"/"controller". Each release hashes differently, so the names are unique within the namespace (KafkaNodePool object names are namespace-unique) and any number of Kafka instances coexist. The hash keeps the pool name a fixed length: Strimzi derives every pod/PVC name as <cluster>-<pool>-<id> and the cluster name is already the release name, so embedding the release name in the pool name too would double it into every pod hostname and blow the 63-character DNS label limit for long release names. A render-time guard fails with a clear message when even the hashed controller node name would still exceed 63 characters. The fixed "kafka" name is still required to adopt an existing ZooKeeper cluster's <cluster>-kafka-N brokers and data in place during migration, so kafka.brokerPoolName resolves to "kafka" for a migrating/migrated cluster and "b-<hash>" for a fresh one. A second ZooKeeper->KRaft migration into a namespace that already holds a "kafka" pool owned by another cluster fails closed, both at render time and in the pre-upgrade hook (whose owner probe uses --ignore-not-found + an explicit exit-code check, so a transient kubectl error aborts rather than silently waiving the collision guard). This replaces the previous blanket "one Kafka per namespace" guard, which over-restricted the fresh case. The pool names are resolved from a live Helm lookup; that is safe because Helm propagates any non-NotFound read error and fails the whole render (pkg/engine/lookup_func.go), so a transient apiserver/RBAC miss retries rather than silently flipping a live cluster's pool name — an empty lookup means genuine absence or a never-applied client-side render. The migration hook and workload monitors follow the same naming. Tests: helm-unittest fixtures (via kubernetesProvider) cover every resolution branch and the fail-closed guards; hack/kafka-migration-hook.bats drives the migration Job's real shell script against a stub kubectl across the fresh / read-error / already-KRaft / owner-collision / happy-path / stuck / retry cases. Verified on a live cluster: in-place ZooKeeper->KRaft migration preserved all data and adopted the original broker PVCs, and two fresh clusters coexist with distinct pools, pods and PVCs. Signed-off-by: Alexey Artamonov <aleksei.artamonov@aenix.io>
143 lines
3.3 KiB
YAML
143 lines
3.3 KiB
YAML
suite: WorkloadMonitor tests
|
|
|
|
templates:
|
|
- templates/workloadmonitor.yaml
|
|
|
|
tests:
|
|
##################################
|
|
# Pool layout (always separated) #
|
|
##################################
|
|
|
|
- it: renders broker and controller WorkloadMonitors
|
|
release:
|
|
name: test-kafka
|
|
namespace: tenant-test
|
|
asserts:
|
|
- hasDocuments:
|
|
count: 2
|
|
- isKind:
|
|
of: WorkloadMonitor
|
|
documentIndex: 0
|
|
- isKind:
|
|
of: WorkloadMonitor
|
|
documentIndex: 1
|
|
|
|
- it: names broker monitor as the release and controller monitor with -controller suffix
|
|
release:
|
|
name: test-kafka
|
|
namespace: tenant-test
|
|
asserts:
|
|
- equal:
|
|
path: metadata.name
|
|
value: test-kafka
|
|
documentIndex: 0
|
|
- equal:
|
|
path: metadata.name
|
|
value: test-kafka-controller
|
|
documentIndex: 1
|
|
|
|
- it: sets broker monitor type to kafka-broker with pool-name selector
|
|
release:
|
|
name: test-kafka
|
|
namespace: tenant-test
|
|
asserts:
|
|
- equal:
|
|
path: spec.type
|
|
value: kafka-broker
|
|
documentIndex: 0
|
|
- matchRegex:
|
|
path: spec.selector["strimzi.io/pool-name"]
|
|
pattern: ^b-[0-9a-f]{8}$
|
|
documentIndex: 0
|
|
|
|
- it: sets controller monitor type to kafka-controller with pool-name selector
|
|
release:
|
|
name: test-kafka
|
|
namespace: tenant-test
|
|
asserts:
|
|
- equal:
|
|
path: spec.type
|
|
value: kafka-controller
|
|
documentIndex: 1
|
|
- matchRegex:
|
|
path: spec.selector["strimzi.io/pool-name"]
|
|
pattern: ^c-[0-9a-f]{8}$
|
|
documentIndex: 1
|
|
|
|
##################################
|
|
# Replicas #
|
|
##################################
|
|
|
|
- it: broker monitor replicas track kafka.replicas
|
|
release:
|
|
name: test-kafka
|
|
namespace: tenant-test
|
|
set:
|
|
kafka:
|
|
replicas: 5
|
|
asserts:
|
|
- equal:
|
|
path: spec.replicas
|
|
value: 5
|
|
documentIndex: 0
|
|
|
|
- it: controller monitor has 3 replicas when kafka.replicas >= 2
|
|
release:
|
|
name: test-kafka
|
|
namespace: tenant-test
|
|
set:
|
|
kafka:
|
|
replicas: 5
|
|
asserts:
|
|
- equal:
|
|
path: spec.replicas
|
|
value: 3
|
|
documentIndex: 1
|
|
|
|
- it: controller monitor falls back to 1 replica when kafka.replicas <= 1
|
|
release:
|
|
name: test-kafka
|
|
namespace: tenant-test
|
|
set:
|
|
kafka:
|
|
replicas: 1
|
|
asserts:
|
|
- equal:
|
|
path: spec.replicas
|
|
value: 1
|
|
documentIndex: 1
|
|
|
|
##################################
|
|
# Common fields #
|
|
##################################
|
|
|
|
- it: sets kind=kafka and minReplicas=1 on both monitors
|
|
release:
|
|
name: test-kafka
|
|
namespace: tenant-test
|
|
asserts:
|
|
- equal:
|
|
path: spec.kind
|
|
value: kafka
|
|
documentIndex: 0
|
|
- equal:
|
|
path: spec.minReplicas
|
|
value: 1
|
|
documentIndex: 0
|
|
- equal:
|
|
path: spec.kind
|
|
value: kafka
|
|
documentIndex: 1
|
|
- equal:
|
|
path: spec.minReplicas
|
|
value: 1
|
|
documentIndex: 1
|
|
|
|
- it: does not render a zookeeper WorkloadMonitor
|
|
release:
|
|
name: test-kafka
|
|
namespace: tenant-test
|
|
asserts:
|
|
- hasDocuments:
|
|
count: 2
|