From 2dcb426d0b0ae7d56784d8b08b14ee52c857d99e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Skyler=20M=C3=A4ntysaari?= Date: Sat, 29 Mar 2025 13:12:35 +0200 Subject: [PATCH] feat: Implictly set BACKEND_HOSTNAME for frontend if backend ingress is enabled. Closes #37 --- .../templates/frontend/config-validator.yaml | 22 ++++++++++++++----- .../templates/frontend/lib/_env_vars.tpl | 4 +++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/charts/apps/piped/templates/frontend/config-validator.yaml b/charts/apps/piped/templates/frontend/config-validator.yaml index a46c60a..d99a5ea 100644 --- a/charts/apps/piped/templates/frontend/config-validator.yaml +++ b/charts/apps/piped/templates/frontend/config-validator.yaml @@ -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 }} \ No newline at end of file diff --git a/charts/apps/piped/templates/frontend/lib/_env_vars.tpl b/charts/apps/piped/templates/frontend/lib/_env_vars.tpl index 308d4fe..88ff1ef 100644 --- a/charts/apps/piped/templates/frontend/lib/_env_vars.tpl +++ b/charts/apps/piped/templates/frontend/lib/_env_vars.tpl @@ -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 = . -}}