@@ -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 ###
0 commit comments