Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,14 @@ jobs:
- uses: docker/setup-buildx-action@v3
# No login and no tags: this proves the Dockerfile still builds, nothing
# more. A broken build fails in review instead of on merge.
#
# Same platform list as publish. Building only one arch here would let an
# arch-specific break reach main and only surface at pod start on the
# other one — which is precisely how the amd64-only image shipped.
- uses: docker/build-push-action@v6
with:
context: operator
platforms: linux/amd64,linux/arm64
push: false
cache-from: type=gha

Expand Down Expand Up @@ -204,9 +209,15 @@ jobs:
type=raw,value=${{ steps.version.outputs.value }}
type=raw,value=latest,enable={{is_default_branch}}

# Both architectures, because "runs on the cluster" is not one platform.
# GKE nodes are amd64; every Apple-Silicon k3d dev cluster is arm64. With
# no platforms: this step built only the runner's arch, and the failure
# landed far from the cause — `no match for platform in manifest` at pod
# start, on a tag that pulls fine on the machine that published it.
- uses: docker/build-push-action@v6
with:
context: operator
platforms: linux/amd64,linux/arm64
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
20 changes: 10 additions & 10 deletions kafka/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@ To verify the service works:

3. **Connection Details**:

The bootstrap server address follows the pattern: `<composite-name>-kafka-bootstrap.kafka.svc:9092`

Get the bootstrap server:
Read the address off the claim — the composition publishes it, so there is nothing to assemble:

```bash
COMPOSITE_NAME=$(kubectl get kafkacluster kafka-test -n mimir -o jsonpath='{.spec.resourceRef.name}')
KAFKA_BOOTSTRAP="${COMPOSITE_NAME}-kafka-bootstrap.kafka.svc:9092"
echo $KAFKA_BOOTSTRAP
kubectl get kafkacluster kafka-test -n mimir -o jsonpath='{.status.bootstrapServers}'
```

It is also the `BOOTSTRAP` column of `kubectl get kafkaclusters`.

The address resolves to `<claim-name>-kafka-bootstrap.kafka.svc:9092`, because Strimzi resources are named after the claim. Prefer reading `status.bootstrapServers` anyway: it is the supported contract, whereas the pattern is an implementation detail. Do **not** derive the name from `spec.resourceRef.name` — that is the composite, which Crossplane suffixes randomly, and it is not what the cluster is called.

### Validation with Client

To verify connectivity, exec into one of the Kafka broker pods:

