|
| 1 | +{{/* |
| 2 | +Expand the name of the chart. |
| 3 | +*/}} |
| 4 | +{{- define "replicated.name" -}} |
| 5 | +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} |
| 6 | +{{- end }} |
| 7 | + |
| 8 | +{{/* |
| 9 | +Create chart name and version as used by the chart label. |
| 10 | +*/}} |
| 11 | +{{- define "replicated.chart" -}} |
| 12 | +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} |
| 13 | +{{- end }} |
| 14 | + |
| 15 | +{{/* |
| 16 | +Allow the release namespace to be overridden for multi-namespace deployments. |
| 17 | +*/}} |
| 18 | +{{- define "replicated.namespace" -}} |
| 19 | +{{- if .Values.namespaceOverride -}} |
| 20 | +{{- .Values.namespaceOverride -}} |
| 21 | +{{- else -}} |
| 22 | +{{- .Release.Namespace -}} |
| 23 | +{{- end -}} |
| 24 | +{{- end -}} |
| 25 | + |
| 26 | +{{/* |
| 27 | +Common labels |
| 28 | +*/}} |
| 29 | +{{- define "replicated.labels" -}} |
| 30 | +helm.sh/chart: {{ include "replicated.chart" . }} |
| 31 | +{{ include "replicated.selectorLabels" . }} |
| 32 | +{{- if .Chart.AppVersion }} |
| 33 | +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 34 | +{{- end }} |
| 35 | +app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 36 | +{{- with .Values.commonLabels }} |
| 37 | +{{- toYaml . | nindent 0 }} |
| 38 | +{{- end }} |
| 39 | +{{- end }} |
| 40 | + |
| 41 | +{{/* |
| 42 | +Pod Labels |
| 43 | +*/}} |
| 44 | +{{- define "replicated.podLabels" -}} |
| 45 | +{{- with .Values.podLabels }} |
| 46 | +{{- toYaml . | nindent 0 }} |
| 47 | +{{- end }} |
| 48 | +{{- end }} |
| 49 | + |
| 50 | +{{/* |
| 51 | +Selector labels |
| 52 | +*/}} |
| 53 | +{{- define "replicated.selectorLabels" -}} |
| 54 | +app.kubernetes.io/name: {{ include "replicated.name" . }} |
| 55 | +app.kubernetes.io/instance: {{ .Release.Name }} |
| 56 | +{{- end }} |
| 57 | + |
| 58 | +{{/* |
| 59 | +Image |
| 60 | +*/}} |
| 61 | +{{- define "replicated.image" -}} |
| 62 | +{{- $registryName := default .Values.image.registry ((.Values.global).imageRegistry) -}} |
| 63 | +{{- $repositoryName := .Values.image.repository -}} |
| 64 | +{{- $separator := ":" -}} |
| 65 | +{{- $termination := "" -}} |
| 66 | + |
| 67 | +{{- if not $repositoryName -}} |
| 68 | + {{- fail "Image repository is required but not set" -}} |
| 69 | +{{- end -}} |
| 70 | + |
| 71 | +{{- if .Values.image.tag -}} |
| 72 | + {{- $termination = .Values.image.tag | toString -}} |
| 73 | +{{- else if .Chart -}} |
| 74 | + {{- $termination = .Chart.AppVersion | default "latest" | toString -}} |
| 75 | +{{- else -}} |
| 76 | + {{- $termination = "latest" -}} |
| 77 | +{{- end -}} |
| 78 | + |
| 79 | +{{- if $registryName -}} |
| 80 | + {{- printf "%s/%s%s%s" $registryName $repositoryName $separator $termination -}} |
| 81 | +{{- else -}} |
| 82 | + {{- printf "%s%s%s" $repositoryName $separator $termination -}} |
| 83 | +{{- end -}} |
| 84 | +{{- end -}} |
| 85 | + |
| 86 | +{{/* |
| 87 | +License Fields |
| 88 | +*/}} |
| 89 | +{{- define "replicated.licenseFields" -}} |
| 90 | + {{- if (((.Values.global).replicated).licenseFields) -}} |
| 91 | + {{- .Values.global.replicated.licenseFields | toYaml -}} |
| 92 | + {{- else if .Values.licenseFields -}} |
| 93 | + {{- .Values.licenseFields | toYaml -}} |
| 94 | + {{- end -}} |
| 95 | +{{- end -}} |
| 96 | + |
| 97 | +{{/* |
| 98 | +Detect if we're running on OpenShift |
| 99 | +*/}} |
| 100 | +{{- define "replicated.isOpenShift" -}} |
| 101 | +{{- $isOpenShift := false }} |
| 102 | +{{- range .Capabilities.APIVersions -}} |
| 103 | + {{- if hasPrefix "apps.openshift.io/" . -}} |
| 104 | + {{- $isOpenShift = true }} |
| 105 | + {{- end -}} |
| 106 | +{{- end -}} |
| 107 | +{{- $isOpenShift }} |
| 108 | +{{- end -}} |
| 109 | +
|
| 110 | +{{/* |
| 111 | +Resource Names |
| 112 | +*/}} |
| 113 | +{{- define "replicated.deploymentName" -}} |
| 114 | + {{ include "replicated.name" . }} |
| 115 | +{{- end -}} |
| 116 | +
|
| 117 | +{{- define "replicated.roleName" -}} |
| 118 | + {{ include "replicated.name" . }}-role |
| 119 | +{{- end -}} |
| 120 | +
|
| 121 | +{{- define "replicated.roleBindingName" -}} |
| 122 | + {{ include "replicated.name" . }}-rolebinding |
| 123 | +{{- end -}} |
| 124 | +
|
| 125 | +{{- define "replicated.serviceName" -}} |
| 126 | + {{ include "replicated.name" . }} |
| 127 | +{{- end -}} |
| 128 | +
|
| 129 | +{{- define "replicated.serviceAccountName" -}} |
| 130 | + {{ .Values.serviceAccountName | default (include "replicated.name" .) }} |
| 131 | +{{- end -}} |
| 132 | +
|
| 133 | +{{- define "replicated.supportBundleName" -}} |
| 134 | + {{ include "replicated.name" . }}-supportbundle |
| 135 | +{{- end -}} |
| 136 | +
|
| 137 | +{{/* |
| 138 | +Get the Replicated App Endpoint |
| 139 | +*/}} |
| 140 | +{{- define "replicated.appEndpoint" -}} |
| 141 | +{{- if .Values.replicatedAppDomain -}} |
| 142 | + {{- printf "https://%s" .Values.replicatedAppDomain -}} |
| 143 | +{{- else if .Values.replicatedAppEndpoint -}} |
| 144 | + {{- .Values.replicatedAppEndpoint -}} |
| 145 | +{{- else -}} |
| 146 | + {{- printf "https://replicated.app" -}} |
| 147 | +{{- end -}} |
| 148 | +{{- end -}} |
| 149 | +
|
| 150 | +{{/* |
| 151 | +Return the proper container image |
| 152 | +This helper handles both the legacy .Values.images format and the new |
| 153 | +structured .Values.image format, selecting the appropriate one based on what's defined. |
| 154 | +*/}} |
| 155 | +{{- define "replicated.containerImage" -}} |
| 156 | +{{- if .Values.images -}} |
| 157 | + {{- index .Values.images "replicated-sdk" -}} |
| 158 | +{{- else -}} |
| 159 | + {{- include "replicated.image" . -}} |
| 160 | +{{- end -}} |
| 161 | +{{- end -}} |
| 162 | + |
| 163 | +{{/* |
| 164 | +Return the proper image pull policy |
| 165 | +*/}} |
| 166 | +{{- define "replicated.imagePullPolicy" -}} |
| 167 | +{{- if .Values.images -}} |
| 168 | + {{- print "IfNotPresent" -}} |
| 169 | +{{- else -}} |
| 170 | + {{- .Values.image.pullPolicy | default "IfNotPresent" -}} |
| 171 | +{{- end -}} |
| 172 | +{{- end -}} |
| 173 | + |
| 174 | +{{/* |
| 175 | +Process pod security context for OpenShift compatibility |
| 176 | +*/}} |
| 177 | +{{- define "replicated.podSecurityContext" -}} |
| 178 | +{{- $isOpenShift := eq (include "replicated.isOpenShift" .) "true" }} |
| 179 | +{{- $podSecurityContext := .Values.podSecurityContext | deepCopy }} |
| 180 | +{{- if $podSecurityContext }} |
| 181 | +{{- if $isOpenShift }} |
| 182 | + {{- if eq ($podSecurityContext.runAsUser | int) 1001 }} |
| 183 | + {{- $_ := unset $podSecurityContext "runAsUser" }} |
| 184 | + {{- end }} |
| 185 | + {{- if eq ($podSecurityContext.runAsGroup | int) 1001 }} |
| 186 | + {{- $_ := unset $podSecurityContext "runAsGroup" }} |
| 187 | + {{- end }} |
| 188 | + {{- if eq ($podSecurityContext.fsGroup | int) 1001 }} |
| 189 | + {{- $_ := unset $podSecurityContext "fsGroup" }} |
| 190 | + {{- end }} |
| 191 | + {{- if $podSecurityContext.supplementalGroups }} |
| 192 | + {{- $hasOnly1001 := true }} |
| 193 | + {{- range $podSecurityContext.supplementalGroups }} |
| 194 | + {{- if ne (. | int) 1001 }} |
| 195 | + {{- $hasOnly1001 = false }} |
| 196 | + {{- end }} |
| 197 | + {{- end }} |
| 198 | + {{- if $hasOnly1001 }} |
| 199 | + {{- $_ := unset $podSecurityContext "supplementalGroups" }} |
| 200 | + {{- end }} |
| 201 | + {{- end }} |
| 202 | +{{- end }} |
| 203 | +{{- if hasKey $podSecurityContext "enabled" }} |
| 204 | + {{- $_ := unset $podSecurityContext "enabled" }} |
| 205 | +{{- end }} |
| 206 | +{{- end }} |
| 207 | +{{- toYaml $podSecurityContext }} |
| 208 | +{{- end -}} |
| 209 | + |
| 210 | +{{/* |
| 211 | +Process container security context |
| 212 | +*/}} |
| 213 | +{{- define "replicated.containerSecurityContext" -}} |
| 214 | +{{- $containerSecurityContext := .Values.containerSecurityContext | deepCopy }} |
| 215 | +{{- if $containerSecurityContext }} |
| 216 | +{{- if hasKey $containerSecurityContext "enabled" }} |
| 217 | + {{- $_ := unset $containerSecurityContext "enabled" }} |
| 218 | +{{- end }} |
| 219 | +{{- end }} |
| 220 | +{{- toYaml $containerSecurityContext }} |
| 221 | +{{- end -}} |
| 222 | + |
| 223 | +{{/* |
| 224 | +Get the secret name to use - either the user-specified existing secret or the default |
| 225 | +*/}} |
| 226 | +{{- define "replicated.secretName" -}} |
| 227 | +{{- if and .Values.existingSecret .Values.existingSecret.name -}} |
| 228 | + {{- .Values.existingSecret.name -}} |
| 229 | +{{- else -}} |
| 230 | + {{ include "replicated.name" . }} |
| 231 | +{{- end -}} |
| 232 | +{{- end -}} |
0 commit comments