Skip to content

Commit

Permalink
fix: make kafka support headless svc/pod ip/nodeport network types (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
caiq1nyu authored Jan 23, 2025
1 parent 405b6f9 commit 264ee44
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
11 changes: 0 additions & 11 deletions addons-cluster/kafka/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ Define kafka broker component name
{{- end }}
{{- end }}

{{/*
Define kafka cluster annotation keys for nodeport feature gate.
*/}}
{{- define "kafka-cluster.brokerAddrFeatureGate" -}}
kubeblocks.io/enabled-pod-ordinal-svc: broker
{{- if .Values.nodePortEnabled }}
kubeblocks.io/enabled-node-port-svc: broker
kubeblocks.io/disabled-cluster-ip-svc: broker
{{- end }}
{{- end }}

{{/*
Define kafka-exporter resources
*/}}
Expand Down
16 changes: 6 additions & 10 deletions addons-cluster/kafka/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ metadata:
name: {{ include "kblib.clusterName" . }}
namespace: {{ .Release.Namespace }}
labels: {{ include "kblib.clusterLabels" . | nindent 4 }}
{{/*
annotations:
*/}}
{{/* {{- include "kafka-cluster.brokerAddrFeatureGate" . | nindent 4 }}*/}}
spec:
clusterDef: kafka # ref clusterdefinition.name
terminationPolicy: {{ .Values.extra.terminationPolicy }}
Expand Down Expand Up @@ -38,10 +34,10 @@ spec:
- name: KB_KAFKA_CONTROLLER_HEAP
value: "{{ .Values.controllerHeap }}"
- name: KB_BROKER_DIRECT_POD_ACCESS
{{- if .Values.nodePortEnabled }}
value: "false"
{{- else }}
{{- if .Values.fixedPodIPEnabled }}
value: "true"
{{- else }}
value: "false"
{{- end }}
{{- if .Values.storageEnable }}
volumeClaimTemplates:
Expand Down Expand Up @@ -87,10 +83,10 @@ spec:
- name: KB_KAFKA_CONTROLLER_HEAP
value: "{{ .Values.controllerHeap }}"
- name: KB_BROKER_DIRECT_POD_ACCESS
{{- if .Values.nodePortEnabled }}
value: "false"
{{- else }}
{{- if .Values.fixedPodIPEnabled }}
value: "true"
{{- else }}
value: "false"
{{- end }}
{{- if .Values.storageEnable }}
volumeClaimTemplates:
Expand Down
8 changes: 7 additions & 1 deletion addons-cluster/kafka/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,13 @@
"type": "boolean",
"default": false,
"title": "nodePortEnabled",
"description":"Whether NodePort service is enabled, default is false"
"description":"Whether to enable NodePort mode in Kafka's `advertised.listeners`"
},
"fixedPodIPEnabled": {
"type": "boolean",
"default": false,
"title": "fixedPodIPEnabled",
"description":"Whether to enable fixed Pod IP mode in Kafka's `advertised.listeners`"
}
}
}
9 changes: 8 additions & 1 deletion addons-cluster/kafka/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,11 @@ brokerHeap: -XshowSettings:vm -XX:MaxRAMPercentage=100 -Ddepth=64
controllerHeap: -XshowSettings:vm -XX:MaxRAMPercentage=100 -Ddepth=64

## @param nodePortEnabled
nodePortEnabled: false
## Whether to enable NodePort mode.
## If set to true, Kafka's `advertised.listeners` will use the NodePort address, suitable for scenarios where clients are outside the Kubernetes cluster but can access the NodePort.
nodePortEnabled: false

## @param fixedPodIPEnabled
## Whether to enable fixed Pod IP mode.
## If set to true, Kafka's `advertised.listeners` will use the Pod IP address, suitable for scenarios where clients can directly communicate with the Kafka Pod's network.
fixedPodIPEnabled: false
4 changes: 2 additions & 2 deletions addons/kafka/templates/clusterdefinition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ spec:
compDef: {{ include "kafka-broker.cmpdRegexpPattern" . }}
orders:
provision:
- kafka-broker
- kafka-controller
- kafka-broker
terminate:
- kafka-controller
- kafka-broker
- kafka-controller
update:
- kafka-broker
- kafka-controller
Expand Down
7 changes: 5 additions & 2 deletions examples/kafka/cluster-combined.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ spec:
value: "-XshowSettings:vm -XX:MaxRAMPercentage=100 -Ddepth=64"
- name: KB_KAFKA_CONTROLLER_HEAP # use this ENV to set CONTOLLER_HEAP
value: "-XshowSettings:vm -XX:MaxRAMPercentage=100 -Ddepth=64"
- name: KB_BROKER_DIRECT_POD_ACCESS # set to FALSE for node-port
value: "true"
# Whether to enable direct Pod IP address access mode.
# - If set to 'true', Kafka clients will connect to Brokers using the Pod IP address directly.
# - If set to 'false', Kafka clients will connect to Brokers using the Headless Service's FQDN.
- name: KB_BROKER_DIRECT_POD_ACCESS
value: "false"
# Update `replicas` to your need.
replicas: 1
# Specifies the resources required by the Component.
Expand Down

0 comments on commit 264ee44

Please sign in to comment.