Merge "[SDNC] Upgrade to final SDNC Guilin docker version"
[oom.git] / kubernetes / common / repositoryGenerator / templates / _repository.tpl
1 {{/*
2 # Copyright © 2017 Amdocs, Bell Canada
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 */}}
16
17 {{- define "repositoryGenerator._repositoryHelper" -}}
18   {{- $dot := default . .dot -}}
19   {{- $initRoot := default $dot.Values.repositoryGenerator .initRoot -}}
20   {{- $repoName := .repoName }}
21   {{- $overrideName := printf "%s%s" $repoName "Override" }}
22   {{- if (hasKey $dot.Values $overrideName) -}}
23     {{- printf "%s" (first (pluck $overrideName $dot.Values)) -}}
24   {{- else -}}
25     {{- first (pluck $repoName $dot.Values.global $initRoot.global) -}}
26   {{- end }}
27 {{- end -}}
28
29 {{/*
30   Resolve the name of the common image repository.
31
32   - .Values.global.repository  : default image repository for all ONAP images
33   - .Values.repositoryOverride : override global repository on a per chart basis
34 */}}
35 {{- define "repositoryGenerator.repository" -}}
36   {{- include "repositoryGenerator._repositoryHelper" (merge (dict "repoName" "repository") .) }}
37 {{- end -}}
38
39 {{/*
40   Resolve the name of the dockerHub image repository.
41
42   - .Values.global.dockerHubRepository  : default image dockerHubRepository for all dockerHub images
43   - .Values.dockerHubRepositoryOverride : override global dockerHub repository on a per chart basis
44 */}}
45 {{- define "repositoryGenerator.dockerHubRepository" -}}
46   {{- include "repositoryGenerator._repositoryHelper" (merge (dict "repoName" "dockerHubRepository") .) }}
47 {{- end -}}
48
49 {{/*
50   Resolve the name of the elasticRepository image repository.
51
52   - .Values.global.elasticRepository  : default image elasticRepository for all images using elastic repository
53   - .Values.elasticRepositoryOverride : override global elasticRepository repository on a per chart basis
54 */}}
55 {{- define "repositoryGenerator.elasticRepository" -}}
56   {{- include "repositoryGenerator._repositoryHelper" (merge (dict "repoName" "elasticRepository") .) }}
57 {{- end -}}
58
59 {{/*
60   Resolve the name of the googleK8sRepository image repository.
61
62   - .Values.global.googleK8sRepository  : default image dockerHubRepository for all dockerHub images
63   - .Values.googleK8sRepositoryOverride : override global dockerHub repository on a per chart basis
64 */}}
65 {{- define "repositoryGenerator.googleK8sRepository" -}}
66   {{- include "repositoryGenerator._repositoryHelper" (merge (dict "repoName" "googleK8sRepository") .) }}
67 {{- end -}}
68
69 {{- define "repositoryGenerator.image._helper" -}}
70   {{- $dot := default . .dot -}}
71   {{- $initRoot := default $dot.Values.repositoryGenerator .initRoot -}}
72   {{- $image := .image }}
73   {{- $repoName := first (pluck $image $initRoot.imageRepoMapping) }}
74   {{- include "repositoryGenerator._repositoryHelper" (merge (dict "repoName" $repoName ) .) }}/{{- first (pluck $image $dot.Values.global $initRoot.global) -}}
75 {{- end -}}
76
77 {{- define "repositoryGenerator.image.busybox" -}}
78   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "busyboxImage") .) }}
79 {{- end -}}
80
81 {{- define "repositoryGenerator.image.curl" -}}
82   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "curlImage") .) }}
83 {{- end -}}
84
85 {{- define "repositoryGenerator.image.envsubst" -}}
86   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "envsubstImage") .) }}
87 {{- end -}}
88
89 {{- define "repositoryGenerator.image.htpasswd" -}}
90   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "htpasswdImage") .) }}
91 {{- end -}}
92
93 {{- define "repositoryGenerator.image.kubectl" -}}
94   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "kubectlImage") .) }}
95 {{- end -}}
96
97 {{- define "repositoryGenerator.image.logging" -}}
98   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "loggingImage") .) }}
99 {{- end -}}
100
101 {{- define "repositoryGenerator.image.mariadb" -}}
102   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "mariadbImage") .) }}
103 {{- end -}}
104
105 {{- define "repositoryGenerator.image.nginx" -}}
106   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "nginxImage") .) }}
107 {{- end -}}
108
109 {{- define "repositoryGenerator.image.postgres" -}}
110   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "postgresImage") .) }}
111 {{- end -}}
112
113 {{- define "repositoryGenerator.image.readiness" -}}
114   {{- include "repositoryGenerator.image._helper" (merge (dict "image" "readinessImage") .) }}
115 {{- end -}}
116
117 {{/*
118   Resolve the image repository secret token.
119   The value for .Values.global.repositoryCred is used if provided:
120   repositoryCred:
121     user: user
122     password: password
123     mail: email (optional)
124   You can also set the same things for dockerHub, elastic and googleK8s if
125   needed.
126 */}}
127 {{- define "repositoryGenerator.secret" -}}
128   {{- $dot := default . .dot -}}
129   {{- $initRoot := default $dot.Values.repositoryGenerator .initRoot -}}
130   {{/* Our version of helm doesn't support deepCopy so we need this nasty trick */}}
131   {{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }}
132   {{- $repoCreds := "" }}
133   {{- if $subchartDot.Values.global.dockerHubRepositoryCred }}
134   {{-   $repo := $subchartDot.Values.global.repository }}
135   {{-   $cred := $subchartDot.Values.global.repositoryCred }}
136   {{-   $mail := default "@" $cred.mail }}
137   {{-   $auth := printf "%s:%s" $cred.user $cred.password | b64enc }}
138   {{-   $repoCreds = printf "\"%s\": {\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}" $repo $cred.user $cred.password $mail $auth }}
139   {{- end }}
140   {{- if $subchartDot.Values.global.dockerHubRepositoryCred }}
141   {{-   $dhRepo := $subchartDot.Values.global.dockerHubRepository }}
142   {{-   $dhCred := $subchartDot.Values.global.dockerHubRepositoryCred }}
143   {{-   $dhMail := default "@" $dhCred.mail }}
144   {{-   $dhAuth := printf "%s:%s" $dhCred.user $dhCred.password | b64enc }}
145   {{-   $dhRepoCreds := printf "\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}" $dhRepo $dhCred.user $dhCred.password $dhMail $dhAuth }}
146   {{-   if eq "" $repoCreds }}
147   {{-     $repoCreds = $dhRepoCreds }}
148   {{-   else }}
149   {{-     $repoCreds = printf "%s, %s" $repoCreds $dhRepoCreds }}
150   {{-   end }}
151   {{- end }}
152   {{- if $subchartDot.Values.global.elasticRepositoryCred }}
153   {{-   $eRepo := $subchartDot.Values.global.elasticRepository }}
154   {{-   $eCred := $subchartDot.Values.global.elasticRepositoryCred }}
155   {{-   $eMail := default "@" $eCred.mail }}
156   {{-   $eAuth := printf "%s:%s" $eCred.user $eCred.password | b64enc }}
157   {{-   $eRepoCreds := printf "\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}" $eRepo $eCred.user $eCred.password $eMail $eAuth }}
158   {{-   if eq "" $repoCreds }}
159   {{-     $repoCreds = $eRepoCreds }}
160   {{-   else }}
161   {{-     $repoCreds = printf "%s, %s" $repoCreds $eRepoCreds }}
162   {{-   end }}
163   {{- end }}
164   {{- if $subchartDot.Values.global.googleK8sRepositoryCred }}
165   {{-   $gcrRepo := $subchartDot.Values.global.googleK8sRepository }}
166   {{-   $gcrCred := $subchartDot.Values.global.googleK8sRepositoryCred }}
167   {{-   $gcrMail := default "@" $gcrCred.mail }}
168   {{-   $gcrAuth := printf "%s:%s" $gcrCred.user $gcrCred.password | b64enc }}
169   {{-   $gcrRepoCreds := printf "\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}" $gcrRepo $gcrCred.user $gcrCred.password $gcrMail $gcrAuth }}
170   {{-   if eq "" $repoCreds }}
171   {{-     $repoCreds = $gcrRepoCreds }}
172   {{-   else }}
173   {{-     $repoCreds = printf "%s, %s" $repoCreds $gcrRepoCreds }}
174   {{-   end }}
175   {{- end }}
176   {{- printf "{%s}" $repoCreds | b64enc -}}
177 {{- end -}}