Merge "[AAI] Add model-loader tracing config"
[oom.git] / kubernetes / common / mongodb / common / templates / _images.tpl
1 {{/*
2 Copyright VMware, Inc.
3 SPDX-License-Identifier: APACHE-2.0
4 */}}
5
6 {{/* vim: set filetype=mustache: */}}
7 {{/*
8 Return the proper image name
9 {{ include "common.images.image" ( dict "imageRoot" .Values.path.to.the.image "global" .Values.global ) }}
10 */}}
11 {{- define "common.images.image" -}}
12 {{- $registryName := .imageRoot.registry -}}
13 {{- $repositoryName := .imageRoot.repository -}}
14 {{- $separator := ":" -}}
15 {{- $termination := .imageRoot.tag | toString -}}
16 {{- if .global }}
17     {{- if .global.imageRegistry }}
18      {{- $registryName = .global.imageRegistry -}}
19     {{- end -}}
20 {{- end -}}
21 {{- if .imageRoot.digest }}
22     {{- $separator = "@" -}}
23     {{- $termination = .imageRoot.digest | toString -}}
24 {{- end -}}
25 {{- if $registryName }}
26     {{- printf "%s/%s%s%s" $registryName $repositoryName $separator $termination -}}
27 {{- else -}}
28     {{- printf "%s%s%s"  $repositoryName $separator $termination -}}
29 {{- end -}}
30 {{- end -}}
31
32 {{/*
33 Return the proper Docker Image Registry Secret Names (deprecated: use common.images.renderPullSecrets instead)
34 {{ include "common.images.pullSecrets" ( dict "images" (list .Values.path.to.the.image1, .Values.path.to.the.image2) "global" .Values.global) }}
35 */}}
36 {{- define "common.images.pullSecrets" -}}
37   {{- $pullSecrets := list }}
38
39   {{- if .global }}
40     {{- range .global.imagePullSecrets -}}
41       {{- if kindIs "map" . -}}
42         {{- $pullSecrets = append $pullSecrets .name -}}
43       {{- else -}}
44         {{- $pullSecrets = append $pullSecrets . -}}
45       {{- end }}
46     {{- end -}}
47   {{- end -}}
48
49   {{- range .images -}}
50     {{- range .pullSecrets -}}
51       {{- if kindIs "map" . -}}
52         {{- $pullSecrets = append $pullSecrets .name -}}
53       {{- else -}}
54         {{- $pullSecrets = append $pullSecrets . -}}
55       {{- end -}}
56     {{- end -}}
57   {{- end -}}
58
59   {{- if (not (empty $pullSecrets)) }}
60 imagePullSecrets:
61     {{- range $pullSecrets | uniq }}
62   - name: {{ . }}
63     {{- end }}
64   {{- end }}
65 {{- end -}}
66
67 {{/*
68 Return the proper Docker Image Registry Secret Names evaluating values as templates
69 {{ include "common.images.renderPullSecrets" ( dict "images" (list .Values.path.to.the.image1, .Values.path.to.the.image2) "context" $) }}
70 */}}
71 {{- define "common.images.renderPullSecrets" -}}
72   {{- $pullSecrets := list }}
73   {{- $context := .context }}
74
75   {{- if $context.Values.global }}
76     {{- range $context.Values.global.imagePullSecrets -}}
77       {{- if kindIs "map" . -}}
78         {{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" .name "context" $context)) -}}
79       {{- else -}}
80         {{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" . "context" $context)) -}}
81       {{- end -}}
82     {{- end -}}
83   {{- end -}}
84
85   {{- range .images -}}
86     {{- range .pullSecrets -}}
87       {{- if kindIs "map" . -}}
88         {{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" .name "context" $context)) -}}
89       {{- else -}}
90         {{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" . "context" $context)) -}}
91       {{- end -}}
92     {{- end -}}
93   {{- end -}}
94
95   {{- if (not (empty $pullSecrets)) }}
96 imagePullSecrets:
97     {{- range $pullSecrets | uniq }}
98   - name: {{ . }}
99     {{- end }}
100   {{- end }}
101 {{- end -}}
102
103 {{/*
104 Return the proper image version (ingores image revision/prerelease info & fallbacks to chart appVersion)
105 {{ include "common.images.version" ( dict "imageRoot" .Values.path.to.the.image "chart" .Chart ) }}
106 */}}
107 {{- define "common.images.version" -}}
108 {{- $imageTag := .imageRoot.tag | toString -}}
109 {{/* regexp from https://github.com/Masterminds/semver/blob/23f51de38a0866c5ef0bfc42b3f735c73107b700/version.go#L41-L44 */}}
110 {{- if regexMatch `^([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?$` $imageTag -}}
111     {{- $version := semver $imageTag -}}
112     {{- printf "%d.%d.%d" $version.Major $version.Minor $version.Patch -}}
113 {{- else -}}
114     {{- print .chart.AppVersion -}}
115 {{- end -}}
116 {{- end -}}
117