_helpers.tpl 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. Create chart name and version as used by the chart label.
  10. */}}
  11. {{- define "ingress-nginx.chart" -}}
  12. {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
  13. {{- end -}}
  14. {{/*
  15. Create a default fully qualified app name.
  16. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  17. */}}
  18. {{- define "ingress-nginx.fullname" -}}
  19. {{- if .Values.fullnameOverride -}}
  20. {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
  21. {{- else -}}
  22. {{- $name := default .Chart.Name .Values.nameOverride -}}
  23. {{- if contains $name .Release.Name -}}
  24. {{- .Release.Name | trunc 63 | trimSuffix "-" -}}
  25. {{- else -}}
  26. {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
  27. {{- end -}}
  28. {{- end -}}
  29. {{- end -}}
  30. {{/*
  31. Container SecurityContext.
  32. */}}
  33. {{- define "controller.containerSecurityContext" -}}
  34. {{- if .Values.controller.containerSecurityContext -}}
  35. {{- toYaml .Values.controller.containerSecurityContext -}}
  36. {{- else -}}
  37. capabilities:
  38. drop:
  39. - ALL
  40. add:
  41. - NET_BIND_SERVICE
  42. {{- if .Values.controller.image.chroot }}
  43. - SYS_CHROOT
  44. {{- end }}
  45. runAsUser: {{ .Values.controller.image.runAsUser }}
  46. allowPrivilegeEscalation: {{ .Values.controller.image.allowPrivilegeEscalation }}
  47. {{- end }}
  48. {{- end -}}
  49. {{/*
  50. Get specific image
  51. */}}
  52. {{- define "ingress-nginx.image" -}}
  53. {{- if .chroot -}}
  54. {{- printf "%s-chroot" .image -}}
  55. {{- else -}}
  56. {{- printf "%s" .image -}}
  57. {{- end }}
  58. {{- end -}}
  59. {{/*
  60. Get specific image digest
  61. */}}
  62. {{- define "ingress-nginx.imageDigest" -}}
  63. {{- if .chroot -}}
  64. {{- if .digestChroot -}}
  65. {{- printf "@%s" .digestChroot -}}
  66. {{- end }}
  67. {{- else -}}
  68. {{ if .digest -}}
  69. {{- printf "@%s" .digest -}}
  70. {{- end -}}
  71. {{- end -}}
  72. {{- end -}}
  73. {{/*
  74. Create a default fully qualified controller name.
  75. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  76. */}}
  77. {{- define "ingress-nginx.controller.fullname" -}}
  78. {{- printf "%s-%s" (include "ingress-nginx.fullname" .) .Values.controller.name | trunc 63 | trimSuffix "-" -}}
  79. {{- end -}}
  80. {{/*
  81. Construct a unique electionID.
  82. Users can provide an override for an explicit electionID if they want via `.Values.controller.electionID`
  83. */}}
  84. {{- define "ingress-nginx.controller.electionID" -}}
  85. {{- $defElectionID := printf "%s-leader" (include "ingress-nginx.fullname" .) -}}
  86. {{- $electionID := default $defElectionID .Values.controller.electionID -}}
  87. {{- print $electionID -}}
  88. {{- end -}}
  89. {{/*
  90. Construct the path for the publish-service.
  91. By convention this will simply use the <namespace>/<controller-name> to match the name of the
  92. service generated.
  93. Users can provide an override for an explicit service they want bound via `.Values.controller.publishService.pathOverride`
  94. */}}
  95. {{- define "ingress-nginx.controller.publishServicePath" -}}
  96. {{- $defServiceName := printf "%s/%s" "$(POD_NAMESPACE)" (include "ingress-nginx.controller.fullname" .) -}}
  97. {{- $servicePath := default $defServiceName .Values.controller.publishService.pathOverride }}
  98. {{- print $servicePath | trimSuffix "-" -}}
  99. {{- end -}}
  100. {{/*
  101. Create a default fully qualified default backend name.
  102. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  103. */}}
  104. {{- define "ingress-nginx.defaultBackend.fullname" -}}
  105. {{- printf "%s-%s" (include "ingress-nginx.fullname" .) .Values.defaultBackend.name | trunc 63 | trimSuffix "-" -}}
  106. {{- end -}}
  107. {{/*
  108. Common labels
  109. */}}
  110. {{- define "ingress-nginx.labels" -}}
  111. helm.sh/chart: {{ include "ingress-nginx.chart" . }}
  112. {{ include "ingress-nginx.selectorLabels" . }}
  113. {{- if .Chart.AppVersion }}
  114. app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
  115. {{- end }}
  116. app.kubernetes.io/part-of: {{ template "ingress-nginx.name" . }}
  117. app.kubernetes.io/managed-by: {{ .Release.Service }}
  118. {{- if .Values.commonLabels}}
  119. {{ toYaml .Values.commonLabels }}
  120. {{- end }}
  121. {{- end -}}
  122. {{/*
  123. Selector labels
  124. */}}
  125. {{- define "ingress-nginx.selectorLabels" -}}
  126. app.kubernetes.io/name: {{ include "ingress-nginx.name" . }}
  127. app.kubernetes.io/instance: {{ .Release.Name }}
  128. {{- end -}}
  129. {{/*
  130. Create the name of the controller service account to use
  131. */}}
  132. {{- define "ingress-nginx.serviceAccountName" -}}
  133. {{- if .Values.serviceAccount.create -}}
  134. {{ default (include "ingress-nginx.fullname" .) .Values.serviceAccount.name }}
  135. {{- else -}}
  136. {{ default "default" .Values.serviceAccount.name }}
  137. {{- end -}}
  138. {{- end -}}
  139. {{/*
  140. Create the name of the backend service account to use - only used when podsecuritypolicy is also enabled
  141. */}}
  142. {{- define "ingress-nginx.defaultBackend.serviceAccountName" -}}
  143. {{- if .Values.defaultBackend.serviceAccount.create -}}
  144. {{ default (printf "%s-backend" (include "ingress-nginx.fullname" .)) .Values.defaultBackend.serviceAccount.name }}
  145. {{- else -}}
  146. {{ default "default-backend" .Values.defaultBackend.serviceAccount.name }}
  147. {{- end -}}
  148. {{- end -}}
  149. {{/*
  150. Return the appropriate apiGroup for PodSecurityPolicy.
  151. */}}
  152. {{- define "podSecurityPolicy.apiGroup" -}}
  153. {{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
  154. {{- print "policy" -}}
  155. {{- else -}}
  156. {{- print "extensions" -}}
  157. {{- end -}}
  158. {{- end -}}
  159. {{/*
  160. Check the ingress controller version tag is at most three versions behind the last release
  161. */}}
  162. {{- define "isControllerTagValid" -}}
  163. {{- if not (semverCompare ">=0.27.0-0" .Values.controller.image.tag) -}}
  164. {{- fail "Controller container image tag should be 0.27.0 or higher" -}}
  165. {{- end -}}
  166. {{- end -}}
  167. {{/*
  168. IngressClass parameters.
  169. */}}
  170. {{- define "ingressClass.parameters" -}}
  171. {{- if .Values.controller.ingressClassResource.parameters -}}
  172. parameters:
  173. {{ toYaml .Values.controller.ingressClassResource.parameters | indent 4}}
  174. {{ end }}
  175. {{- end -}}