Merge "[OOM][DCAE] Chartmuseum deployment support"
[oom.git] / kubernetes / common / repositoryGenerator / templates / _repository.tpl
1 {{/*
2 # Copyright © 2017 Amdocs, Bell Canada
3 # Copyright © 2021 AT&T
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 {{- define "repositoryGenerator._repositoryHelper" -}}
19   {{- $dot := default . .dot -}}
20   {{- $initRoot := default $dot.Values.repositoryGenerator .initRoot -}}
21   {{- $repoName := .repoName }}
22   {{- $overrideName := printf "%s%s" $repoName "Override" }}
23   {{- if (hasKey $dot.Values $overrideName) -}}
24     {{- printf "%s" (first (pluck $overrideName $dot.Values)) -}}
25   {{- else -}}
26     {{- first (pluck $repoName $dot.Values.global $initRoot.global) -}}
27   {{- end }}
28 {{- end -}}
29
30 {{/*
31   Resolve the name of the common image repository.
32
33   - .Values.global.repository  : default image repository for all ONAP images
34   - .Values.repositoryOverride : override global repository on a per chart basis
35 */}}
36 {{- define "repositoryGenerator.repository" -}}
37   {{- include "repositoryGenerator._repositoryHelper" (merge (dict "repoName" "repository") .) }}
38 {{- end -}}
39
40 {{/*
41   Resolve the name of the dockerHub image repository.
42
43   - .Values.global.dockerHubRepository  : default image dockerHubRepository for all dockerHub images
44   - .Values.dockerHubRepositoryOverride : override global dockerHub repository on a per chart basis
45 */}}
46 {{- define "repositoryGenerator.dockerHubRepository" -}}
47   {{- include "repositoryGenerator._repositoryHelper" (merge (dict "repoName" "dockerHubRepository") .) }}
48 {{- end -}}
49
50 {{/*
51   Resolve the name of the elasticRepository image repository.
52
53   - .Values.global.elasticRepository  : default image elasticRepository for all images using elastic repository
54   - .Values.elasticRepositoryOverride : override global elasticRepository repository on a per chart basis
55 */}}
56 {{- define "repositoryGenerator.elasticRepository" -}}
57   {{- include "repositoryGenerator._repositoryHelper" (merge (dict "repoName" "elasticRepository") .) }}
58 {{- end -}}
59
60 {{/*
61   Resolve the name of the googleK8sRepository image repository.
62
63   - .Values.global.googleK8sRepository  : default image dockerHubRepository for all dockerHub images
64   - .Values.googleK8sRepositoryOverride : override global dockerHub repository on a per chart basis
65 */}}
66 {{- define "repositoryGenerator.googleK8sRepository" -}}
67   {{- include "repositoryGenerator._repositoryHelper" (merge (dict "repoName" "googleK8sRepository") .) }}
68 {{- end -}}
69
70 {{/*
71   Resolve the name of the GithubContainer registry
72   - .Values.global.githubContainerRegistry  : default image githubContainerRegistry for all dockerHub images
73   - .Values.githubContainerRegistryOverride : override global githubContainerRegistry on a per chart basis
74 */}}
75 {{- define "repositoryGenerator.githubContainerRegistry" -}}
76   {{- include "repositoryGenerator._repositoryHelper" (merge (dict "repoName" "githubContainerRegistry") .) }}
77 {{- end -}}
78
79 {{- define "repositoryGenerator.image._helper" -}}
80   {{- $dot := default . .dot -}}
81   {{- $initRoot := default $dot.Values.repositoryGenerator .initRoot -}}
82   {{- $image := .image }}
83   {{- $repoName := first (pluck $image $initRoot.imageRepoMapping) }}
84   {{- include "repositoryGenerator._repositoryHelper" (merge (dict "repoName" $repoName ) .) }}/{{- first (pluck $image $dot.Values.global $initRoot.global) -}}
85 {{- end -}}
86
87 {{- define "repositoryGenerator.image.busybox" -}}
88   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "busyboxImage") .) }}
89 {{- end -}}
90
91 {{- define "repositoryGenerator.image.curl" -}}
92   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "curlImage") .) }}
93 {{- end -}}
94
95 {{- define "repositoryGenerator.image.dcaepolicysync" -}}
96   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "dcaePolicySyncImage") .) }}
97 {{- end -}}
98
99 {{- define "repositoryGenerator.image.envsubst" -}}
100   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "envsubstImage") .) }}
101 {{- end -}}
102
103 {{- define "repositoryGenerator.image.htpasswd" -}}
104   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "htpasswdImage") .) }}
105 {{- end -}}
106
107 {{- define "repositoryGenerator.image.jre" -}}
108   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "jreImage") .) }}
109 {{- end -}}
110
111 {{- define "repositoryGenerator.image.kubectl" -}}
112   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "kubectlImage") .) }}
113 {{- end -}}
114
115 {{- define "repositoryGenerator.image.logging" -}}
116   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "loggingImage") .) }}
117 {{- end -}}
118
119 {{- define "repositoryGenerator.image.mariadb" -}}
120   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "mariadbImage") .) }}
121 {{- end -}}
122
123 {{- define "repositoryGenerator.image.nginx" -}}
124   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "nginxImage") .) }}
125 {{- end -}}
126
127 {{- define "repositoryGenerator.image.postgres" -}}
128   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "postgresImage") .) }}
129 {{- end -}}
130
131 {{- define "repositoryGenerator.image.readiness" -}}
132   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "readinessImage") .) }}
133 {{- end -}}
134
135 {{/*
136   Resolve the image repository secret token.
137   The value for .Values.global.repositoryCred is used if provided:
138   repositoryCred:
139     user: user
140     password: password
141     mail: email (optional)
142   You can also set the same things for dockerHub, elastic and googleK8s if
143   needed.
144 */}}
145 {{- define "repositoryGenerator.secret" -}}
146   {{- $dot := default . .dot -}}
147   {{- $initRoot := default $dot.Values.repositoryGenerator .initRoot -}}
148   {{/* Our version of helm doesn't support deepCopy so we need this nasty trick */}}
149   {{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }}
150   {{- $repoCreds := "" }}
151   {{- if $subchartDot.Values.global.repositoryCred }}
152   {{-   $repo := $subchartDot.Values.global.repository }}
153   {{-   $cred := $subchartDot.Values.global.repositoryCred }}
154   {{-   $mail := default "@" $cred.mail }}
155   {{-   $auth := printf "%s:%s" $cred.user $cred.password | b64enc }}
156   {{-   $repoCreds = printf "\"%s\": {\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}" $repo $cred.user $cred.password $mail $auth }}
157   {{- end }}
158   {{- if $subchartDot.Values.global.dockerHubRepositoryCred }}
159   {{-   $dhRepo := $subchartDot.Values.global.dockerHubRepository }}
160   {{-   $dhCred := $subchartDot.Values.global.dockerHubRepositoryCred }}
161   {{-   $dhMail := default "@" $dhCred.mail }}
162   {{-   $dhAuth := printf "%s:%s" $dhCred.user $dhCred.password | b64enc }}
163   {{-   $dhRepoCreds := printf "\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}" $dhRepo $dhCred.user $dhCred.password $dhMail $dhAuth }}
164   {{-   if eq "" $repoCreds }}
165   {{-     $repoCreds = $dhRepoCreds }}
166   {{-   else }}
167   {{-     $repoCreds = printf "%s, %s" $repoCreds $dhRepoCreds }}
168   {{-   end }}
169   {{- end }}
170   {{- if $subchartDot.Values.global.elasticRepositoryCred }}
171   {{-   $eRepo := $subchartDot.Values.global.elasticRepository }}
172   {{-   $eCred := $subchartDot.Values.global.elasticRepositoryCred }}
173   {{-   $eMail := default "@" $eCred.mail }}
174   {{-   $eAuth := printf "%s:%s" $eCred.user $eCred.password | b64enc }}
175   {{-   $eRepoCreds := printf "\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}" $eRepo $eCred.user $eCred.password $eMail $eAuth }}
176   {{-   if eq "" $repoCreds }}
177   {{-     $repoCreds = $eRepoCreds }}
178   {{-   else }}
179   {{-     $repoCreds = printf "%s, %s" $repoCreds $eRepoCreds }}
180   {{-   end }}
181   {{- end }}
182   {{- if $subchartDot.Values.global.googleK8sRepositoryCred }}
183   {{-   $gcrRepo := $subchartDot.Values.global.googleK8sRepository }}
184   {{-   $gcrCred := $subchartDot.Values.global.googleK8sRepositoryCred }}
185   {{-   $gcrMail := default "@" $gcrCred.mail }}
186   {{-   $gcrAuth := printf "%s:%s" $gcrCred.user $gcrCred.password | b64enc }}
187   {{-   $gcrRepoCreds := printf "\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}" $gcrRepo $gcrCred.user $gcrCred.password $gcrMail $gcrAuth }}
188   {{-   if eq "" $repoCreds }}
189   {{-     $repoCreds = $gcrRepoCreds }}
190   {{-   else }}
191   {{-     $repoCreds = printf "%s, %s" $repoCreds $gcrRepoCreds }}
192   {{-   end }}
193   {{- end }}
194   {{- if $subchartDot.Values.global.githubContainerRegistryCred }}
195   {{-   $ghcrRepo := $subchartDot.Values.global.githubContainerRegistry }}
196   {{-   $ghcrCred := $subchartDot.Values.global.githubContainerRegistryCred }}
197   {{-   $ghcrMail := default "@" $ghcrCred.mail }}
198   {{-   $ghcrAuth := printf "%s:%s" $ghcrCred.user $ghcrCred.password | b64enc }}
199   {{-   $ghcrRepoCreds := printf "\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}" $ghcrRepo $ghcrCred.user $ghcrCred.password $ghcrMail $ghcrAuth }}
200   {{-   if eq "" $repoCreds }}
201   {{-     $repoCreds = $ghcrRepoCreds }}
202   {{-   else }}
203   {{-     $repoCreds = printf "%s, %s" $repoCreds $ghcrRepoCreds }}
204   {{-   end }}
205   {{- end }}
206   {{- printf "{%s}" $repoCreds | b64enc -}}
207 {{- end -}}