feat: Implictly set BACKEND_HOSTNAME for frontend if backend ingress is enabled.

Closes #37
This commit is contained in:
Skyler Mäntysaari 2025-03-29 13:12:35 +02:00
parent 7ef0f91785
commit 2dcb426d0b
2 changed files with 19 additions and 7 deletions

View File

@ -1,7 +1,17 @@
{{- if .Values.frontend.env }}
{{- $envVar := .Values.frontend.env.BACKEND_HOSTNAME }}
{{ else if .Values.ingress.main.enabled }}
{{- $envVar := index (index .Values.ingress.main.hosts 0) "host" }}
{{- else }}
{{- fail "Frontend container environment is missing a required variable BACKEND_HOSTNAME or main ingress is not enabled." .Values.frontend.env }}
{{- define "frontend.configValidation" }}
{{- $envVar := "" }}
{{- if .Values.frontend.env }}
{{- $envVar = .Values.frontend.env.BACKEND_HOSTNAME }}
{{- else if .Values.ingress.backend.enabled }}
{{- if (and (hasKey .Values.ingress.backend "hosts") (gt (len .Values.ingress.backend.hosts) 0)) }}
{{- $envVar = index (index .Values.ingress.backend.hosts 0) "host" }}
{{- end }}
{{- else if .Values.ingress.main.enabled }}
{{- if (and (hasKey .Values.ingress.main "hosts") (gt (len .Values.ingress.main.hosts) 0)) }}
{{- $envVar = index (index .Values.ingress.main.hosts 0) "host" }}
{{- end }}
{{- else }}
{{- fail "Frontend container environment is missing a required variable BACKEND_HOSTNAME, main or backend ingress is not enabled." .Values.frontend.env }}
{{- end }}
{{- $envVar }} # Return the value of $envVar
{{- end }}

View File

@ -2,7 +2,9 @@
Environment variables used by containers.
*/}}
{{- define "frontend.controller.env_vars" -}}
{{- $values := merge .Values.frontend.env -}}
{{- $envVar := include "frontend.configValidation" . | trim | quote }}
{{- $values := merge .Values.frontend.env (dict "BACKEND_HOSTNAME" $envVar) -}}
{{- if hasKey . "ObjectValues" -}}
{{- with .ObjectValues.env -}}
{{- $values = . -}}