-
Notifications
You must be signed in to change notification settings - Fork 0
/
_module_image.tpl
76 lines (73 loc) · 3.95 KB
/
_module_image.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{{- /* Usage: {{ include "helm_lib_module_image" (list . "<container-name>") }} */ -}}
{{- /* returns image name */ -}}
{{- define "helm_lib_module_image" }}
{{- $context := index . 0 }} {{- /* Template context with .Values, .Chart, etc */ -}}
{{- $containerName := index . 1 | trimAll "\"" }} {{- /* Container name */ -}}
{{- $moduleName := (include "helm_lib_module_camelcase_name" $context) }}
{{- if ge (len .) 3 }}
{{- $moduleName = (include "helm_lib_module_camelcase_name" (index . 2)) }} {{- /* Optional module name */ -}}
{{- end }}
{{- $imageDigest := index $context.Values.global.modulesImages.digests $moduleName $containerName }}
{{- if not $imageDigest }}
{{- $error := (printf "Image %s.%s has no digest" $moduleName $containerName ) }}
{{- fail $error }}
{{- end }}
{{- $registryBase := $context.Values.global.modulesImages.registry.base }}
{{- /* handle external modules registry */}}
{{- if index $context.Values $moduleName }}
{{- if index $context.Values $moduleName "registry" }}
{{- if index $context.Values $moduleName "registry" "base" }}
{{- $host := trimAll "/" (index $context.Values $moduleName "registry" "base") }}
{{- $path := trimAll "/" $context.Chart.Name }}
{{- $registryBase = join "/" (list $host $path) }}
{{- end }}
{{- end }}
{{- end }}
{{- printf "%s@%s" $registryBase $imageDigest }}
{{- end }}
{{- /* Usage: {{ include "helm_lib_module_image_no_fail" (list . "<container-name>") }} */ -}}
{{- /* returns image name if found */ -}}
{{- define "helm_lib_module_image_no_fail" }}
{{- $context := index . 0 }} {{- /* Template context with .Values, .Chart, etc */ -}}
{{- $containerName := index . 1 | trimAll "\"" }} {{- /* Container name */ -}}
{{- $moduleName := (include "helm_lib_module_camelcase_name" $context) }}
{{- if ge (len .) 3 }}
{{- $moduleName = (include "helm_lib_module_camelcase_name" (index . 2)) }} {{- /* Optional module name */ -}}
{{- end }}
{{- $imageDigest := index $context.Values.global.modulesImages.digests $moduleName $containerName }}
{{- if $imageDigest }}
{{- $registryBase := $context.Values.global.modulesImages.registry.base }}
{{- if index $context.Values $moduleName }}
{{- if index $context.Values $moduleName "registry" }}
{{- if index $context.Values $moduleName "registry" "base" }}
{{- $host := trimAll "/" (index $context.Values $moduleName "registry" "base") }}
{{- $path := trimAll "/" $context.Chart.Name }}
{{- $registryBase = join "/" (list $host $path) }}
{{- end }}
{{- end }}
{{- end }}
{{- printf "%s@%s" $registryBase $imageDigest }}
{{- end }}
{{- end }}
{{- /* Usage: {{ include "helm_lib_module_common_image" (list . "<container-name>") }} */ -}}
{{- /* returns image name from common module */ -}}
{{- define "helm_lib_module_common_image" }}
{{- $context := index . 0 }} {{- /* Template context with .Values, .Chart, etc */ -}}
{{- $containerName := index . 1 | trimAll "\"" }} {{- /* Container name */ -}}
{{- $imageDigest := index $context.Values.global.modulesImages.digests "common" $containerName }}
{{- if not $imageDigest }}
{{- $error := (printf "Image %s.%s has no digest" "common" $containerName ) }}
{{- fail $error }}
{{- end }}
{{- printf "%s@%s" $context.Values.global.modulesImages.registry.base $imageDigest }}
{{- end }}
{{- /* Usage: {{ include "helm_lib_module_common_image_no_fail" (list . "<container-name>") }} */ -}}
{{- /* returns image name from common module if found */ -}}
{{- define "helm_lib_module_common_image_no_fail" }}
{{- $context := index . 0 }} {{- /* Template context with .Values, .Chart, etc */ -}}
{{- $containerName := index . 1 | trimAll "\"" }} {{- /* Container name */ -}}
{{- $imageDigest := index $context.Values.global.modulesImages.digests "common" $containerName }}
{{- if $imageDigest }}
{{- printf "%s@%s" $context.Values.global.modulesImages.registry.base $imageDigest }}
{{- end }}
{{- end }}