```bash
# Get composite name and broker pod (run all 3 lines)
COMPOSITE_NAME=$(kubectl get kafkacluster kafka-test -n mimir -o jsonpath='{.spec.resourceRef.name}')
KAFKA_POD=$(kubectl get pods -n kafka -l strimzi.io/cluster=$COMPOSITE_NAME,strimzi.io/broker-role=true -o jsonpath='{.items[0].metadata.name}')
# The Strimzi cluster is named after the CLAIM, so the label selector is just
# the claim name — no lookup needed (run both lines)
KAFKA_POD=$(kubectl get pods -n kafka -l strimzi.io/cluster=kafka-test,strimzi.io/broker-role=true -o jsonpath='{.items[0].metadata.name}')
echo "Using pod: $KAFKA_POD"

# List topics
Expand Down Expand Up @@ -103,7 +103,7 @@ kubectl exec -n kafka $KAFKA_POD -- \

External projects (like `Heimdall` or application projects) should treat this as a dependency.

1. **Define Dependency**: In your project's Helm chart or configuration, reference the expected bootstrap URL pattern.
1. **Define Dependency**: Read `status.bootstrapServers` off the claim rather than hardcoding an address. A committed manifest carrying a guessed cluster name is the failure this API exists to prevent — and a `KafkaTopic` whose `strimzi.io/cluster` label names a cluster that does not exist is silently ignored by Strimzi, so the mistake surfaces as missing topics with no error anywhere.
2. **Network Policies**: Ensure your namespace allows egress to `kafka`.
3. **Topics**: Use the Strimzi `KafkaTopic` CRD to create topics (managed by the Entity Operator).

Expand Down
64 changes: 59 additions & 5 deletions kafka/composition.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Strimzi resources are named from the CLAIM, not the composite.
#
# Crossplane derives a composite's name as <claim>-<random5>, so naming the
# Kafka cluster after the composite made it unpredictable and different after
# every teardown — `knarr-kafka-8r9tn` one time, `knarr-kafka-2wjjq` the next.
# Consumers cannot reference that: a KafkaTopic labelled with a cluster name
# that no longer exists is SILENTLY IGNORED by Strimzi, so a stale reference
# produces no topics and no error. Knarr shipped two committed files carrying
# a dead name for exactly this reason.
#
# spec.claimRef.name is stable for the life of the claim, so the cluster is now
# deterministically named and its bootstrap address is knowable in advance.
#
# CONSTRAINT this introduces: every Kafka cluster lands in the shared `kafka`
# namespace, so claim names must be unique ACROSS namespaces — two claims both
# called `events` in different namespaces would now collide where the random
# suffix used to hide it. Deliberate: one cluster per k8s cluster is the
# current expectation, and a predictable name is worth more than protection
# against a case that would itself be a naming mistake. Prefixing with the
# claim namespace would remove the constraint at the cost of every name.
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
Expand All @@ -19,10 +39,22 @@ spec:
source: Inline
inline:
template: |
{{- /*
Claim name when there is a claim; the composite's own name otherwise.
Both are stable, and the fallback is not a lesser case: Crossplane
appends the random suffix only when it creates a composite FOR a
claim, so a directly-created XKafkaCluster already carries the name
its author chose. Without the guard a claimless composite renders
`<no value>` into every resource name.
*/}}
{{- $name := .observed.composite.resource.metadata.name }}
{{- with .observed.composite.resource.spec.claimRef }}
{{- $name = .name }}
{{- end }}
apiVersion: kubernetes.crossplane.io/v1alpha2
kind: Object
metadata:
name: {{ .observed.composite.resource.metadata.name }}-kafka
name: {{ $name }}-kafka
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
annotations:
gotemplating.fn.crossplane.io/composition-resource-name: kafka-cluster
spec:
Expand All @@ -34,7 +66,7 @@ spec:
apiVersion: kafka.strimzi.io/v1beta2
kind: Kafka
metadata:
name: {{ .observed.composite.resource.metadata.name }}
name: {{ $name }}
namespace: kafka
annotations:
strimzi.io/kraft: "enabled"
Expand All @@ -60,6 +92,16 @@ spec:
entityOperator:
topicOperator: {}
userOperator: {}
---
# Publish the bootstrap address the XRD has always advertised. It was
# declared in the XRD's status schema and never populated, so the
# BOOTSTRAP printer column rendered empty and every consumer had to
# reassemble the string by hand from a name it could not predict.
# Reading it from status is now the supported way to find the cluster.
apiVersion: {{ .observed.composite.resource.apiVersion }}
kind: {{ .observed.composite.resource.kind }}
status:
bootstrapServers: {{ $name }}-kafka-bootstrap.kafka.svc:9092

- step: deploy-kafka-node-pool
functionRef:
Expand All @@ -70,10 +112,22 @@ spec:
source: Inline
inline:
template: |
{{- /*
Claim name when there is a claim; the composite's own name otherwise.
Both are stable, and the fallback is not a lesser case: Crossplane
appends the random suffix only when it creates a composite FOR a
claim, so a directly-created XKafkaCluster already carries the name
its author chose. Without the guard a claimless composite renders
`<no value>` into every resource name.
*/}}
{{- $name := .observed.composite.resource.metadata.name }}
{{- with .observed.composite.resource.spec.claimRef }}
{{- $name = .name }}
{{- end }}
apiVersion: kubernetes.crossplane.io/v1alpha2
kind: Object
metadata:
name: {{ .observed.composite.resource.metadata.name }}-nodepool
name: {{ $name }}-nodepool
annotations:
gotemplating.fn.crossplane.io/composition-resource-name: kafka-nodepool
spec:
Expand All @@ -85,10 +139,10 @@ spec:
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaNodePool
metadata:
name: {{ .observed.composite.resource.metadata.name }}-combined
name: {{ $name }}-combined
namespace: kafka
labels:
strimzi.io/cluster: {{ .observed.composite.resource.metadata.name }}
strimzi.io/cluster: {{ $name }}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
spec:
replicas: {{ .observed.composite.resource.spec.parameters.replicas }}
roles:
Expand Down
19 changes: 15 additions & 4 deletions operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Build the manager binary.
FROM golang:1.25 AS builder
#
# --platform=$BUILDPLATFORM pins the builder stage to the machine doing the
# building, so a linux/arm64 target cross-compiles natively instead of running
# the whole Go toolchain under QEMU. Without it a two-platform build is several
# minutes slower for no benefit — the Go compiler already emits any GOARCH.
FROM --platform=$BUILDPLATFORM golang:1.25 AS builder
WORKDIR /workspace

# Dependencies first, so a source-only change reuses the module layer.
Expand All @@ -11,9 +16,15 @@ COPY api/ api/
COPY internal/ internal/

# CGO off and a static link: the runtime image has no libc to link against.
# TARGETOS/TARGETARCH come from buildx so the same file cross-builds.
ARG TARGETOS=linux
ARG TARGETARCH=amd64
#
# TARGETOS/TARGETARCH are declared WITHOUT defaults on purpose. BuildKit
# populates both automatically for any build, so a default is never needed —
# and `=amd64` was actively harmful: it won over the host platform, so a plain
# `docker build` on an arm64 machine produced an amd64 binary inside an
# arm64-labelled image. That fails at exec time with a confusing error rather
# than at build time with an honest one.
ARG TARGETOS
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -a -trimpath -ldflags="-s -w" -o manager cmd/main.go

Expand Down
Loading