Merge "[AAI] Add model-loader tracing config"
[oom.git] / kubernetes / common / common / templates / _images.tpl
1 {{/*
2 # Copyright © Original (https://github.com/bitnami/charts) VMware, Inc.
3 # Copyright © 2024 Deutsche Telekom
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 */}}
17
18 {{/* vim: set filetype=mustache: */}}
19
20 {{/*
21 Return the proper Docker Image Registry Secret Names
22 Original, if common way of image definition:
23 {{- include "common.images.renderPullSecrets" (dict "images" (list .Values.image .Values.metrics.image .Values.volumePermissions.image .Values.tls.image) "context" $) -}}
24 */}}
25 {{- define "common.imagePullSecrets" -}}
26 {{- $images := list }}
27 {{- if .Values.image }}
28   {{- if kindIs "map" .Values.image -}}
29     {{- $images = append $images ".Values.image" -}}
30   {{- end -}}
31 {{- end -}}
32 {{- if .Values.metrics }}
33   {{- if .Values.metrics.image }}
34     {{- if kindIs "map" .Values.metrics.image -}}
35       {{- $images = append $images ".Values.metrics.image" -}}
36     {{- end -}}
37   {{- end -}}
38 {{- end -}}
39 {{- include "common.images._renderPullSecrets" (dict "images" $images "context" $) -}}
40 {{- end -}}
41
42 {{/*
43 Return the proper image name
44 {{ include "common.images.image" ( dict "imageRoot" .Values.path.to.the.image "global" .Values.global ) }}
45 */}}
46 {{- define "common.images.image" -}}
47 {{- $registryName := .imageRoot.registry -}}
48 {{- $repositoryName := .imageRoot.repository -}}
49 {{- $separator := ":" -}}
50 {{- $termination := .imageRoot.tag | toString -}}
51 {{- if .global }}
52     {{- if .global.imageRegistry }}
53      {{- $registryName = .global.imageRegistry -}}
54     {{- end -}}
55 {{- end -}}
56 {{- if .imageRoot.digest }}
57     {{- $separator = "@" -}}
58     {{- $termination = .imageRoot.digest | toString -}}
59 {{- end -}}
60 {{- if $registryName }}
61     {{- printf "%s/%s%s%s" $registryName $repositoryName $separator $termination -}}
62 {{- else -}}
63     {{- printf "%s%s%s"  $repositoryName $separator $termination -}}
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   {{- $images := .images }}
75
76   {{- if $context.Values.global }}
77     {{- range $context.Values.global.imagePullSecrets -}}
78       {{- if kindIs "map" . -}}
79         {{- $pullSecrets = append $pullSecrets (include "common.tplvalues._render" (dict "value" .name "context" $context)) -}}
80       {{- else -}}
81         {{- $pullSecrets = append $pullSecrets (include "common.tplvalues._render" (dict "value" . "context" $context)) -}}
82       {{- end -}}
83     {{- end -}}
84   {{- end -}}
85
86   {{- range $image := $images -}}
87     {{- if contains "pullSecret" $image -}}
88       {{- range $pullSecret := $image.pullSecrets -}}
89         {{- if kindIs "map" $pullSecret -}}
90           {{- $pullSecrets = append $pullSecrets $pullSecret.name -}}
91         {{- else -}}
92           {{- $pullSecrets = append $pullSecrets $pullSecret -}}
93         {{- end -}}
94       {{- end -}}
95     {{- end -}}
96   {{- end -}}
97
98   {{- if (not (empty $pullSecrets)) }}
99 imagePullSecrets:
100     {{- range $pullSecrets | uniq }}
101   - name: {{ . }}
102     {{- end }}
103   {{- else -}}
104 imagePullSecrets: []
105   {{- end }}
106 {{- end -}}
107
108 {{/*
109 Return the proper image version (ingores image revision/prerelease info & fallbacks to chart appVersion)
110 {{ include "common.images.version" ( dict "imageRoot" .Values.path.to.the.image "chart" .Chart ) }}
111 */}}
112 {{- define "common.images._version" -}}
113 {{- $imageTag := .imageRoot.tag | toString -}}
114 {{/* regexp from https://github.com/Masterminds/semver/blob/23f51de38a0866c5ef0bfc42b3f735c73107b700/version.go#L41-L44 */}}
115 {{- 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 -}}
116     {{- $version := semver $imageTag -}}
117     {{- printf "%d.%d.%d" $version.Major $version.Minor $version.Patch -}}
118 {{- else -}}
119     {{- print .chart.AppVersion -}}
120 {{- end -}}
121 {{- end -}}