From fd885206e4e66b800af03ad5cb1924705577ffd4 Mon Sep 17 00:00:00 2001 From: Mattia Eleuteri Date: Fri, 20 Nov 2026 15:41:03 +0100 Subject: [PATCH] fix(kafka): link the node pools the hook creates to their HelmRelease The broker and controller pools are applied by the pre-upgrade hook, outside Flux, so they carry neither an ownerReference nor the HelmRelease labels Flux puts on what it renders. The lineage walk from a broker or controller pod therefore stopped at its pool: those pods were never marked as managed by Cozystack, and the Kafka application's schedulingClass never reached them. Assisted-by: LLM Signed-off-by: Mattia Eleuteri --- packages/apps/kafka/README.md | 6 +++--- .../apps/kafka/templates/migration-hook.yaml | 8 +++++++ .../apps/kafka/tests/migration-hook_test.yaml | 21 +++++++++++++++++++ packages/apps/kafka/values.schema.json | 2 +- packages/apps/kafka/values.yaml | 2 +- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/packages/apps/kafka/README.md b/packages/apps/kafka/README.md index 6fcb592bb..44d96bb25 100644 --- a/packages/apps/kafka/README.md +++ b/packages/apps/kafka/README.md @@ -62,9 +62,9 @@ Neither lowering the `version` field on a running cluster nor rolling the app ba ### Scheduling parameters -| Name | Description | Type | Value | -| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ----- | -| `schedulingClass` | Name of a SchedulingClass CR (cluster-scoped, group cozystack.io) used in place of the tenant's for this application's pods. A pod gets its class when it is created, so running pods keep theirs until they are recreated. Must be the tenant's own class or one listed in the tenant's `allowedSchedulingClasses`; any other value is refused. If the class is later removed from that list, new pods get the tenant's class. Empty means inherit from the tenant. | `string` | `""` | +| Name | Description | Type | Value | +| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ----- | +| `schedulingClass` | Name of a SchedulingClass CR (cluster-scoped, group cozystack.io) used in place of the tenant's for this application's pods. A pod gets its class when it is created, so running pods keep theirs until they are recreated. Must be the tenant's own class or one listed in the tenant's `allowedSchedulingClasses`. Setting any other value is refused, and the pods of an application whose class is not, or no longer, in that list get the tenant's class. Empty means inherit from the tenant. | `string` | `""` | ## Parameter examples and reference diff --git a/packages/apps/kafka/templates/migration-hook.yaml b/packages/apps/kafka/templates/migration-hook.yaml index 5c9e95032..3578c9dd8 100644 --- a/packages/apps/kafka/templates/migration-hook.yaml +++ b/packages/apps/kafka/templates/migration-hook.yaml @@ -99,6 +99,12 @@ spec: labels: strimzi.io/cluster: ${name} app.kubernetes.io/managed-by: Helm + # Flux puts these on everything it renders, and the lineage + # walk follows them to the application. A pool created here + # has neither them nor an ownerReference, so without them its + # broker and controller pods resolve to no application at all. + helm.toolkit.fluxcd.io/name: ${name} + helm.toolkit.fluxcd.io/namespace: ${ns} annotations: meta.helm.sh/release-name: ${name} meta.helm.sh/release-namespace: ${ns} @@ -134,6 +140,8 @@ spec: labels: strimzi.io/cluster: ${name} app.kubernetes.io/managed-by: Helm + helm.toolkit.fluxcd.io/name: ${name} + helm.toolkit.fluxcd.io/namespace: ${ns} annotations: meta.helm.sh/release-name: ${name} meta.helm.sh/release-namespace: ${ns} diff --git a/packages/apps/kafka/tests/migration-hook_test.yaml b/packages/apps/kafka/tests/migration-hook_test.yaml index 5b1daff11..ae2a2c9d8 100644 --- a/packages/apps/kafka/tests/migration-hook_test.yaml +++ b/packages/apps/kafka/tests/migration-hook_test.yaml @@ -279,3 +279,24 @@ tests: - matchRegex: path: spec.template.spec.containers[0].args[0] pattern: 'brokerPool="b-[0-9a-f]{8}"' + + # The pools are created by the hook, outside Flux, so they carry the + # HelmRelease labels themselves: the lineage walk needs them to resolve + # broker and controller pods to the Kafka application. + - it: labels both node pools with their HelmRelease + release: + name: test-kafka + namespace: tenant-test + asserts: + - matchRegex: + path: spec.template.spec.containers[0].args[0] + pattern: 'name: \$\{brokerPool\}\s+namespace: \$\{ns\}\s+labels:\s+strimzi\.io/cluster: \$\{name\}\s+app\.kubernetes\.io/managed-by: Helm\s+(#[^\n]*\s+)*helm\.toolkit\.fluxcd\.io/name: \$\{name\}\s+helm\.toolkit\.fluxcd\.io/namespace: \$\{ns\}\s+annotations:' + documentSelector: + path: kind + value: Job + - matchRegex: + path: spec.template.spec.containers[0].args[0] + pattern: 'name: [-a-z0-9]+\s+namespace: \$\{ns\}\s+labels:\s+strimzi\.io/cluster: \$\{name\}\s+app\.kubernetes\.io/managed-by: Helm\s+helm\.toolkit\.fluxcd\.io/name: \$\{name\}\s+helm\.toolkit\.fluxcd\.io/namespace: \$\{ns\}\s+annotations:\s+meta\.helm\.sh/release-name: \$\{name\}\s+meta\.helm\.sh/release-namespace: \$\{ns\}\s+# Controller node IDs' + documentSelector: + path: kind + value: Job diff --git a/packages/apps/kafka/values.schema.json b/packages/apps/kafka/values.schema.json index 699bacf23..8197eaa2c 100644 --- a/packages/apps/kafka/values.schema.json +++ b/packages/apps/kafka/values.schema.json @@ -212,7 +212,7 @@ } }, "schedulingClass": { - "description": "Name of a SchedulingClass CR (cluster-scoped, group cozystack.io) used in place of the tenant's for this application's pods. A pod gets its class when it is created, so running pods keep theirs until they are recreated. Must be the tenant's own class or one listed in the tenant's `allowedSchedulingClasses`; any other value is refused. If the class is later removed from that list, new pods get the tenant's class. Empty means inherit from the tenant.", + "description": "Name of a SchedulingClass CR (cluster-scoped, group cozystack.io) used in place of the tenant's for this application's pods. A pod gets its class when it is created, so running pods keep theirs until they are recreated. Must be the tenant's own class or one listed in the tenant's `allowedSchedulingClasses`. Setting any other value is refused, and the pods of an application whose class is not, or no longer, in that list get the tenant's class. Empty means inherit from the tenant.", "type": "string", "default": "", "maxLength": 63 diff --git a/packages/apps/kafka/values.yaml b/packages/apps/kafka/values.yaml index 3874113de..2fbb2535f 100644 --- a/packages/apps/kafka/values.yaml +++ b/packages/apps/kafka/values.yaml @@ -127,6 +127,6 @@ kafka: ## @section Scheduling parameters -## @param {string} schedulingClass - Name of a SchedulingClass CR (cluster-scoped, group cozystack.io) used in place of the tenant's for this application's pods. A pod gets its class when it is created, so running pods keep theirs until they are recreated. Must be the tenant's own class or one listed in the tenant's `allowedSchedulingClasses`; any other value is refused. If the class is later removed from that list, new pods get the tenant's class. Empty means inherit from the tenant. +## @param {string} schedulingClass - Name of a SchedulingClass CR (cluster-scoped, group cozystack.io) used in place of the tenant's for this application's pods. A pod gets its class when it is created, so running pods keep theirs until they are recreated. Must be the tenant's own class or one listed in the tenant's `allowedSchedulingClasses`. Setting any other value is refused, and the pods of an application whose class is not, or no longer, in that list get the tenant's class. Empty means inherit from the tenant. ## @maxLength 63 schedulingClass: ""