helm-charts/charts/library/common/templates/lib/routes/_autoDetectService.tpl
2025-06-11 14:09:46 +00:00

21 lines
760 B
Smarty

{{/*
Autodetects the service for a Route object
*/}}
{{- define "bjw-s.common.lib.route.autoDetectService" -}}
{{- $rootContext := .rootContext -}}
{{- $routeObject := .object -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- if eq 1 (len $enabledServices) -}}
{{- range $routeObject.rules -}}
{{- range .backendRefs }}
{{- $backendRef := . -}}
{{- if and (empty (dig "name" nil $backendRef)) (empty (dig "identifier" nil $backendRef)) -}}
{{- $_ := set $backendRef "identifier" ($enabledServices | keys | first) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $routeObject | toYaml -}}
{{- end -}}