From a909b733ead2fc646b5816ea91aa468978da3174 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Tue, 13 Oct 2026 07:28:46 +0300 Subject: [PATCH] chore(kafka, kafka-operator): drop the JVM sizing workaround The workaround passed MaxRAM and ActiveProcessorCount to every Strimzi JVM because the JDK 17 in the 0.45 images could not see the container limits on kernels without CONFIG_MEMCG_V1 (JDK-8347811). The Strimzi 1.2.0 images ship JDK 21.0.12, which carries the fix. On such a kernel, with a 1Gi limit, Strimzi's heap probe in the Kafka image now estimates a 495M maximum heap, where the 0.45.1-rc1 image estimated 13.9G. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- packages/apps/kafka/templates/_jvm.tpl | 20 ----- packages/apps/kafka/templates/kafka.yaml | 11 +-- .../apps/kafka/templates/migration-hook.yaml | 11 --- .../apps/kafka/tests/jvm_sizing_test.yaml | 83 ------------------- packages/system/kafka-operator/Makefile | 3 - .../kafka-operator/tests/jvm_sizing_test.yaml | 31 ------- packages/system/kafka-operator/values.yaml | 16 ---- 7 files changed, 1 insertion(+), 174 deletions(-) delete mode 100644 packages/apps/kafka/templates/_jvm.tpl delete mode 100644 packages/apps/kafka/tests/jvm_sizing_test.yaml delete mode 100644 packages/system/kafka-operator/tests/jvm_sizing_test.yaml diff --git a/packages/apps/kafka/templates/_jvm.tpl b/packages/apps/kafka/templates/_jvm.tpl deleted file mode 100644 index 6b541ef63..000000000 --- a/packages/apps/kafka/templates/_jvm.tpl +++ /dev/null @@ -1,20 +0,0 @@ -{{- /* - JAVA_TOOL_OPTIONS for a Strimzi-managed container, from its resource limits. - The JDK 17 in the Strimzi images cannot see the container limits on kernels - built without CONFIG_MEMCG_V1 (JDK-8347811) and sizes itself from the host: - Strimzi's heap probe then hands every broker up to a 5Gi heap. Every java in - the container reads this variable, the probe included, so Strimzi's own - heap rules work again. jvmOptions -XX would not do: Strimzi moves those into - KAFKA_JVM_PERFORMANCE_OPTS, and kafka-run-class.sh drops its G1 tuning when - that variable is set. ActiveProcessorCount only when the chart sets a CPU - limit: a default a LimitRange adds at admission is not visible here, and - Strimzi template env takes no resourceFieldRef, so such a JVM still counts - the host CPUs. -*/ -}} -{{- define "kafka.javaToolOptions" -}} -{{- $opts := list (printf "-XX:MaxRAM=%d" (include "cozy-lib.resources.toFloat" .memory | float64 | int64)) -}} -{{- with .cpu -}} -{{- $opts = append $opts (printf "-XX:ActiveProcessorCount=%d" (include "cozy-lib.resources.toFloat" . | float64 | ceil | int64)) -}} -{{- end -}} -{{- join " " $opts -}} -{{- end -}} diff --git a/packages/apps/kafka/templates/kafka.yaml b/packages/apps/kafka/templates/kafka.yaml index e1b5dc0ed..b7039ace1 100644 --- a/packages/apps/kafka/templates/kafka.yaml +++ b/packages/apps/kafka/templates/kafka.yaml @@ -80,8 +80,7 @@ spec: # The topic-operator and user-operator are JVM processes and OOMKill at # that default, leaving the entity-operator in CrashLoopBackOff so # KafkaTopics/KafkaUsers never reconcile. Set explicit resources so they - # don't inherit the namespace default. JAVA_TOOL_OPTIONS: see - # kafka.javaToolOptions. + # don't inherit the namespace default. topicOperator: resources: requests: @@ -107,11 +106,3 @@ spec: labels: policy.cozystack.io/allow-to-apiserver: "true" enableServiceLinks: false - topicOperatorContainer: - env: - - name: JAVA_TOOL_OPTIONS - value: {{ include "kafka.javaToolOptions" (dict "memory" $entityOperatorMemory) | quote }} - userOperatorContainer: - env: - - name: JAVA_TOOL_OPTIONS - value: {{ include "kafka.javaToolOptions" (dict "memory" $entityOperatorMemory) | quote }} diff --git a/packages/apps/kafka/templates/migration-hook.yaml b/packages/apps/kafka/templates/migration-hook.yaml index 646a6ae1d..5c9e95032 100644 --- a/packages/apps/kafka/templates/migration-hook.yaml +++ b/packages/apps/kafka/templates/migration-hook.yaml @@ -107,12 +107,6 @@ spec: roles: - broker resources: {{- include "cozy-lib.resources.defaultingSanitize" (list .Values.kafka.resourcesPreset .Values.kafka.resources $) | nindent 18 }} - # JAVA_TOOL_OPTIONS: see kafka.javaToolOptions. - template: - kafkaContainer: - env: - - name: JAVA_TOOL_OPTIONS - value: {{ include "kafka.javaToolOptions" (include "cozy-lib.resources.defaultingSanitize" (list .Values.kafka.resourcesPreset .Values.kafka.resources $) | fromYaml).limits | quote }} storage: type: jbod volumes: @@ -152,11 +146,6 @@ spec: roles: - controller resources: {{- include "cozy-lib.resources.defaultingSanitize" (list .Values.kafka.resourcesPreset .Values.kafka.resources $) | nindent 18 }} - template: - kafkaContainer: - env: - - name: JAVA_TOOL_OPTIONS - value: {{ include "kafka.javaToolOptions" (include "cozy-lib.resources.defaultingSanitize" (list .Values.kafka.resourcesPreset .Values.kafka.resources $) | fromYaml).limits | quote }} storage: type: jbod volumes: diff --git a/packages/apps/kafka/tests/jvm_sizing_test.yaml b/packages/apps/kafka/tests/jvm_sizing_test.yaml deleted file mode 100644 index 223131814..000000000 --- a/packages/apps/kafka/tests/jvm_sizing_test.yaml +++ /dev/null @@ -1,83 +0,0 @@ -suite: Kafka JVMs are sized from their container limits - -templates: - - templates/migration-hook.yaml - - templates/kafka.yaml - -release: - name: test-kafka - namespace: tenant-test - -tests: - - it: passes the default preset limits to every node pool JVM - template: templates/migration-hook.yaml - documentIndex: 3 - asserts: - - matchRegex: - path: spec.template.spec.containers[0].args[0] - pattern: "release-namespace: \\$\\{ns\\}\\s+spec:\\s+replicas: \\d+\\s+roles:\\s+- broker\\s+resources:\\s+limits:(\\s+\\S+: \\S+)+\\s+requests:(\\s+\\S+: \\S+)+(\\s+#[^\\n]*)*\\s+template:\\s+kafkaContainer:\\s+env:\\s+- name: JAVA_TOOL_OPTIONS\\s+value: \"-XX:MaxRAM=1073741824 -XX:ActiveProcessorCount=1\"\\s+storage:" - - matchRegex: - path: spec.template.spec.containers[0].args[0] - pattern: "roles:\\s+- controller\\s+resources:\\s+limits:(\\s+\\S+: \\S+)+\\s+requests:(\\s+\\S+: \\S+)+(\\s+#[^\\n]*)*\\s+template:\\s+kafkaContainer:\\s+env:\\s+- name: JAVA_TOOL_OPTIONS\\s+value: \"-XX:MaxRAM=1073741824 -XX:ActiveProcessorCount=1\"\\s+storage:" - - # Strimzi moves jvmOptions -XX into KAFKA_JVM_PERFORMANCE_OPTS, and - # kafka-run-class.sh then drops its G1 settings. - - it: leaves the node pool JVM options to Strimzi and Kafka - template: templates/migration-hook.yaml - documentSelector: - path: kind - value: Job - asserts: - - notMatchRegex: - path: spec.template.spec.containers[0].args[0] - pattern: "jvmOptions" - - - it: rounds a fractional CPU limit up - template: templates/migration-hook.yaml - documentIndex: 3 - set: - kafka.resources: - cpu: 2500m - memory: 3Gi - asserts: - - matchRegex: - path: spec.template.spec.containers[0].args[0] - pattern: "roles:\\s+- controller\\s+resources:\\s+limits:(\\s+\\S+: \\S+)+\\s+requests:(\\s+\\S+: \\S+)+(\\s+#[^\\n]*)*\\s+template:\\s+kafkaContainer:\\s+env:\\s+- name: JAVA_TOOL_OPTIONS\\s+value: \"-XX:MaxRAM=3221225472 -XX:ActiveProcessorCount=3\"\\s+storage:" - - - it: takes the limits, not the requests, when the allocation ratios shrink the requests - template: templates/migration-hook.yaml - documentIndex: 3 - set: - _cluster: - cpu-allocation-ratio: "4" - memory-allocation-ratio: "2" - kafka.resources: - cpu: "2" - memory: 2Gi - asserts: - - matchRegex: - path: spec.template.spec.containers[0].args[0] - pattern: "release-namespace: \\$\\{ns\\}\\s+spec:\\s+replicas: \\d+\\s+roles:\\s+- broker\\s+resources:\\s+limits:(\\s+\\S+: \\S+)+\\s+requests:(\\s+\\S+: \\S+)+(\\s+#[^\\n]*)*\\s+template:\\s+kafkaContainer:\\s+env:\\s+- name: JAVA_TOOL_OPTIONS\\s+value: \"-XX:MaxRAM=2147483648 -XX:ActiveProcessorCount=2\"\\s+storage:" - - matchRegex: - path: spec.template.spec.containers[0].args[0] - pattern: "roles:\\s+- controller\\s+resources:\\s+limits:(\\s+\\S+: \\S+)+\\s+requests:(\\s+\\S+: \\S+)+(\\s+#[^\\n]*)*\\s+template:\\s+kafkaContainer:\\s+env:\\s+- name: JAVA_TOOL_OPTIONS\\s+value: \"-XX:MaxRAM=2147483648 -XX:ActiveProcessorCount=2\"\\s+storage:" - - - it: passes the entity operator memory limit to its JVMs - template: templates/kafka.yaml - asserts: - - equal: - path: spec.entityOperator.topicOperator.resources.limits.memory - value: 512Mi - - equal: - path: spec.entityOperator.template.topicOperatorContainer.env - value: - - name: JAVA_TOOL_OPTIONS - value: -XX:MaxRAM=536870912 - - equal: - path: spec.entityOperator.userOperator.resources.limits.memory - value: 512Mi - - equal: - path: spec.entityOperator.template.userOperatorContainer.env - value: - - name: JAVA_TOOL_OPTIONS - value: -XX:MaxRAM=536870912 diff --git a/packages/system/kafka-operator/Makefile b/packages/system/kafka-operator/Makefile index fb8122538..592b653a3 100644 --- a/packages/system/kafka-operator/Makefile +++ b/packages/system/kafka-operator/Makefile @@ -3,9 +3,6 @@ export NAMESPACE=cozy-$(NAME) include ../../../hack/package.mk -test: - helm unittest . - update: rm -rf charts helm pull oci://quay.io/strimzi-helm/strimzi-kafka-operator --untar --untardir charts --version 1.2.0 diff --git a/packages/system/kafka-operator/tests/jvm_sizing_test.yaml b/packages/system/kafka-operator/tests/jvm_sizing_test.yaml deleted file mode 100644 index e72a9a657..000000000 --- a/packages/system/kafka-operator/tests/jvm_sizing_test.yaml +++ /dev/null @@ -1,31 +0,0 @@ -suite: cluster operator JVM is sized from the container limits -release: - name: kafka-operator - namespace: cozy-kafka-operator -templates: - - charts/strimzi-kafka-operator/templates/060-Deployment-strimzi-cluster-operator.yaml -tests: - - it: passes the container limits to the JVM, which cannot read them on kernels without cgroup v1 controllers - asserts: - # $(VAR) expands only from entries earlier in the list. - - equal: - path: spec.template.spec.containers[0].env[19] - value: - name: CONTAINER_MEMORY_LIMIT - valueFrom: - resourceFieldRef: - resource: limits.memory - - equal: - path: spec.template.spec.containers[0].env[20] - value: - name: CONTAINER_CPU_LIMIT - valueFrom: - resourceFieldRef: - resource: limits.cpu - - equal: - path: spec.template.spec.containers[0].env[21] - value: - name: JAVA_OPTS - value: -XX:MaxRAM=$(CONTAINER_MEMORY_LIMIT) -XX:ActiveProcessorCount=$(CONTAINER_CPU_LIMIT) - - exists: - path: spec.template.spec.containers[0].resources.limits.cpu diff --git a/packages/system/kafka-operator/values.yaml b/packages/system/kafka-operator/values.yaml index 8fb5509ad..ddfa2c9b8 100644 --- a/packages/system/kafka-operator/values.yaml +++ b/packages/system/kafka-operator/values.yaml @@ -5,19 +5,3 @@ strimzi-kafka-operator: resources: limits: memory: 512Mi - # The JDK 17 in the operator image decides whether to read the container - # limits by looking at /proc/cgroups, which loses its memory line on kernels - # built without CONFIG_MEMCG_V1 (6.12+). The JVM then sizes its heap from - # host RAM and the container is OOMKilled. Drop this once the image ships a - # JDK with JDK-8347811 (17.0.20, 21.0.10). - extraEnvs: - - name: CONTAINER_MEMORY_LIMIT - valueFrom: - resourceFieldRef: - resource: limits.memory - - name: CONTAINER_CPU_LIMIT - valueFrom: - resourceFieldRef: - resource: limits.cpu - - name: JAVA_OPTS - value: -XX:MaxRAM=$(CONTAINER_MEMORY_LIMIT) -XX:ActiveProcessorCount=$(CONTAINER_CPU_LIMIT)