From 5c6e212ef417fd14a241d0499dd655e98ce23c25 Mon Sep 17 00:00:00 2001 From: Matt Wise Date: Tue, 21 Jan 2025 13:07:53 -0800 Subject: [PATCH 1/6] feat(local-kafka): switch to kraft, start faster, allow annotations --- charts/local-kafka/Chart.yaml | 4 +-- .../templates/kafka-node-pool.yaml | 22 +++++++++++++++ charts/local-kafka/templates/kafka.yaml | 28 ++++++------------- charts/local-kafka/values.yaml | 17 +++-------- 4 files changed, 37 insertions(+), 34 deletions(-) create mode 100644 charts/local-kafka/templates/kafka-node-pool.yaml diff --git a/charts/local-kafka/Chart.yaml b/charts/local-kafka/Chart.yaml index 6734c94..dcf676a 100644 --- a/charts/local-kafka/Chart.yaml +++ b/charts/local-kafka/Chart.yaml @@ -2,13 +2,13 @@ apiVersion: v2 name: local-kafka description: Local Development spinup of Strimzi-managed Kafka type: application -version: 0.42.1 +version: 0.43.0 appVersion: latest maintainers: - name: diranged email: matt@nextdoor.com dependencies: - name: strimzi-kafka-operator - version: 0.42.0 + version: 0.45.0 repository: https://strimzi.io/charts condition: strimzi-kafka-operator.enabled diff --git a/charts/local-kafka/templates/kafka-node-pool.yaml b/charts/local-kafka/templates/kafka-node-pool.yaml new file mode 100644 index 0000000..9c880a3 --- /dev/null +++ b/charts/local-kafka/templates/kafka-node-pool.yaml @@ -0,0 +1,22 @@ +apiVersion: kafka.strimzi.io/v1beta2 +kind: KafkaNodePool +metadata: + name: {{ .Values.clusterName }} + {{- with .Values.namespaceOverride }} + namespace: {{ . }} + {{- end }} + labels: + strimzi.io/cluster: {{ .Values.clusterName }} +spec: + replicas: 1 + roles: + - controller + - broker + storage: + type: jbod + volumes: + - id: 0 + type: persistent-claim + size: 500Mi + deleteClaim: false + kraftMetadata: shared diff --git a/charts/local-kafka/templates/kafka.yaml b/charts/local-kafka/templates/kafka.yaml index 34dfc40..3eead9c 100644 --- a/charts/local-kafka/templates/kafka.yaml +++ b/charts/local-kafka/templates/kafka.yaml @@ -6,6 +6,9 @@ metadata: {{- with .Values.namespaceOverride }} namespace: {{ . }} {{- end }} + annotations: + strimzi.io/node-pools: enabled + strimzi.io/kraft: enabled spec: kafka: {{- with .Values.kafka.brokerVersion }} @@ -17,12 +20,12 @@ spec: priorityClassName: {{ . }} {{- end }} replicas: 1 - livenessProbe: - initialDelaySeconds: 60 - failureThreshold: 30 # 30 * 10s - readinessProbe: - initialDelaySeconds: 60 - failureThreshold: 30 # 30 * 10s + #livenessProbe: + # initialDelaySeconds: 60 + # failureThreshold: 30 # 30 * 10s + #readinessProbe: + # initialDelaySeconds: 60 + # failureThreshold: 30 # 30 * 10s authorization: type: simple superUsers: @@ -54,19 +57,6 @@ spec: {{- with .Values.kafka.interBrokerProtocolVersion }} inter.broker.protocol.version: "{{ . }}" {{- end }} - storage: - type: jbod - volumes: - - id: 0 - type: persistent-claim - size: 500Mi - deleteClaim: false - zookeeper: - replicas: 1 - storage: - type: persistent-claim - size: 500Mi - deleteClaim: false entityOperator: topicOperator: {} userOperator: {} diff --git a/charts/local-kafka/values.yaml b/charts/local-kafka/values.yaml index 5a9e8dc..2d99efd 100644 --- a/charts/local-kafka/values.yaml +++ b/charts/local-kafka/values.yaml @@ -63,19 +63,10 @@ strimzi-kafka-operator: # development projects. watchAnyNamespace: true - # -- Run the Operator in a pretty verbose mode - allowing developers to more - # easily understand if there are any problems with the operator installation - # or its behavior. - logLevel: DEBUG - - # I cannot tell you why - but for local dev (at least on an M1 laptop), it - # seems that the initial startup takes MUCH longer than it should. Without - # this, you get into a restart-loop where Kubernetes keeps thinking the - # Operator is not healthy, when it's really just in its startup phase. - livenessProbe: - initialDelaySeconds: 180 - readinessProbe: - initialDelaySeconds: 180 + # -- Optionally run the Operator in a pretty verbose mode - allowing + # developers to more easily understand if there are any problems with the + # operator installation or its behavior. + logLevel: INFO # -- Reconfigure the default resource requirements here so that the # "requests" are as low as possible for memory (so we're not allocating any From 34a0e8b8a2e82a9dac6afd09e6418e24a0ef4332 Mon Sep 17 00:00:00 2001 From: Matt Wise Date: Tue, 21 Jan 2025 13:20:44 -0800 Subject: [PATCH 2/6] feat(local-kafka): add podAnnotations --- charts/local-kafka/README.md | 35 ++++++++++++++++--- charts/local-kafka/README.md.gotmpl | 26 ++++++++++++++ charts/local-kafka/ci/default-values.yaml | 1 + charts/local-kafka/ci/local-values.yaml | 1 + .../templates/kafka-node-pool.yaml | 7 ++++ charts/local-kafka/templates/kafka.yaml | 7 ++++ charts/local-kafka/values.local.yaml | 2 ++ charts/local-kafka/values.yaml | 3 ++ 8 files changed, 77 insertions(+), 5 deletions(-) create mode 120000 charts/local-kafka/ci/default-values.yaml create mode 120000 charts/local-kafka/ci/local-values.yaml diff --git a/charts/local-kafka/README.md b/charts/local-kafka/README.md index 07b95ed..40446c2 100644 --- a/charts/local-kafka/README.md +++ b/charts/local-kafka/README.md @@ -2,7 +2,7 @@ Local Development spinup of Strimzi-managed Kafka -![Version: 0.42.1](https://img.shields.io/badge/Version-0.42.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square) +![Version: 0.43.0](https://img.shields.io/badge/Version-0.43.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square) [strimzi_op]: https://github.com/strimzi/strimzi-kafka-operator @@ -30,11 +30,37 @@ That will allow each project to install a local `Kafka` cluster and `KafkaUser` resource in the development namespace, completely isolated from the _other_ project's development namespace. +## Upgrade Notes + +### 0.42.x -> 0.43.x + +**NEW: Using KRaft mode instead of Zookeeper mode** + +By switching Strimzi to use [KRaft +mode](https://strimzi.io/blog/2024/03/22/strimzi-kraft-migration/) we reduce +the number of pods that have to start up locally and speed up the test process +because we do not have to wait for Zookeeper to start up. + +**NEW: Custom Pod Annotations** + +When installing the `local-kafka` chart as a dependency purely for testing, it +may be advantageous to add [Helm Chart +Hooks](https://helm.sh/docs/topics/charts_hooks/) that set the order in which +the pods start up. For example, if you want to make sure all of the Kafka pods +are up and ready before your own application pods start up: + +```yaml +# values.yaml +local-kafka: + podAnnotations: + "helm.sh/hook": pre-install +``` + ## Requirements | Repository | Name | Version | |------------|------|---------| -| https://strimzi.io/charts | strimzi-kafka-operator | 0.42.0 | +| https://strimzi.io/charts | strimzi-kafka-operator | 0.45.0 | ## Values @@ -47,14 +73,13 @@ project's development namespace. | kafka.priorityClassName | `str` | `nil` | Optional value for the kafka cluster pod priority class name | | listeners | list | `[{"configuration":{"brokers":[{"advertisedHost":"127.0.0.1","broker":0,"nodePort":32000}]},"name":"external","port":9094,"tls":false,"type":"nodeport"}]` | Additional configurable listeners for connecting to brokers. | | namespaceOverride | string | `nil` | Optionally force the namespace that the resources in this stack are launched in. Without this, the default namespace that the Helm chart is being put into is used. It is recommended to keep this empty. | +| podAnnotations | object | `{}` | Optional annotations added to all of the Strimzi-managed Pods. | | strimzi-kafka-operator.enabled | bool | `true` | Set to `false` to intentionally disable installation of the Operator. This is useful if you are running this stack in a local dev environment where you might have multiple Kafka environments, and are already running the Strimzi operator. | | strimzi-kafka-operator.image.name | `str` | `"operator"` | Cluster Operator image name | | strimzi-kafka-operator.image.registry | `str` | `""` | Override default Cluster Operator image registry | | strimzi-kafka-operator.image.repository | `str` | `""` | Override default Cluster Operator image repository | | strimzi-kafka-operator.image.tag | `str` | `""` | Override default Cluster Operator image tag | -| strimzi-kafka-operator.livenessProbe.initialDelaySeconds | int | `180` | | -| strimzi-kafka-operator.logLevel | string | `"DEBUG"` | Run the Operator in a pretty verbose mode - allowing developers to more easily understand if there are any problems with the operator installation or its behavior. | -| strimzi-kafka-operator.readinessProbe.initialDelaySeconds | int | `180` | | +| strimzi-kafka-operator.logLevel | string | `"INFO"` | Optionally run the Operator in a pretty verbose mode - allowing developers to more easily understand if there are any problems with the operator installation or its behavior. | | strimzi-kafka-operator.resources | object | `{"limits":{"memory":"1Gi"},"requests":{"cpu":"250m","memory":"512Mi"}}` | Reconfigure the default resource requirements here so that the "requests" are as low as possible for memory (so we're not allocating any more memory than we absolutely must). | | strimzi-kafka-operator.watchAnyNamespace | bool | `true` | Because you can only install one Strimzi Operator helm chart in a cluster, we might as well set this to True. This allows the chart to be re-used (with `strimzi-kafka-operator.enabled: false`) by other local development projects. | | userName | string | `"user"` | Set the name of the KafkaUser that is created for local development | diff --git a/charts/local-kafka/README.md.gotmpl b/charts/local-kafka/README.md.gotmpl index 39319f7..ad4bc35 100644 --- a/charts/local-kafka/README.md.gotmpl +++ b/charts/local-kafka/README.md.gotmpl @@ -29,6 +29,32 @@ That will allow each project to install a local `Kafka` cluster and `KafkaUser` resource in the development namespace, completely isolated from the _other_ project's development namespace. +## Upgrade Notes + +### 0.42.x -> 0.43.x + +**NEW: Using KRaft mode instead of Zookeeper mode** + +By switching Strimzi to use [KRaft +mode](https://strimzi.io/blog/2024/03/22/strimzi-kraft-migration/) we reduce +the number of pods that have to start up locally and speed up the test process +because we do not have to wait for Zookeeper to start up. + +**NEW: Custom Pod Annotations** + +When installing the `local-kafka` chart as a dependency purely for testing, it +may be advantageous to add [Helm Chart +Hooks](https://helm.sh/docs/topics/charts_hooks/) that set the order in which +the pods start up. For example, if you want to make sure all of the Kafka pods +are up and ready before your own application pods start up: + +```yaml +# values.yaml +local-kafka: + podAnnotations: + "helm.sh/hook": pre-install +``` + {{ template "chart.requirementsSection" . }} {{ template "chart.valuesSection" . }} diff --git a/charts/local-kafka/ci/default-values.yaml b/charts/local-kafka/ci/default-values.yaml new file mode 120000 index 0000000..5d1191e --- /dev/null +++ b/charts/local-kafka/ci/default-values.yaml @@ -0,0 +1 @@ +../values.yaml \ No newline at end of file diff --git a/charts/local-kafka/ci/local-values.yaml b/charts/local-kafka/ci/local-values.yaml new file mode 120000 index 0000000..123e79e --- /dev/null +++ b/charts/local-kafka/ci/local-values.yaml @@ -0,0 +1 @@ +../values.local.yaml \ No newline at end of file diff --git a/charts/local-kafka/templates/kafka-node-pool.yaml b/charts/local-kafka/templates/kafka-node-pool.yaml index 9c880a3..2c5eeae 100644 --- a/charts/local-kafka/templates/kafka-node-pool.yaml +++ b/charts/local-kafka/templates/kafka-node-pool.yaml @@ -20,3 +20,10 @@ spec: size: 500Mi deleteClaim: false kraftMetadata: shared + {{- with .Values.podAnnotations }} + template: + pod: + metadata: + annotations: + {{- toYaml . | nindent 10 }} + {{- end }} diff --git a/charts/local-kafka/templates/kafka.yaml b/charts/local-kafka/templates/kafka.yaml index 3eead9c..0f3ddc4 100644 --- a/charts/local-kafka/templates/kafka.yaml +++ b/charts/local-kafka/templates/kafka.yaml @@ -60,3 +60,10 @@ spec: entityOperator: topicOperator: {} userOperator: {} + {{- with .Values.podAnnotations }} + template: + pod: + metadata: + annotations: + {{- toYaml . | nindent 14 }} + {{- end }} diff --git a/charts/local-kafka/values.local.yaml b/charts/local-kafka/values.local.yaml index e69de29..460d615 100644 --- a/charts/local-kafka/values.local.yaml +++ b/charts/local-kafka/values.local.yaml @@ -0,0 +1,2 @@ +podAnnotations: + testAnnotation: value diff --git a/charts/local-kafka/values.yaml b/charts/local-kafka/values.yaml index 2d99efd..b899150 100644 --- a/charts/local-kafka/values.yaml +++ b/charts/local-kafka/values.yaml @@ -9,6 +9,9 @@ clusterName: default # put into is used. It is recommended to keep this empty. namespaceOverride: +# -- Optional annotations added to all of the Strimzi-managed Pods. +podAnnotations: {} + # Settings that dictate the version of Kafka to run, message formats, etc. If # these are left out, then the _latest_ version is used by the Operator. kafka: From 3a90e28f82e59a217b063b0ee5ddb8b47bbc80c1 Mon Sep 17 00:00:00 2001 From: Matt Wise Date: Tue, 21 Jan 2025 13:25:47 -0800 Subject: [PATCH 3/6] tests --- charts/local-kafka/ci/helm-hook-values.yaml | 4 ++++ charts/local-kafka/values.local.yaml | 1 + 2 files changed, 5 insertions(+) create mode 100644 charts/local-kafka/ci/helm-hook-values.yaml diff --git a/charts/local-kafka/ci/helm-hook-values.yaml b/charts/local-kafka/ci/helm-hook-values.yaml new file mode 100644 index 0000000..7c46859 --- /dev/null +++ b/charts/local-kafka/ci/helm-hook-values.yaml @@ -0,0 +1,4 @@ +# Test that setting the helm.sh/hook annotations works as expected and the helm +# tests function +podAnnotations: + helm.sh/hook: pre-install diff --git a/charts/local-kafka/values.local.yaml b/charts/local-kafka/values.local.yaml index 460d615..ce79ff1 100644 --- a/charts/local-kafka/values.local.yaml +++ b/charts/local-kafka/values.local.yaml @@ -1,2 +1,3 @@ +# Example of setting custom pod annotations podAnnotations: testAnnotation: value From 75143f116385b3b7eac8b19615112c0ca27070cd Mon Sep 17 00:00:00 2001 From: Matt Wise Date: Tue, 21 Jan 2025 13:33:58 -0800 Subject: [PATCH 4/6] annotations --- charts/local-kafka/README.md | 5 +++-- charts/local-kafka/README.md.gotmpl | 4 ++-- charts/local-kafka/ci/helm-hook-values.yaml | 2 +- charts/local-kafka/templates/kafka-node-pool.yaml | 11 +++++++++-- charts/local-kafka/templates/kafka.yaml | 13 +++++++++---- charts/local-kafka/templates/user.yaml | 4 ++++ charts/local-kafka/values.local.yaml | 2 ++ charts/local-kafka/values.yaml | 3 +++ 8 files changed, 33 insertions(+), 11 deletions(-) diff --git a/charts/local-kafka/README.md b/charts/local-kafka/README.md index 40446c2..aedfa8e 100644 --- a/charts/local-kafka/README.md +++ b/charts/local-kafka/README.md @@ -52,8 +52,8 @@ are up and ready before your own application pods start up: ```yaml # values.yaml local-kafka: - podAnnotations: - "helm.sh/hook": pre-install + annotations: + helm.sh/hook: pre-install ``` ## Requirements @@ -66,6 +66,7 @@ local-kafka: | Key | Type | Default | Description | |-----|------|---------|-------------| +| annotations | object | `{}` | Optionall annotations added to all of the resources managed by this template. | | clusterName | string | `"default"` | Set the name of the Kafka Cluster that is created for local development | | kafka.brokerVersion | `str` | `nil` | Optional version of Kafka to install (eg, `2.8.0`) | | kafka.interBrokerProtocolVersion | `str` | `nil` | Optional value for the inter.broker.protocol.version property (eg. `2.8`) | diff --git a/charts/local-kafka/README.md.gotmpl b/charts/local-kafka/README.md.gotmpl index ad4bc35..95c8639 100644 --- a/charts/local-kafka/README.md.gotmpl +++ b/charts/local-kafka/README.md.gotmpl @@ -51,8 +51,8 @@ are up and ready before your own application pods start up: ```yaml # values.yaml local-kafka: - podAnnotations: - "helm.sh/hook": pre-install + annotations: + helm.sh/hook: pre-install ``` {{ template "chart.requirementsSection" . }} diff --git a/charts/local-kafka/ci/helm-hook-values.yaml b/charts/local-kafka/ci/helm-hook-values.yaml index 7c46859..799c9be 100644 --- a/charts/local-kafka/ci/helm-hook-values.yaml +++ b/charts/local-kafka/ci/helm-hook-values.yaml @@ -1,4 +1,4 @@ # Test that setting the helm.sh/hook annotations works as expected and the helm # tests function -podAnnotations: +annotations: helm.sh/hook: pre-install diff --git a/charts/local-kafka/templates/kafka-node-pool.yaml b/charts/local-kafka/templates/kafka-node-pool.yaml index 2c5eeae..b60c030 100644 --- a/charts/local-kafka/templates/kafka-node-pool.yaml +++ b/charts/local-kafka/templates/kafka-node-pool.yaml @@ -7,6 +7,10 @@ metadata: {{- end }} labels: strimzi.io/cluster: {{ .Values.clusterName }} + {{- with .Values.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} spec: replicas: 1 roles: @@ -20,10 +24,13 @@ spec: size: 500Mi deleteClaim: false kraftMetadata: shared - {{- with .Values.podAnnotations }} template: pod: metadata: annotations: + {{- with .Values.annotations }} {{- toYaml . | nindent 10 }} - {{- end }} + {{- end }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 10 }} + {{- end }} diff --git a/charts/local-kafka/templates/kafka.yaml b/charts/local-kafka/templates/kafka.yaml index 0f3ddc4..e7b7e97 100644 --- a/charts/local-kafka/templates/kafka.yaml +++ b/charts/local-kafka/templates/kafka.yaml @@ -1,4 +1,3 @@ -# https://github.com/strimzi/strimzi-kafka-operator/blob/master/examples/kafka/kafka-ephemeral.yaml apiVersion: kafka.strimzi.io/v1beta2 kind: Kafka metadata: @@ -9,6 +8,9 @@ metadata: annotations: strimzi.io/node-pools: enabled strimzi.io/kraft: enabled + {{- with .Values.annotations }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: kafka: {{- with .Values.kafka.brokerVersion }} @@ -60,10 +62,13 @@ spec: entityOperator: topicOperator: {} userOperator: {} - {{- with .Values.podAnnotations }} template: pod: metadata: annotations: - {{- toYaml . | nindent 14 }} - {{- end }} + {{- with .Values.annotations }} + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 12 }} + {{- end }} diff --git a/charts/local-kafka/templates/user.yaml b/charts/local-kafka/templates/user.yaml index 8472102..597717d 100644 --- a/charts/local-kafka/templates/user.yaml +++ b/charts/local-kafka/templates/user.yaml @@ -7,6 +7,10 @@ metadata: {{- end }} labels: strimzi.io/cluster: {{ .Values.clusterName }} + {{- with .Values.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} spec: authentication: type: tls diff --git a/charts/local-kafka/values.local.yaml b/charts/local-kafka/values.local.yaml index ce79ff1..865dc0b 100644 --- a/charts/local-kafka/values.local.yaml +++ b/charts/local-kafka/values.local.yaml @@ -1,3 +1,5 @@ # Example of setting custom pod annotations +annotations: + testAllAnnotations: value podAnnotations: testAnnotation: value diff --git a/charts/local-kafka/values.yaml b/charts/local-kafka/values.yaml index b899150..3ab6f4a 100644 --- a/charts/local-kafka/values.yaml +++ b/charts/local-kafka/values.yaml @@ -9,6 +9,9 @@ clusterName: default # put into is used. It is recommended to keep this empty. namespaceOverride: +# -- Optionall annotations added to all of the resources managed by this template. +annotations: {} + # -- Optional annotations added to all of the Strimzi-managed Pods. podAnnotations: {} From c749b28936bddf0b7af5d8bfffd6209fc9b2f3b2 Mon Sep 17 00:00:00 2001 From: Matt Wise Date: Tue, 21 Jan 2025 13:41:26 -0800 Subject: [PATCH 5/6] remove_comment --- charts/local-kafka/templates/kafka.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/charts/local-kafka/templates/kafka.yaml b/charts/local-kafka/templates/kafka.yaml index e7b7e97..b7ce04d 100644 --- a/charts/local-kafka/templates/kafka.yaml +++ b/charts/local-kafka/templates/kafka.yaml @@ -22,12 +22,6 @@ spec: priorityClassName: {{ . }} {{- end }} replicas: 1 - #livenessProbe: - # initialDelaySeconds: 60 - # failureThreshold: 30 # 30 * 10s - #readinessProbe: - # initialDelaySeconds: 60 - # failureThreshold: 30 # 30 * 10s authorization: type: simple superUsers: From 7ca4dc202e8f83814b2ed6905001b5d39ba2f766 Mon Sep 17 00:00:00 2001 From: Matt Wise Date: Tue, 21 Jan 2025 13:48:11 -0800 Subject: [PATCH 6/6] Typo --- charts/local-kafka/README.md | 2 +- charts/local-kafka/values.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/local-kafka/README.md b/charts/local-kafka/README.md index aedfa8e..77b01a4 100644 --- a/charts/local-kafka/README.md +++ b/charts/local-kafka/README.md @@ -66,7 +66,7 @@ local-kafka: | Key | Type | Default | Description | |-----|------|---------|-------------| -| annotations | object | `{}` | Optionall annotations added to all of the resources managed by this template. | +| annotations | object | `{}` | Optional annotations added to all of the resources managed by this template. | | clusterName | string | `"default"` | Set the name of the Kafka Cluster that is created for local development | | kafka.brokerVersion | `str` | `nil` | Optional version of Kafka to install (eg, `2.8.0`) | | kafka.interBrokerProtocolVersion | `str` | `nil` | Optional value for the inter.broker.protocol.version property (eg. `2.8`) | diff --git a/charts/local-kafka/values.yaml b/charts/local-kafka/values.yaml index 3ab6f4a..c873b47 100644 --- a/charts/local-kafka/values.yaml +++ b/charts/local-kafka/values.yaml @@ -9,7 +9,7 @@ clusterName: default # put into is used. It is recommended to keep this empty. namespaceOverride: -# -- Optionall annotations added to all of the resources managed by this template. +# -- Optional annotations added to all of the resources managed by this template. annotations: {} # -- Optional annotations added to all of the Strimzi-managed Pods.