| Giorgi Lekveishvili | 725bb39 | 2023-05-05 18:24:27 +0400 | [diff] [blame] | 1 | {{/* vim: set filetype=mustache: */}} |
| 2 | {{/* |
| 3 | Expand the name of the chart. |
| 4 | */}} |
| 5 | {{- define "ingress-nginx.name" -}} |
| 6 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} |
| 7 | {{- end -}} |
| 8 | |
| 9 | {{/* |
| 10 | Create chart name and version as used by the chart label. |
| 11 | */}} |
| 12 | {{- define "ingress-nginx.chart" -}} |
| 13 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} |
| 14 | {{- end -}} |
| 15 | |
| 16 | {{/* |
| 17 | Create a default fully qualified app name. |
| 18 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
| 19 | */}} |
| 20 | {{- define "ingress-nginx.fullname" -}} |
| 21 | {{- if .Values.fullnameOverride -}} |
| 22 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} |
| 23 | {{- else -}} |
| 24 | {{- $name := default .Chart.Name .Values.nameOverride -}} |
| 25 | {{- if contains $name .Release.Name -}} |
| 26 | {{- .Release.Name | trunc 63 | trimSuffix "-" -}} |
| 27 | {{- else -}} |
| 28 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} |
| 29 | {{- end -}} |
| 30 | {{- end -}} |
| 31 | {{- end -}} |
| 32 | |
| 33 | {{/* |
| 34 | Create a default fully qualified controller name. |
| 35 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
| 36 | */}} |
| 37 | {{- define "ingress-nginx.controller.fullname" -}} |
| 38 | {{- printf "%s-%s" (include "ingress-nginx.fullname" .) .Values.controller.name | trunc 63 | trimSuffix "-" -}} |
| 39 | {{- end -}} |
| 40 | |
| 41 | {{/* |
| 42 | Construct the path for the publish-service. |
| 43 | |
| 44 | By convention this will simply use the <namespace>/<controller-name> to match the name of the |
| 45 | service generated. |
| 46 | |
| 47 | Users can provide an override for an explicit service they want bound via `.Values.controller.publishService.pathOverride` |
| 48 | |
| 49 | */}} |
| 50 | {{- define "ingress-nginx.controller.publishServicePath" -}} |
| 51 | {{- $defServiceName := printf "%s/%s" "$(POD_NAMESPACE)" (include "ingress-nginx.controller.fullname" .) -}} |
| 52 | {{- $servicePath := default $defServiceName .Values.controller.publishService.pathOverride }} |
| 53 | {{- print $servicePath | trimSuffix "-" -}} |
| 54 | {{- end -}} |
| 55 | |
| 56 | {{/* |
| 57 | Create a default fully qualified default backend name. |
| 58 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
| 59 | */}} |
| 60 | {{- define "ingress-nginx.defaultBackend.fullname" -}} |
| 61 | {{- printf "%s-%s" (include "ingress-nginx.fullname" .) .Values.defaultBackend.name | trunc 63 | trimSuffix "-" -}} |
| 62 | {{- end -}} |
| 63 | |
| 64 | {{/* |
| 65 | Common labels |
| 66 | */}} |
| 67 | {{- define "ingress-nginx.labels" -}} |
| 68 | helm.sh/chart: {{ include "ingress-nginx.chart" . }} |
| 69 | {{ include "ingress-nginx.selectorLabels" . }} |
| 70 | {{- if .Chart.AppVersion }} |
| 71 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 72 | {{- end }} |
| 73 | app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 74 | {{- end -}} |
| 75 | |
| 76 | {{/* |
| 77 | Selector labels |
| 78 | */}} |
| 79 | {{- define "ingress-nginx.selectorLabels" -}} |
| 80 | app.kubernetes.io/name: {{ include "ingress-nginx.name" . }} |
| 81 | app.kubernetes.io/instance: {{ .Release.Name }} |
| 82 | {{- end -}} |
| 83 | |
| 84 | {{/* |
| 85 | Create the name of the controller service account to use |
| 86 | */}} |
| 87 | {{- define "ingress-nginx.serviceAccountName" -}} |
| 88 | {{- if .Values.serviceAccount.create -}} |
| 89 | {{ default (include "ingress-nginx.fullname" .) .Values.serviceAccount.name }} |
| 90 | {{- else -}} |
| 91 | {{ default "default" .Values.serviceAccount.name }} |
| 92 | {{- end -}} |
| 93 | {{- end -}} |
| 94 | |
| 95 | {{/* |
| 96 | Create the name of the backend service account to use - only used when podsecuritypolicy is also enabled |
| 97 | */}} |
| 98 | {{- define "ingress-nginx.defaultBackend.serviceAccountName" -}} |
| 99 | {{- if .Values.defaultBackend.serviceAccount.create -}} |
| 100 | {{ default (printf "%s-backend" (include "ingress-nginx.fullname" .)) .Values.defaultBackend.serviceAccount.name }} |
| 101 | {{- else -}} |
| 102 | {{ default "default-backend" .Values.defaultBackend.serviceAccount.name }} |
| 103 | {{- end -}} |
| 104 | {{- end -}} |
| 105 | |
| 106 | {{/* |
| 107 | Return the appropriate apiGroup for PodSecurityPolicy. |
| 108 | */}} |
| 109 | {{- define "podSecurityPolicy.apiGroup" -}} |
| 110 | {{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} |
| 111 | {{- print "policy" -}} |
| 112 | {{- else -}} |
| 113 | {{- print "extensions" -}} |
| 114 | {{- end -}} |
| 115 | {{- end -}} |
| 116 | |
| 117 | {{/* |
| 118 | Check the ingress controller version tag is at most three versions behind the last release |
| 119 | */}} |
| 120 | {{- define "isControllerTagValid" -}} |
| 121 | {{- if not (semverCompare ">=0.27.0-0" .Values.controller.image.tag) -}} |
| 122 | {{- fail "Controller container image tag should be 0.27.0 or higher" -}} |
| 123 | {{- end -}} |
| 124 | {{- end -}} |
| 125 | |
| 126 | {{/* |
| 127 | IngressClass parameters. |
| 128 | */}} |
| 129 | {{- define "ingressClass.parameters" -}} |
| 130 | {{- if .Values.controller.ingressClassResource.parameters -}} |
| 131 | parameters: |
| 132 | {{ toYaml .Values.controller.ingressClassResource.parameters | indent 4}} |
| 133 | {{ end }} |
| 134 | {{- end -}} |