helm-charts/charts/library/common/templates/lib/service/_primaryForController.tpl
Bernd Schorgers 425f4428ab
fix(common): Release v3.0.3 (#291)
Co-authored-by: Gabe Cook <gabe565@gmail.com>
2024-03-13 14:26:40 +01:00

39 lines
1.6 KiB
Smarty

{{/*
Return the primary service object for a controller
*/}}
{{- define "bjw-s.common.lib.service.primaryForController" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerIdentifier := .controllerIdentifier -}}
{{- $identifier := "" -}}
{{- $result := dict -}}
{{- /* Loop over all enabled services */ -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if $enabledServices -}}
{{- /* We are only interested in services for the specified controller */ -}}
{{- $enabledServicesForController := dict -}}
{{- range $name, $service := $enabledServices -}}
{{- if eq $service.controller $controllerIdentifier -}}
{{- $_ := set $enabledServicesForController $name $service -}}
{{- end -}}
{{- end -}}
{{- range $name, $service := $enabledServicesForController -}}
{{- /* Determine the Service that has been marked as primary */ -}}
{{- if $service.primary -}}
{{- $identifier = $name -}}
{{- $result = $service -}}
{{- end -}}
{{- /* Return the first Service if none has been explicitly marked as primary */ -}}
{{- if not $result -}}
{{- $firstServiceKey := keys $enabledServicesForController | first -}}
{{- $result = get $enabledServicesForController $firstServiceKey -}}
{{- $identifier = $result.identifier -}}
{{- end -}}
{{- end -}}
{{- include "bjw-s.common.lib.service.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $result) -}}
{{- end -}}
{{- end -}}