| Sketch🕴️ | 620d57b | 2025-07-31 22:31:14 +0400 | [diff] [blame^] | 1 | {{/* |
| 2 | Copyright Broadcom, Inc. All Rights Reserved. |
| 3 | SPDX-License-Identifier: APACHE-2.0 |
| 4 | */}} |
| 5 | |
| 6 | {{/* vim: set filetype=mustache: */}} |
| 7 | {{/* |
| 8 | Return the proper NGINX image name |
| 9 | */}} |
| 10 | {{- define "nginx.image" -}} |
| 11 | {{ include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) }} |
| 12 | {{- end -}} |
| 13 | |
| 14 | {{/* |
| 15 | Return the proper GIT image name |
| 16 | */}} |
| 17 | {{- define "nginx.cloneStaticSiteFromGit.image" -}} |
| 18 | {{ include "common.images.image" (dict "imageRoot" .Values.cloneStaticSiteFromGit.image "global" .Values.global) }} |
| 19 | {{- end -}} |
| 20 | |
| 21 | {{/* |
| 22 | Return the proper Prometheus metrics image name |
| 23 | */}} |
| 24 | {{- define "nginx.metrics.image" -}} |
| 25 | {{ include "common.images.image" (dict "imageRoot" .Values.metrics.image "global" .Values.global) }} |
| 26 | {{- end -}} |
| 27 | |
| 28 | {{/* |
| 29 | Return the proper Docker Image Registry Secret Names |
| 30 | */}} |
| 31 | {{- define "nginx.imagePullSecrets" -}} |
| 32 | {{ include "common.images.renderPullSecrets" (dict "images" (list .Values.image .Values.cloneStaticSiteFromGit.image .Values.metrics.image) "context" $) }} |
| 33 | {{- end -}} |
| 34 | |
| 35 | {{/* |
| 36 | Return true if a static site should be mounted in the NGINX container |
| 37 | */}} |
| 38 | {{- define "nginx.useStaticSite" -}} |
| 39 | {{- if or .Values.cloneStaticSiteFromGit.enabled .Values.staticSiteConfigmap .Values.staticSitePVC }} |
| 40 | {- true -}} |
| 41 | {{- end -}} |
| 42 | {{- end -}} |
| 43 | |
| 44 | {{/* |
| 45 | Return the volume to use to mount the static site in the NGINX container |
| 46 | */}} |
| 47 | {{- define "nginx.staticSiteVolume" -}} |
| 48 | {{- if .Values.cloneStaticSiteFromGit.enabled }} |
| 49 | emptyDir: {} |
| 50 | {{- else if .Values.staticSiteConfigmap }} |
| 51 | configMap: |
| 52 | name: {{ printf "%s" (tpl .Values.staticSiteConfigmap $) -}} |
| 53 | {{- else if .Values.staticSitePVC }} |
| 54 | persistentVolumeClaim: |
| 55 | claimName: {{ printf "%s" (tpl .Values.staticSitePVC $) -}} |
| 56 | {{- end }} |
| 57 | {{- end -}} |
| 58 | |
| 59 | {{/* |
| 60 | Return the custom NGINX server block configmap. |
| 61 | */}} |
| 62 | {{- define "nginx.serverBlockConfigmapName" -}} |
| 63 | {{- if .Values.existingServerBlockConfigmap -}} |
| 64 | {{- printf "%s" (tpl .Values.existingServerBlockConfigmap $) -}} |
| 65 | {{- else -}} |
| 66 | {{- printf "%s-server-block" (include "common.names.fullname" .) -}} |
| 67 | {{- end -}} |
| 68 | {{- end -}} |
| 69 | |
| 70 | {{/* |
| 71 | Return the custom NGINX stream server block configmap. |
| 72 | */}} |
| 73 | {{- define "nginx.streamServerBlockConfigmapName" -}} |
| 74 | {{- if .Values.existingStreamServerBlockConfigmap -}} |
| 75 | {{- printf "%s" (tpl .Values.existingStreamServerBlockConfigmap $) -}} |
| 76 | {{- else -}} |
| 77 | {{- printf "%s-stream-server-block" (include "common.names.fullname" .) -}} |
| 78 | {{- end -}} |
| 79 | {{- end -}} |
| 80 | |
| 81 | {{/* |
| 82 | Compile all warnings into a single message, and call fail. |
| 83 | */}} |
| 84 | {{- define "nginx.validateValues" -}} |
| 85 | {{- $messages := list -}} |
| 86 | {{- $messages := append $messages (include "nginx.validateValues.cloneStaticSiteFromGit" .) -}} |
| 87 | {{- $messages := append $messages (include "nginx.validateValues.extraVolumes" .) -}} |
| 88 | {{- $messages := without $messages "" -}} |
| 89 | {{- $message := join "\n" $messages -}} |
| 90 | |
| 91 | {{- if $message -}} |
| 92 | {{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}} |
| 93 | {{- end -}} |
| 94 | {{- end -}} |
| 95 | |
| 96 | {{/* Validate values of NGINX - Clone StaticSite from Git configuration */}} |
| 97 | {{- define "nginx.validateValues.cloneStaticSiteFromGit" -}} |
| 98 | {{- if and .Values.cloneStaticSiteFromGit.enabled (or (not .Values.cloneStaticSiteFromGit.repository) (not .Values.cloneStaticSiteFromGit.branch)) -}} |
| 99 | nginx: cloneStaticSiteFromGit |
| 100 | When enabling cloing a static site from a Git repository, both the Git repository and the Git branch must be provided. |
| 101 | Please provide them by setting the `cloneStaticSiteFromGit.repository` and `cloneStaticSiteFromGit.branch` parameters. |
| 102 | {{- end -}} |
| 103 | {{- end -}} |
| 104 | |
| 105 | {{/* Validate values of NGINX - Incorrect extra volume settings */}} |
| 106 | {{- define "nginx.validateValues.extraVolumes" -}} |
| 107 | {{- if and (.Values.extraVolumes) (not (or .Values.extraVolumeMounts .Values.cloneStaticSiteFromGit.extraVolumeMounts)) -}} |
| 108 | nginx: missing-extra-volume-mounts |
| 109 | You specified extra volumes but not mount points for them. Please set |
| 110 | the extraVolumeMounts value |
| 111 | {{- end -}} |
| 112 | {{- end -}} |
| 113 | |
| 114 | {{/* |
| 115 | Create the name of the service account to use |
| 116 | */}} |
| 117 | {{- define "nginx.serviceAccountName" -}} |
| 118 | {{- if .Values.serviceAccount.create -}} |
| 119 | {{ default (include "common.names.fullname" .) .Values.serviceAccount.name }} |
| 120 | {{- else -}} |
| 121 | {{ default "default" .Values.serviceAccount.name }} |
| 122 | {{- end -}} |
| 123 | {{- end -}} |