Skip to content

Commit 0deeacb

Browse files
committed
javaooptions changes
1 parent c19f5e7 commit 0deeacb

File tree

4 files changed

+87
-20
lines changed

4 files changed

+87
-20
lines changed

chart/templates/backend-deployment.yaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,10 @@ spec:
145145
- name: SPRING_PROFILES_ACTIVE
146146
value: "prod,swagger,cluster"
147147
{{- if .Values.deployments.backend.extraEnvs }}
148-
{{- toYaml .Values.deployments.backend.extraEnvs | nindent 12 }}
149-
{{- if not (include "list-of-maps-contains" (list .Values.deployments.backend.extraEnvs "_JAVA_OPTIONS") ) }}
150-
- name: "_JAVA_OPTIONS"
151-
value: {{- toYaml (include "calculate-heap-size" .Values.deployments.backend) | nindent 21 }}
152-
{{- end }}
153-
{{- else }}
154-
- name: "_JAVA_OPTIONS"
155-
value: {{- toYaml (include "calculate-heap-size" .Values.deployments.backend) | nindent 21 }}
148+
{{- include "filter-out-java-options" .Values.deployments.backend.extraEnvs | nindent 12 }}
156149
{{- end }}
150+
- name: "_JAVA_OPTIONS"
151+
value: {{- toYaml (include "compose-java-options" (list .Values.deployments.backend (include "get-java-options-from-envs" .Values.deployments.backend.extraEnvs))) | nindent 21 }}
157152

158153
# waiting for mysql, rabbitmq and keycloak initialization
159154
initContainers:

chart/templates/crons/deployment.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,8 @@ spec:
140140
{{- if $mergedExtraEnvs }}
141141
{{ $mergedExtraEnvs | nindent 12 }}
142142
{{- end }}
143-
{{- if and (not (include "list-of-maps-contains" (list .Values.deployments.crons.extraEnvs "_JAVA_OPTIONS"))) (not (include "list-of-maps-contains" (list .Values.deployments.backend.extraEnvs "_JAVA_OPTIONS"))) }}
144143
- name: "_JAVA_OPTIONS"
145-
value: {{- toYaml (include "calculate-heap-size" (list .Values.deployments.crons 1 3)) | nindent 21 }}
146-
{{- end }}
144+
value: {{- toYaml (include "compose-java-options" (list .Values.deployments.crons (include "lightrun-crons.getMergedJavaOptions" .) 1 3)) | nindent 21 }}
147145

148146
# waiting for mysql, rabbitmq and keycloak initialization
149147
initContainers:

chart/templates/helpers/_helpers.tpl

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,63 @@ false
572572
{{- printf "-Xmx%vm -Xms%vm" $heap $xms -}}
573573
{{- end -}}
574574

575+
{{/*
576+
Build final JAVA options string according to the rules:
577+
- If user provided -Xms and/or -Xmx, use exactly what they provided and do not add the missing pair
578+
- If neither -Xms nor -Xmx were provided, calculate both and append any additional user options
579+
Usage:
580+
{{ include "compose-java-options" (list $deployment $userOptions) }}
581+
{{ include "compose-java-options" (list $deployment $userOptions 1 3) }} # with ratios
582+
*/}}
583+
{{- define "compose-java-options" -}}
584+
{{- $deployment := index . 0 -}}
585+
{{- $userOptions := index . 1 | default "" -}}
586+
{{- $xmsRatio := 1 -}}
587+
{{- $xmxRatio := 1 -}}
588+
{{- if ge (len .) 3 -}}
589+
{{- $xmsRatio = index . 2 | int -}}
590+
{{- end -}}
591+
{{- if ge (len .) 4 -}}
592+
{{- $xmxRatio = index . 3 | int -}}
593+
{{- end -}}
594+
{{- $hasXms := and $userOptions (contains "-Xms" $userOptions) -}}
595+
{{- $hasXmx := and $userOptions (contains "-Xmx" $userOptions) -}}
596+
{{- if or $hasXms $hasXmx -}}
597+
{{- $userOptions -}}
598+
{{- else -}}
599+
{{- $calculated := include "calculate-heap-size" (list $deployment $xmsRatio $xmxRatio) -}}
600+
{{- printf "%s %s" $calculated $userOptions | trim -}}
601+
{{- end -}}
602+
{{- end -}}
603+
604+
{{/* Extract JAVA options value from a list of env maps */}}
605+
{{- define "get-java-options-from-envs" -}}
606+
{{- $envs := . | default list -}}
607+
{{- $opts := "" -}}
608+
{{- range $envs -}}
609+
{{- if or (eq .name "_JAVA_OPTIONS") (eq .name "JAVA_OPTIONS") -}}
610+
{{- if .value -}}
611+
{{- $opts = .value -}}
612+
{{- end -}}
613+
{{- end -}}
614+
{{- end -}}
615+
{{- $opts -}}
616+
{{- end -}}
617+
618+
{{/* Return env list without any JAVA options entries */}}
619+
{{- define "filter-out-java-options" -}}
620+
{{- $envs := . | default list -}}
621+
{{- $out := list -}}
622+
{{- range $envs -}}
623+
{{- if and (ne .name "_JAVA_OPTIONS") (ne .name "JAVA_OPTIONS") -}}
624+
{{- $out = append $out . -}}
625+
{{- end -}}
626+
{{- end -}}
627+
{{- if $out -}}
628+
{{- toYaml $out -}}
629+
{{- end -}}
630+
{{- end -}}
631+
575632
{{- define "list-of-maps-contains" }}
576633
{{- $arg1 := index . 0 }}
577634
{{- $arg2 := index . 1 }}
@@ -852,7 +909,8 @@ Cron-specific asyncProfiler helpers
852909
{{- end -}}
853910

