Mohammed Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 1 | {{/* vim: set filetype=mustache: */}} |
| 2 | {{/* |
| 3 | Expand the name of the chart. |
| 4 | */}} |
| 5 | {{- define "prometheus-pushgateway.name" -}} |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 6 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} |
| 7 | {{- end }} |
| 8 | |
| 9 | {{/* |
| 10 | Namespace to set on the resources |
| 11 | */}} |
| 12 | {{- define "prometheus-pushgateway.namespace" -}} |
| 13 | {{- if .Values.namespaceOverride -}} |
| 14 | {{- .Values.namespaceOverride -}} |
| 15 | {{- else -}} |
| 16 | {{- .Release.Namespace -}} |
| 17 | {{- end -}} |
Mohammed Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 18 | {{- end -}} |
| 19 | |
| 20 | {{/* |
| 21 | Create a default fully qualified app name. |
| 22 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
| 23 | If release name contains chart name it will be used as a full name. |
| 24 | */}} |
| 25 | {{- define "prometheus-pushgateway.fullname" -}} |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 26 | {{- if .Values.fullnameOverride }} |
| 27 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} |
| 28 | {{- else }} |
| 29 | {{- $name := default .Chart.Name .Values.nameOverride }} |
| 30 | {{- if contains $name .Release.Name }} |
| 31 | {{- .Release.Name | trunc 63 | trimSuffix "-" }} |
| 32 | {{- else }} |
| 33 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} |
| 34 | {{- end }} |
| 35 | {{- end }} |
| 36 | {{- end }} |
Mohammed Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 37 | |
| 38 | {{/* |
| 39 | Create chart name and version as used by the chart label. |
| 40 | */}} |
| 41 | {{- define "prometheus-pushgateway.chart" -}} |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 42 | {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} |
| 43 | {{- end }} |
Mohammed Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 44 | |
| 45 | {{/* |
| 46 | Create the name of the service account to use |
| 47 | */}} |
| 48 | {{- define "prometheus-pushgateway.serviceAccountName" -}} |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 49 | {{- if .Values.serviceAccount.create }} |
| 50 | {{- default (include "prometheus-pushgateway.fullname" .) .Values.serviceAccount.name }} |
| 51 | {{- else }} |
| 52 | {{- default "default" .Values.serviceAccount.name }} |
| 53 | {{- end }} |
| 54 | {{- end }} |
Mohammed Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 55 | |
| 56 | {{/* |
| 57 | Create default labels |
| 58 | */}} |
| 59 | {{- define "prometheus-pushgateway.defaultLabels" -}} |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 60 | helm.sh/chart: {{ include "prometheus-pushgateway.chart" . }} |
| 61 | {{ include "prometheus-pushgateway.selectorLabels" . }} |
| 62 | {{- if .Chart.AppVersion }} |
| 63 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
| 64 | {{- end }} |
| 65 | app.kubernetes.io/managed-by: {{ .Release.Service }} |
| 66 | {{- with .Values.podLabels }} |
| 67 | {{ toYaml . }} |
| 68 | {{- end }} |
| 69 | {{- end }} |
| 70 | |
| 71 | {{/* |
| 72 | Selector labels |
| 73 | */}} |
| 74 | {{- define "prometheus-pushgateway.selectorLabels" -}} |
| 75 | app.kubernetes.io/name: {{ include "prometheus-pushgateway.name" . }} |
| 76 | app.kubernetes.io/instance: {{ .Release.Name }} |
| 77 | {{- end }} |
Mohammed Naser | 9ad0d46 | 2023-01-15 20:36:37 -0500 | [diff] [blame] | 78 | |
| 79 | {{/* |
| 80 | Return the appropriate apiVersion for networkpolicy. |
| 81 | */}} |
| 82 | {{- define "prometheus-pushgateway.networkPolicy.apiVersion" -}} |
Mohammed Naser | 65cda13 | 2024-05-02 14:34:08 -0400 | [diff] [blame] | 83 | {{- if semverCompare ">=1.4-0, <1.7-0" .Capabilities.KubeVersion.GitVersion }} |
| 84 | {{- print "extensions/v1beta1" }} |
| 85 | {{- else if semverCompare "^1.7-0" .Capabilities.KubeVersion.GitVersion }} |
| 86 | {{- print "networking.k8s.io/v1" }} |
| 87 | {{- end }} |
| 88 | {{- end }} |
| 89 | |
| 90 | {{/* |
| 91 | Define PDB apiVersion |
| 92 | */}} |
| 93 | {{- define "prometheus-pushgateway.pdb.apiVersion" -}} |
| 94 | {{- if $.Capabilities.APIVersions.Has "policy/v1/PodDisruptionBudget" }} |
| 95 | {{- print "policy/v1" }} |
| 96 | {{- else }} |
| 97 | {{- print "policy/v1beta1" }} |
| 98 | {{- end }} |
| 99 | {{- end }} |
| 100 | |
| 101 | {{/* |
| 102 | Define Ingress apiVersion |
| 103 | */}} |
| 104 | {{- define "prometheus-pushgateway.ingress.apiVersion" -}} |
| 105 | {{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion }} |
| 106 | {{- print "networking.k8s.io/v1" }} |
| 107 | {{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion }} |
| 108 | {{- print "networking.k8s.io/v1beta1" }} |
| 109 | {{- else }} |
| 110 | {{- print "extensions/v1beta1" }} |
| 111 | {{- end }} |
| 112 | {{- end }} |
| 113 | |
| 114 | {{/* |
| 115 | Define webConfiguration |
| 116 | */}} |
| 117 | {{- define "prometheus-pushgateway.webConfiguration" -}} |
| 118 | basic_auth_users: |
| 119 | {{- range $k, $v := .Values.webConfiguration.basicAuthUsers }} |
| 120 | {{ $k }}: {{ htpasswd "" $v | trimPrefix ":"}} |
| 121 | {{- end }} |
| 122 | {{- end }} |
| 123 | |
| 124 | {{/* |
| 125 | Define Authorization |
| 126 | */}} |
| 127 | {{- define "prometheus-pushgateway.Authorization" -}} |
| 128 | {{- $users := keys .Values.webConfiguration.basicAuthUsers }} |
| 129 | {{- $user := first $users }} |
| 130 | {{- $password := index .Values.webConfiguration.basicAuthUsers $user }} |
| 131 | {{- $user }}:{{ $password }} |
| 132 | {{- end }} |
| 133 | |
| 134 | {{/* |
| 135 | Returns pod spec |
| 136 | */}} |
| 137 | {{- define "prometheus-pushgateway.podSpec" -}} |
| 138 | serviceAccountName: {{ include "prometheus-pushgateway.serviceAccountName" . }} |
| 139 | automountServiceAccountToken: {{ .Values.automountServiceAccountToken }} |
| 140 | {{- with .Values.priorityClassName }} |
| 141 | priorityClassName: {{ . | quote }} |
| 142 | {{- end }} |
| 143 | {{- with .Values.hostAliases }} |
| 144 | hostAliases: |
| 145 | {{- toYaml . | nindent 2 }} |
| 146 | {{- end }} |
| 147 | {{- with .Values.imagePullSecrets }} |
| 148 | imagePullSecrets: |
| 149 | {{- toYaml . | nindent 2 }} |
| 150 | {{- end }} |
| 151 | {{- with .Values.extraInitContainers }} |
| 152 | initContainers: |
| 153 | {{- toYaml . | nindent 2 }} |
| 154 | {{- end }} |
| 155 | containers: |
| 156 | {{- with .Values.extraContainers }} |
| 157 | {{- toYaml . | nindent 2 }} |
| 158 | {{- end }} |
| 159 | - name: pushgateway |
| 160 | image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" |
| 161 | imagePullPolicy: {{ .Values.image.pullPolicy }} |
| 162 | {{- with .Values.extraVars }} |
| 163 | env: |
| 164 | {{- toYaml . | nindent 6 }} |
| 165 | {{- end }} |
| 166 | {{- if or .Values.extraArgs .Values.webConfiguration }} |
| 167 | args: |
| 168 | {{- with .Values.extraArgs }} |
| 169 | {{- toYaml . | nindent 6 }} |
| 170 | {{- end }} |
| 171 | {{- if .Values.webConfiguration }} |
| 172 | - --web.config.file=/etc/config/web-config.yaml |
| 173 | {{- end }} |
| 174 | {{- end }} |
| 175 | ports: |
| 176 | - name: metrics |
| 177 | containerPort: 9091 |
| 178 | protocol: TCP |
| 179 | {{- if .Values.liveness.enabled }} |
| 180 | {{- $livenessCommon := omit .Values.liveness.probe "httpGet" }} |
| 181 | livenessProbe: |
| 182 | {{- with .Values.liveness.probe }} |
| 183 | httpGet: |
| 184 | path: {{ .httpGet.path }} |
| 185 | port: {{ .httpGet.port }} |
| 186 | {{- if or .httpGet.httpHeaders $.Values.webConfiguration.basicAuthUsers }} |
| 187 | httpHeaders: |
| 188 | {{- if $.Values.webConfiguration.basicAuthUsers }} |
| 189 | - name: Authorization |
| 190 | value: Basic {{ include "prometheus-pushgateway.Authorization" $ | b64enc }} |
| 191 | {{- end }} |
| 192 | {{- with .httpGet.httpHeaders }} |
| 193 | {{- toYaml . | nindent 10 }} |
| 194 | {{- end }} |
| 195 | {{- end }} |
| 196 | {{- toYaml $livenessCommon | nindent 6 }} |
| 197 | {{- end }} |
| 198 | {{- end }} |
| 199 | {{- if .Values.readiness.enabled }} |
| 200 | {{- $readinessCommon := omit .Values.readiness.probe "httpGet" }} |
| 201 | readinessProbe: |
| 202 | {{- with .Values.readiness.probe }} |
| 203 | httpGet: |
| 204 | path: {{ .httpGet.path }} |
| 205 | port: {{ .httpGet.port }} |
| 206 | {{- if or .httpGet.httpHeaders $.Values.webConfiguration.basicAuthUsers }} |
| 207 | httpHeaders: |
| 208 | {{- if $.Values.webConfiguration.basicAuthUsers }} |
| 209 | - name: Authorization |
| 210 | value: Basic {{ include "prometheus-pushgateway.Authorization" $ | b64enc }} |
| 211 | {{- end }} |
| 212 | {{- with .httpGet.httpHeaders }} |
| 213 | {{- toYaml . | nindent 10 }} |
| 214 | {{- end }} |
| 215 | {{- end }} |
| 216 | {{- toYaml $readinessCommon | nindent 6 }} |
| 217 | {{- end }} |
| 218 | {{- end }} |
| 219 | {{- with .Values.resources }} |
| 220 | resources: |
| 221 | {{- toYaml . | nindent 6 }} |
| 222 | {{- end }} |
| 223 | {{- with .Values.containerSecurityContext }} |
| 224 | securityContext: |
| 225 | {{- toYaml . | nindent 6 }} |
| 226 | {{- end }} |
| 227 | volumeMounts: |
| 228 | - name: storage-volume |
| 229 | mountPath: "{{ .Values.persistentVolume.mountPath }}" |
| 230 | subPath: "{{ .Values.persistentVolume.subPath }}" |
| 231 | {{- if .Values.webConfiguration }} |
| 232 | - name: web-config |
| 233 | mountPath: "/etc/config" |
| 234 | {{- end }} |
| 235 | {{- with .Values.extraVolumeMounts }} |
| 236 | {{- toYaml . | nindent 6 }} |
| 237 | {{- end }} |
| 238 | {{- with .Values.nodeSelector }} |
| 239 | nodeSelector: |
| 240 | {{- toYaml . | nindent 2 }} |
| 241 | {{- end }} |
| 242 | {{- with .Values.tolerations }} |
| 243 | tolerations: |
| 244 | {{- toYaml . | nindent 2 }} |
| 245 | {{- end }} |
| 246 | {{- if or .Values.podAntiAffinity .Values.affinity }} |
| 247 | affinity: |
| 248 | {{- end }} |
| 249 | {{- with .Values.affinity }} |
| 250 | {{- toYaml . | nindent 2 }} |
| 251 | {{- end }} |
| 252 | {{- if eq .Values.podAntiAffinity "hard" }} |
| 253 | podAntiAffinity: |
| 254 | requiredDuringSchedulingIgnoredDuringExecution: |
| 255 | - topologyKey: {{ .Values.podAntiAffinityTopologyKey }} |
| 256 | labelSelector: |
| 257 | matchExpressions: |
| 258 | - {key: app.kubernetes.io/name, operator: In, values: [{{ include "prometheus-pushgateway.name" . }}]} |
| 259 | {{- else if eq .Values.podAntiAffinity "soft" }} |
| 260 | podAntiAffinity: |
| 261 | preferredDuringSchedulingIgnoredDuringExecution: |
| 262 | - weight: 100 |
| 263 | podAffinityTerm: |
| 264 | topologyKey: {{ .Values.podAntiAffinityTopologyKey }} |
| 265 | labelSelector: |
| 266 | matchExpressions: |
| 267 | - {key: app.kubernetes.io/name, operator: In, values: [{{ include "prometheus-pushgateway.name" . }}]} |
| 268 | {{- end }} |
| 269 | {{- with .Values.topologySpreadConstraints }} |
| 270 | topologySpreadConstraints: |
| 271 | {{- toYaml . | nindent 2 }} |
| 272 | {{- end }} |
| 273 | {{- with .Values.securityContext }} |
| 274 | securityContext: |
| 275 | {{- toYaml . | nindent 2 }} |
| 276 | {{- end }} |
| 277 | volumes: |
| 278 | {{- $storageVolumeAsPVCTemplate := and .Values.runAsStatefulSet .Values.persistentVolume.enabled -}} |
| 279 | {{- if not $storageVolumeAsPVCTemplate }} |
| 280 | - name: storage-volume |
| 281 | {{- if .Values.persistentVolume.enabled }} |
| 282 | persistentVolumeClaim: |
| 283 | claimName: {{ if .Values.persistentVolume.existingClaim }}{{ .Values.persistentVolume.existingClaim }}{{- else }}{{ include "prometheus-pushgateway.fullname" . }}{{- end }} |
| 284 | {{- else }} |
| 285 | emptyDir: {} |
| 286 | {{- end }} |
| 287 | {{- if .Values.webConfiguration }} |
| 288 | - name: web-config |
| 289 | secret: |
| 290 | secretName: {{ include "prometheus-pushgateway.fullname" . }} |
| 291 | {{- end }} |
| 292 | {{- end }} |
| 293 | {{- if .Values.extraVolumes }} |
| 294 | {{- toYaml .Values.extraVolumes | nindent 2 }} |
| 295 | {{- else if $storageVolumeAsPVCTemplate }} |
| 296 | {{- if .Values.webConfiguration }} |
| 297 | - name: web-config |
| 298 | secret: |
| 299 | secretName: {{ include "prometheus-pushgateway.fullname" . }} |
| 300 | {{- else }} |
| 301 | [] |
| 302 | {{- end }} |
| 303 | {{- end }} |
| 304 | {{- end }} |