feat(common)!: Release version 1.0.0 (#68)

- Removed: **BREAKING**: Removed support for HorizontalPodAutoscaler
- Added: Support services have extraSelectorLabels (#58)
- Added: support for `httpGet` probes
- Added: support for setting labels / annotations on volumeClaimTemplates
- Changed: **BREAKING**: Restructure of template components. All Helm templates have been renamed / namespaced. E.g. `common.values.setup` has now become `bjw-s.common.loader.init`.
- Changed: **BREAKING**: Raised minimum supported k8s version to 1.22
- Changed: **BREAKING**: Renamed `configmap` key to `configMaps`
- Changed: **BREAKING**: Moved `serviceMonitor` from `service` to its own key
- Changed: **BREAKING**: Renamed `secret` key to `secrets`, which now works similar to `configMaps`
- Changed: Updated code-server image to v4.8.2
- Changed: Updated gluetun image to v3.32.0
- Fixed: Fix NOTES always showing ingress protocol as http (#62)

Signed-off-by: Gavin Mogan <git@gavinmogan.com>
Co-authored-by: Gavin Mogan <github@gavinmogan.com>
Co-authored-by: Gabe Cook <gabe565@gmail.com>
This commit is contained in:
Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs 2022-11-03 11:41:35 +01:00 committed by GitHub
parent 98ee81df4e
commit ae4233c77f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
94 changed files with 1126 additions and 976 deletions

View file

@ -1,19 +0,0 @@
{{/* Allow KubeVersion to be overridden. */}}
{{- define "common.capabilities.ingress.kubeVersion" -}}
{{- default .Capabilities.KubeVersion.Version .Values.kubeVersionOverride -}}
{{- end -}}
{{/* Return the appropriate apiVersion for Ingress objects */}}
{{- define "common.capabilities.ingress.apiVersion" -}}
{{- print "networking.k8s.io/v1" -}}
{{- if semverCompare "<1.19" (include "common.capabilities.ingress.kubeVersion" .) -}}
{{- print "beta1" -}}
{{- end -}}
{{- end -}}
{{/* Check Ingress stability */}}
{{- define "common.capabilities.ingress.isStable" -}}
{{- if eq (include "common.capabilities.ingress.apiVersion" .) "networking.k8s.io/v1" -}}
{{- true -}}
{{- end -}}
{{- end -}}

View file

@ -1,22 +0,0 @@
{{/* Common labels shared across objects */}}
{{- define "common.labels" -}}
helm.sh/chart: {{ include "common.names.chart" . }}
{{ include "common.labels.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.global.labels }}
{{- range $k, $v := . }}
{{- $name := $k }}
{{- $value := tpl $v $ }}
{{ $name }}: {{ quote $value }}
{{- end }}
{{- end }}
{{- end -}}
{{/* Selector labels shared across objects */}}
{{- define "common.labels.selectorLabels" -}}
app.kubernetes.io/name: {{ include "common.names.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

View file

@ -1,5 +1,5 @@
{{/* Expand the name of the chart */}}
{{- define "common.names.name" -}}
{{- define "bjw-s.common.lib.chart.names.name" -}}
{{- $globalNameOverride := "" -}}
{{- if hasKey .Values "global" -}}
{{- $globalNameOverride = (default $globalNameOverride .Values.global.nameOverride) -}}
@ -12,8 +12,8 @@ Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "common.names.fullname" -}}
{{- $name := include "common.names.name" . -}}
{{- define "bjw-s.common.lib.chart.names.fullname" -}}
{{- $name := include "bjw-s.common.lib.chart.names.name" . -}}
{{- $globalFullNameOverride := "" -}}
{{- if hasKey .Values "global" -}}
{{- $globalFullNameOverride = (default $globalFullNameOverride .Values.global.fullnameOverride) -}}
@ -31,28 +31,15 @@ If release name contains chart name it will be used as a full name.
{{- end -}}
{{/* Create chart name and version as used by the chart label */}}
{{- define "common.names.chart" -}}
{{- define "bjw-s.common.lib.chart.names.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/* Create the name of the ServiceAccount to use */}}
{{- define "common.names.serviceAccountName" -}}
{{- define "bjw-s.common.lib.chart.names.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{- default (include "common.names.fullname" .) .Values.serviceAccount.name -}}
{{- default (include "bjw-s.common.lib.chart.names.fullname" .) .Values.serviceAccount.name -}}
{{- else -}}
{{- default "default" .Values.serviceAccount.name -}}
{{- end -}}
{{- end -}}
{{/* Return the properly cased version of the controller type */}}
{{- define "common.names.controllerType" -}}
{{- if eq .Values.controller.type "deployment" -}}
{{- print "Deployment" -}}
{{- else if eq .Values.controller.type "daemonset" -}}
{{- print "DaemonSet" -}}
{{- else if eq .Values.controller.type "statefulset" -}}
{{- print "StatefulSet" -}}
{{- else -}}
{{- fail (printf "Not a valid controller.type (%s)" .Values.controller.type) -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,56 @@
{{/*
Default NOTES.txt content.
*/}}
{{- define "bjw-s.common.lib.chart.notes" -}}
{{- $primaryIngress := get .Values.ingress (include "bjw-s.common.lib.ingress.primary" .) -}}
{{- $primaryService := get .Values.service (include "bjw-s.common.lib.service.primary" .) -}}
{{- $primaryPort := "" -}}
{{- if $primaryService -}}
{{- $primaryPort = get $primaryService.ports (include "bjw-s.common.lib.service.primaryPort" (dict "serviceName" (include "bjw-s.common.lib.service.primary" .) "values" $primaryService)) -}}
{{- end -}}
{{- $prefix := "http" -}}
{{- if $primaryPort }}
{{- if hasKey $primaryPort "protocol" }}
{{- if eq $primaryPort.protocol "HTTPS" }}
{{- $prefix = "https" }}
{{- end }}
{{- end }}
{{- end }}
{{- if $primaryIngress }}
1. Access the application by visiting one of these URL's:
{{ range $primaryIngress.hosts }}
{{- $prefix = "http" -}}
{{ if $primaryIngress.tls -}}
{{- $prefix = "https" -}}
{{ end -}}
{{- $host := .host -}}
{{ if .hostTpl -}}
{{- $host = tpl .hostTpl $ -}}
{{ end }}
{{- $path := (first .paths).path | default "/" -}}
{{ if (first .paths).pathTpl -}}
{{- $path = tpl (first .paths).pathTpl $ -}}
{{ end }}
- {{ $prefix }}://{{- $host }}{{- $path }}
{{- end }}
{{- else if and $primaryService $primaryPort }}
1. Get the application URL by running these commands:
{{- if contains "NodePort" $primaryService.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "bjw-s.common.lib.chart.names.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo {{ $prefix }}://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" $primaryService.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ include "bjw-s.common.lib.chart.names.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "bjw-s.common.lib.chart.names.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo {{ $prefix }}://$SERVICE_IP:{{ $primaryPort.port }}
{{- else if contains "ClusterIP" $primaryService.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "bjw-s.common.lib.chart.names.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit {{ $prefix }}://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:{{ $primaryPort.port }}
{{- end }}
{{- end }}
{{- end -}}

View file

@ -1,9 +0,0 @@
{{/* Merge the local chart values and the common chart defaults */}}
{{- define "common.values.setup" -}}
{{- if .Values.common -}}
{{- $defaultValues := deepCopy .Values.common -}}
{{- $userValues := deepCopy (omit .Values "common") -}}
{{- $mergedValues := mustMergeOverwrite $defaultValues $userValues -}}
{{- $_ := set . "Values" (deepCopy $mergedValues) -}}
{{- end -}}
{{- end -}}

View file

@ -1,10 +1,10 @@
{{/*
Environment variables used by containers.
*/}}
{{- define "common.controller.env_vars" -}}
{{- define "bjw-s.common.lib.container.envVars" -}}
{{- $values := .Values.env -}}
{{- if hasKey . "ObjectValues" -}}
{{- with .ObjectValues.env -}}
{{- with .ObjectValues.envVars -}}
{{- $values = . -}}
{{- end -}}
{{- end -}}

View file

@ -1,7 +1,7 @@
{{/*
Ports included by the controller.
*/}}
{{- define "common.controller.ports" -}}
{{- define "bjw-s.common.lib.container.ports" -}}
{{- $ports := list -}}
{{- range .Values.service -}}
{{- if .enabled -}}

View file

@ -0,0 +1,47 @@
{{/*
Probes selection logic.
*/}}
{{- define "bjw-s.common.lib.container.probes" -}}
{{- $primaryService := get .Values.service (include "bjw-s.common.lib.service.primary" .) -}}
{{- $primaryPort := "" -}}
{{- if $primaryService -}}
{{- $primaryPort = get $primaryService.ports (include "bjw-s.common.lib.service.primaryPort" (dict "serviceName" (include "bjw-s.common.lib.service.primary" .) "values" $primaryService)) -}}
{{- end -}}
{{- range $probeName, $probe := .Values.probes }}
{{- if $probe.enabled -}}
{{- "" | nindent 0 }}
{{- $probeName }}Probe:
{{- if $probe.custom -}}
{{- $probe.spec | toYaml | nindent 2 }}
{{- else }}
{{- if and $primaryService $primaryPort -}}
{{- $probeType := "" -}}
{{- if eq $probe.type "AUTO" -}}
{{- $probeType = $primaryPort.protocol -}}
{{- else -}}
{{- $probeType = $probe.type | default "TCP" -}}
{{- end }}
{{- if or ( eq $probeType "HTTPS" ) ( eq $probeType "HTTP" ) -}}
httpGet:
path: {{ $probe.path }}
scheme: {{ $probeType }}
{{- else }}
tcpSocket:
{{- end }}
{{- if $probe.port }}
port: {{ ( tpl ( $probe.port | toString ) $ ) }}
{{- else if $primaryPort.targetPort }}
port: {{ $primaryPort.targetPort }}
{{- else }}
port: {{ $primaryPort.port }}
{{- end }}
initialDelaySeconds: {{ $probe.spec.initialDelaySeconds }}
failureThreshold: {{ $probe.spec.failureThreshold }}
timeoutSeconds: {{ $probe.spec.timeoutSeconds }}
periodSeconds: {{ $probe.spec.periodSeconds }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

View file

@ -1,5 +1,5 @@
{{/* Volumes included by the controller */}}
{{- define "common.controller.volumeMounts" -}}
{{- define "bjw-s.common.lib.container.volumeMounts" -}}
{{- range $persistenceIndex, $persistenceItem := .Values.persistence }}
{{- if $persistenceItem.enabled -}}
{{- if kindIs "slice" $persistenceItem.subPath -}}

View file

@ -1,6 +1,6 @@
{{- /* The main container included in the controller */ -}}
{{- define "common.controller.mainContainer" -}}
- name: {{ include "common.names.fullname" . }}
{{- define "bjw-s.common.lib.controller.mainContainer" -}}
- name: {{ include "bjw-s.common.lib.chart.names.fullname" . }}
image: {{ printf "%s:%s" .Values.image.repository (default .Chart.AppVersion .Values.image.tag) | quote }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.command }}
@ -36,7 +36,7 @@
{{- with .Values.env }}
env:
{{- get (fromYaml (include "common.controller.env_vars" $)) "env" | toYaml | nindent 4 -}}
{{- get (fromYaml (include "bjw-s.common.lib.container.envVars" $)) "env" | toYaml | nindent 4 -}}
{{- end }}
{{- if or .Values.envFrom .Values.secret }}
envFrom:
@ -45,16 +45,16 @@
{{- end }}
{{- if .Values.secret }}
- secretRef:
name: {{ include "common.names.fullname" . }}
name: {{ include "bjw-s.common.lib.chart.names.fullname" . }}
{{- end }}
{{- end }}
ports:
{{- include "common.controller.ports" . | trim | nindent 4 }}
{{- with (include "common.controller.volumeMounts" . | trim) }}
{{- include "bjw-s.common.lib.container.ports" . | trim | nindent 4 }}
{{- with (include "bjw-s.common.lib.container.volumeMounts" . | trim) }}
volumeMounts:
{{- nindent 4 . }}
{{- end }}
{{- include "common.controller.probes" . | trim | nindent 2 }}
{{- include "bjw-s.common.lib.container.probes" . | trim | nindent 2 }}
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 4 }}

View file

@ -0,0 +1,25 @@
{{- define "bjw-s.common.lib.controller.metadata.labels" -}}
{{-
$labels := (
merge
(.Values.controller.labels | default dict)
(include "bjw-s.common.lib.metadata.allLabels" $ | fromYaml)
)
-}}
{{- with $labels -}}
{{- toYaml . -}}
{{- end -}}
{{- end -}}
{{- define "bjw-s.common.lib.controller.metadata.annotations" -}}
{{-
$annotations := (
merge
(.Values.controller.annotations | default dict)
(include "bjw-s.common.lib.metadata.globalAnnotations" $ | fromYaml)
)
-}}
{{- with $annotations -}}
{{- toYaml . -}}
{{- end -}}
{{- end -}}

View file

@ -1,12 +1,12 @@
{{- /*
The pod definition included in the controller.
*/ -}}
{{- define "common.controller.pod" -}}
{{- define "bjw-s.common.lib.controller.pod" -}}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 2 }}
{{- end }}
serviceAccountName: {{ include "common.names.serviceAccountName" . }}
serviceAccountName: {{ include "bjw-s.common.lib.chart.names.serviceAccountName" . }}
automountServiceAccountToken: {{ .Values.automountServiceAccountToken }}
{{- with .Values.podSecurityContext }}
securityContext:
@ -51,9 +51,9 @@ initContainers:
{{- $_ := set $container "name" $key }}
{{- end }}
{{- if $container.env -}}
{{- $_ := set $ "ObjectValues" (dict "env" $container.env) -}}
{{- $newEnv := fromYaml (include "common.controller.env_vars" $) -}}
{{- $_ := unset $.ObjectValues "env" -}}
{{- $_ := set $ "ObjectValues" (dict "envVars" $container.env) -}}
{{- $newEnv := fromYaml (include "bjw-s.common.lib.container.envVars" $) -}}
{{- $_ := unset $.ObjectValues "envVars" -}}
{{- $_ := set $container "env" $newEnv.env }}
{{- end }}
{{- $initContainers = append $initContainers $container }}
@ -61,7 +61,7 @@ initContainers:
{{- tpl (toYaml $initContainers) $ | nindent 2 }}
{{- end }}
containers:
{{- include "common.controller.mainContainer" . | nindent 2 }}
{{- include "bjw-s.common.lib.controller.mainContainer" . | nindent 2 }}
{{- with .Values.additionalContainers }}
{{- $additionalContainers := list }}
{{- range $name, $container := . }}
@ -69,16 +69,16 @@ containers:
{{- $_ := set $container "name" $name }}
{{- end }}
{{- if $container.env -}}
{{- $_ := set $ "ObjectValues" (dict "env" $container.env) -}}
{{- $newEnv := fromYaml (include "common.controller.env_vars" $) -}}
{{- $_ := set $ "ObjectValues" (dict "envVars" $container.env) -}}
{{- $newEnv := fromYaml (include "bjw-s.common.lib.container.envVars" $) -}}
{{- $_ := set $container "env" $newEnv.env }}
{{- $_ := unset $.ObjectValues "env" -}}
{{- $_ := unset $.ObjectValues "envVars" -}}
{{- end }}
{{- $additionalContainers = append $additionalContainers $container }}
{{- end }}
{{- tpl (toYaml $additionalContainers) $ | nindent 2 }}
{{- end }}
{{- with (include "common.controller.volumes" . | trim) }}
{{- with (include "bjw-s.common.lib.controller.volumes" . | trim) }}
volumes:
{{- nindent 2 . }}
{{- end }}

View file

@ -1,33 +0,0 @@
{{/*
Probes selection logic.
*/}}
{{- define "common.controller.probes" -}}
{{- $primaryService := get .Values.service (include "common.service.primary" .) -}}
{{- $primaryPort := "" -}}
{{- if $primaryService -}}
{{- $primaryPort = get $primaryService.ports (include "common.classes.service.ports.primary" (dict "serviceName" (include "common.service.primary" .) "values" $primaryService)) -}}
{{- end -}}
{{- range $probeName, $probe := .Values.probes }}
{{- if $probe.enabled -}}
{{- "" | nindent 0 }}
{{- $probeName }}Probe:
{{- if $probe.custom -}}
{{- $probe.spec | toYaml | nindent 2 }}
{{- else }}
{{- if and $primaryService $primaryPort -}}
{{- "tcpSocket:" | nindent 2 }}
{{- if $primaryPort.targetPort }}
{{- printf "port: %v" $primaryPort.targetPort | nindent 4 }}
{{- else}}
{{- printf "port: %v" $primaryPort.port | nindent 4 }}
{{- end }}
{{- printf "initialDelaySeconds: %v" $probe.spec.initialDelaySeconds | nindent 2 }}
{{- printf "failureThreshold: %v" $probe.spec.failureThreshold | nindent 2 }}
{{- printf "timeoutSeconds: %v" $probe.spec.timeoutSeconds | nindent 2 }}
{{- printf "periodSeconds: %v" $probe.spec.periodSeconds | nindent 2 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

View file

@ -1,12 +1,12 @@
{{/*
Volumes included by the controller.
*/}}
{{- define "common.controller.volumes" -}}
{{- define "bjw-s.common.lib.controller.volumes" -}}
{{- range $index, $persistence := .Values.persistence }}
{{- if $persistence.enabled }}
- name: {{ $index }}
{{- if eq (default "pvc" $persistence.type) "pvc" }}
{{- $pvcName := (include "common.names.fullname" $) -}}
{{- $pvcName := (include "bjw-s.common.lib.chart.names.fullname" $) -}}
{{- if $persistence.existingClaim }}
{{- /* Always prefer an existingClaim if that is set */}}
{{- $pvcName = $persistence.existingClaim -}}
@ -14,10 +14,10 @@ Volumes included by the controller.
{{- /* Otherwise refer to the PVC name */}}
{{- if $persistence.nameOverride -}}
{{- if not (eq $persistence.nameOverride "-") -}}
{{- $pvcName = (printf "%s-%s" (include "common.names.fullname" $) $persistence.nameOverride) -}}
{{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $) $persistence.nameOverride) -}}
{{- end -}}
{{- else -}}
{{- $pvcName = (printf "%s-%s" (include "common.names.fullname" $) $index) -}}
{{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $) $index) -}}
{{- end -}}
{{- end }}
persistentVolumeClaim:

View file

@ -0,0 +1,21 @@
{{/* Return the name of the primary ingress object */}}
{{- define "bjw-s.common.lib.ingress.primary" -}}
{{- $enabledIngresses := dict -}}
{{- range $name, $ingress := .Values.ingress -}}
{{- if $ingress.enabled -}}
{{- $_ := set $enabledIngresses $name . -}}
{{- end -}}
{{- end -}}
{{- $result := "" -}}
{{- range $name, $ingress := $enabledIngresses -}}
{{- if and (hasKey $ingress "primary") $ingress.primary -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}
{{- if not $result -}}
{{- $result = keys $enabledIngresses | first -}}
{{- end -}}
{{- $result -}}
{{- end -}}

View file

@ -0,0 +1,10 @@
{{/* Common labels shared across objects */}}
{{- define "bjw-s.common.lib.metadata.allLabels" -}}
helm.sh/chart: {{ include "bjw-s.common.lib.chart.names.chart" . }}
{{ include "bjw-s.common.lib.metadata.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{ include "bjw-s.common.lib.metadata.globalLabels" . }}
{{- end -}}

View file

@ -0,0 +1,10 @@
{{/* Common annotations shared across objects */}}
{{- define "bjw-s.common.lib.metadata.globalAnnotations" -}}
{{- with .Values.global.annotations }}
{{- range $k, $v := . }}
{{- $name := $k }}
{{- $value := tpl $v $ }}
{{ $name }}: {{ quote $value }}
{{- end }}
{{- end }}
{{- end -}}

View file

@ -0,0 +1,9 @@
{{- define "bjw-s.common.lib.metadata.globalLabels" -}}
{{- with .Values.global.labels }}
{{- range $k, $v := . }}
{{- $name := $k }}
{{- $value := tpl $v $ }}
{{ $name }}: {{ quote $value }}
{{- end }}
{{- end }}
{{- end -}}

View file

@ -1,22 +1,11 @@
{{/* Common annotations shared across objects */}}
{{- define "common.annotations" -}}
{{- with .Values.global.annotations }}
{{- range $k, $v := . }}
{{- $name := $k }}
{{- $value := tpl $v $ }}
{{ $name }}: {{ quote $value }}
{{- end }}
{{- end }}
{{- end -}}
{{/* Determine the Pod annotations used in the controller */}}
{{- define "common.podAnnotations" -}}
{{- define "bjw-s.common.lib.metadata.podAnnotations" -}}
{{- if .Values.podAnnotations -}}
{{- tpl (toYaml .Values.podAnnotations) . | nindent 0 -}}
{{- end -}}
{{- $configMapsFound := dict -}}
{{- range $name, $configmap := .Values.configmap -}}
{{- range $name, $configmap := .Values.configMaps -}}
{{- if $configmap.enabled -}}
{{- $_ := set $configMapsFound $name (toYaml $configmap.data | sha256sum) -}}
{{- end -}}

View file

@ -0,0 +1,5 @@
{{/* Selector labels shared across objects */}}
{{- define "bjw-s.common.lib.metadata.selectorLabels" -}}
app.kubernetes.io/name: {{ include "bjw-s.common.lib.chart.names.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

View file

@ -0,0 +1,23 @@
{{/*
Return the primary service object
*/}}
{{- define "bjw-s.common.lib.service.primary" -}}
{{- $enabledServices := dict -}}
{{- range $name, $service := .Values.service -}}
{{- if $service.enabled -}}
{{- $_ := set $enabledServices $name . -}}
{{- end -}}
{{- end -}}
{{- $result := "" -}}
{{- range $name, $service := $enabledServices -}}
{{- if and (hasKey $service "primary") $service.primary -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}
{{- if not $result -}}
{{- $result = keys $enabledServices | first -}}
{{- end -}}
{{- $result -}}
{{- end -}}

View file

@ -0,0 +1,27 @@
{{/*
Return the primary port for a given Service object.
*/}}
{{- define "bjw-s.common.lib.service.primaryPort" -}}
{{- $enabledPorts := dict -}}
{{- range $name, $port := .values.ports -}}
{{- if $port.enabled -}}
{{- $_ := set $enabledPorts $name . -}}
{{- end -}}
{{- end -}}
{{- if eq 0 (len $enabledPorts) }}
{{- fail (printf "No ports are enabled for service \"%s\"!" .serviceName) }}
{{- end }}
{{- $result := "" -}}
{{- range $name, $port := $enabledPorts -}}
{{- if and (hasKey $port "primary") $port.primary -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}
{{- if not $result -}}
{{- $result = keys $enabledPorts | first -}}
{{- end -}}
{{- $result -}}
{{- end -}}