854911
{{/*
855-
Merge extraEnvs from backend and crons with crons taking precedence for duplicate keys
912+
Merge extraEnvs from backend and crons with crons taking precedence for duplicate keys.
913+
JAVA options are intentionally filtered out and should be added explicitly by templates.
856914
*/}}
857915
{{- define "lightrun-crons.mergedExtraEnvs" -}}
858916
{{- $backendExtraEnvs := .Values.deployments.backend.extraEnvs | default list -}}
@@ -871,13 +929,17 @@ Merge extraEnvs from backend and crons with crons taking precedence for duplicat
871929
{{- end -}}
872930
{{/* Only add backend env if not overridden by crons */}}
873931
{{- if not $isOverridden -}}
874-
{{- $mergedEnvs = append $mergedEnvs $backendEnv -}}
932+
{{- if and (ne $backendEnv.name "_JAVA_OPTIONS") (ne $backendEnv.name "JAVA_OPTIONS") -}}
933+
{{- $mergedEnvs = append $mergedEnvs $backendEnv -}}
934+
{{- end -}}
875935
{{- end -}}
876936
{{- end -}}
877937

878938
{{/* Then, add all crons extraEnvs (these take precedence) */}}
879939
{{- range $cronsExtraEnvs -}}
880-
{{- $mergedEnvs = append $mergedEnvs . -}}
940+
{{- if and (ne .name "_JAVA_OPTIONS") (ne .name "JAVA_OPTIONS") -}}
941+
{{- $mergedEnvs = append $mergedEnvs . -}}
942+
{{- end -}}
881943
{{- end -}}
882944

883945
{{/* Output merged envs as YAML if any exist */}}
@@ -886,6 +948,20 @@ Merge extraEnvs from backend and crons with crons taking precedence for duplicat
886948
{{- end -}}
887949
{{- end -}}
888950

951+
952+
{{/* Get merged JAVA options from backend+crons with crons taking precedence */}}
953+
{{- define "lightrun-crons.getMergedJavaOptions" -}}
954+
{{- $backendExtraEnvs := .Values.deployments.backend.extraEnvs | default list -}}
955+
{{- $cronsExtraEnvs := .Values.deployments.crons.extraEnvs | default list -}}
956+
{{- $opts := include "get-java-options-from-envs" $backendExtraEnvs -}}
957+
{{- $cronsOpts := include "get-java-options-from-envs" $cronsExtraEnvs -}}
958+
{{- if $cronsOpts -}}
959+
{{- $cronsOpts -}}
960+
{{- else -}}
961+
{{- $opts -}}
962+
{{- end -}}
963+
{{- end -}}
964+
889965
{{/*
890966
################
891967
### Datadog ###

chart/templates/keycloak-statefulset.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,11 @@ spec:
301301
- name: JAVASCRIPT_FILES
302302
value: js/keycloak.js
303303
{{- if .Values.deployments.keycloak.extraEnvs }}
304-
{{- toYaml .Values.deployments.keycloak.extraEnvs | nindent 12 }}
305-
{{- if not (include "list-of-maps-contains" (list .Values.deployments.keycloak.extraEnvs "_JAVA_OPTIONS") ) }}
304+
{{- include "filter-out-java-options" .Values.deployments.keycloak.extraEnvs | nindent 12 }}
305+
{{- end }}
306306
- name: "_JAVA_OPTIONS"
307-
value: {{- toYaml (include "calculate-heap-size" .Values.deployments.keycloak) | nindent 21 }}
308-
{{- end }}
307+
value: {{- toYaml (include "compose-java-options" (list .Values.deployments.keycloak (include "get-java-options-from-envs" .Values.deployments.keycloak.extraEnvs))) | nindent 21 }}
308+
{{- if .Values.deployments.keycloak.extraEnvs }}
309309
{{- if not (include "list-of-maps-contains" (list .Values.deployments.keycloak.extraEnvs "KC_HOSTNAME") ) }}
310310
{{- if semverCompare ">=1.38.0" $version }}
311311
- name: KC_HOSTNAME
@@ -316,8 +316,6 @@ spec:
316316
{{- end }}
317317
{{- end }}
318318
{{- else }}
319-
- name: "_JAVA_OPTIONS"
320-
value: {{- toYaml (include "calculate-heap-size" .Values.deployments.keycloak) | nindent 21 }}
321319
{{- if semverCompare ">=1.38.0" $version }}
322320
- name: KC_HOSTNAME
323321
value: 'https://{{ .Values.general.lightrun_endpoint }}/auth'

0 commit comments

Comments
 (0)