Skip to content

Commit

Permalink
feat(local-kafka): switch to kraft, start faster, allow annotations (#…
Browse files Browse the repository at this point in the history
…355)

## Goal

The goal for this PR is to improve the usability of the `local-kafka`
chart by reducing its startup time, introducing podAnnotations and
removing old legacy settings:

### Change: Removed legacy startup/readiness probe delays

We no longer see the Strimzi Operator take minutes to start up on M1
laptops, so I am removing the arbitrary startup/readiness probe delays.

### Change: Replace Zookeeper with KRaft

Strimzi is moving to removing Zookeeper entirely in the 0.46.0 release
anyways ... this change gets our local testing setup that way ahead of
the change. This also reduces the number of pods that have to run
locally, reducing the total startup time of a full testing environment.

### Change: Introduce `podAnnotations` and `annotations` settings

If you set `.Values.podAnnotations: { ... }` now we will add these
annotations to the Kafka and Entity Operator pods. This makes it easier
to tell Helm to start these pods up before the rest of the tested
resources get created.

---------

Co-authored-by: Matt Wise <[email protected]>
  • Loading branch information
diranged and diranged authored Jan 21, 2025
1 parent 783dcbd commit 5ec9117
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 40 deletions.
4 changes: 2 additions & 2 deletions charts/local-kafka/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
dependencies:
- name: strimzi-kafka-operator
version: 0.42.0
version: 0.45.0
repository: https://strimzi.io/charts
condition: strimzi-kafka-operator.enabled
36 changes: 31 additions & 5 deletions charts/local-kafka/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -30,31 +30,57 @@ 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:
annotations:
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
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| 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`) |
| kafka.logMessageFormatVersion | `str` | `nil` | Optional value for the log.message.format.version property (eg, `2.7`) |
| 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 |
Expand Down
26 changes: 26 additions & 0 deletions charts/local-kafka/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
annotations:
helm.sh/hook: pre-install
```

{{ template "chart.requirementsSection" . }}

{{ template "chart.valuesSection" . }}
Expand Down
1 change: 1 addition & 0 deletions charts/local-kafka/ci/default-values.yaml
4 changes: 4 additions & 0 deletions charts/local-kafka/ci/helm-hook-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Test that setting the helm.sh/hook annotations works as expected and the helm
# tests function
annotations:
helm.sh/hook: pre-install
1 change: 1 addition & 0 deletions charts/local-kafka/ci/local-values.yaml
36 changes: 36 additions & 0 deletions charts/local-kafka/templates/kafka-node-pool.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaNodePool
metadata:
name: {{ .Values.clusterName }}
{{- with .Values.namespaceOverride }}
namespace: {{ . }}
{{- end }}
labels:
strimzi.io/cluster: {{ .Values.clusterName }}
{{- with .Values.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
replicas: 1
roles:
- controller
- broker
storage:
type: jbod
volumes:
- id: 0
type: persistent-claim
size: 500Mi
deleteClaim: false
kraftMetadata: shared
template:
pod:
metadata:
annotations:
{{- with .Values.annotations }}
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 10 }}
{{- end }}
36 changes: 16 additions & 20 deletions charts/local-kafka/templates/kafka.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# https://github.com/strimzi/strimzi-kafka-operator/blob/master/examples/kafka/kafka-ephemeral.yaml
apiVersion: kafka.strimzi.io/v1beta2
kind: Kafka
metadata:
name: {{ .Values.clusterName }}
{{- with .Values.namespaceOverride }}
namespace: {{ . }}
{{- end }}
annotations:
strimzi.io/node-pools: enabled
strimzi.io/kraft: enabled
{{- with .Values.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
kafka:
{{- with .Values.kafka.brokerVersion }}
Expand All @@ -17,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:
Expand Down Expand Up @@ -54,19 +53,16 @@ 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: {}
template:
pod:
metadata:
annotations:
{{- with .Values.annotations }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 12 }}
{{- end }}
4 changes: 4 additions & 0 deletions charts/local-kafka/templates/user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ metadata:
{{- end }}
labels:
strimzi.io/cluster: {{ .Values.clusterName }}
{{- with .Values.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
authentication:
type: tls
Expand Down
5 changes: 5 additions & 0 deletions charts/local-kafka/values.local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Example of setting custom pod annotations
annotations:
testAllAnnotations: value
podAnnotations:
testAnnotation: value
23 changes: 10 additions & 13 deletions charts/local-kafka/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ clusterName: default
# put into is used. It is recommended to keep this empty.
namespaceOverride:

# -- Optional annotations added to all of the resources managed by this template.
annotations: {}

# -- 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:
Expand Down Expand Up @@ -63,19 +69,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
Expand Down

0 comments on commit 5ec9117

Please sign in to comment.