Skip to content

Commit a2d3760

Browse files
authored
feat: possibility to override image tag programmatically (#1)
1 parent 44d5eff commit a2d3760

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

charts/common/templates/_images.tpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{{/* vim: set filetype=mustache: */}}
22
{{/*
33
Return the proper image name
4-
{{ include "hf.common.images.image" ( dict "imageRoot" .Values.path.to.the.image "global" .Values.global ) }}
4+
{{ include "hf.common.images.image" ( dict "imageRoot" .Values.path.to.the.image "global" .Values.global "tag" .Chart.AppVersion ) }}
55
*/}}
66
{{- define "hf.common.images.image" -}}
77
{{- $useGlobalRegistry := or (not (hasKey .imageRoot "useGlobalRegistry")) .imageRoot.useGlobalRegistry -}}
88
{{- $registryName := .imageRoot.registry -}}
99
{{- $repositoryName := .imageRoot.repository -}}
1010
{{- $separator := ":" -}}
11-
{{- $termination := .imageRoot.tag | toString -}}
11+
{{- $termination := .imageRoot.tag | default .tag | toString -}}
1212
{{- if .global }}
1313
{{- if and .global.imageRegistry $useGlobalRegistry }}
1414
{{- $registryName = .global.imageRegistry -}}
@@ -33,7 +33,7 @@ Return the proper Docker Image Registry Secret Names evaluating values as templa
3333
{{- $pullSecrets := list }}
3434
{{- $context := .context }}
3535

36-
{{- if $context.Values.global.huggingface }}
36+
{{- if and $context $context.Values $context.Values.global $context.Values.global.huggingface $context.Values.global.huggingface.imagePullSecrets }}
3737
{{- range $context.Values.global.huggingface.imagePullSecrets -}}
3838
{{- $pullSecrets = append $pullSecrets (include "hf.common.tplvalues.render" (dict "value" . "context" $context)) -}}
3939
{{- end -}}
@@ -51,4 +51,4 @@ imagePullSecrets:
5151
- name: {{ . }}
5252
{{- end }}
5353
{{- end }}
54-
{{- end -}}
54+
{{- end -}}

charts/unit-tests/templates/_helpers.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
{{- end -}}
88

99
{{- define "appManager.image" -}}
10-
{{ include "hf.common.images.image" (dict "imageRoot" .Values.images.appManager "global" .Values.global.huggingface) | quote }}
10+
{{ include "hf.common.images.image" (dict "imageRoot" .Values.images.appManager "global" .Values.global.huggingface "tag" .Chart.AppVersion) | quote }}
11+
{{- end -}}
12+
13+
{{- define "someApp.image" -}}
14+
{{ include "hf.common.images.image" (dict "imageRoot" .Values.images.someApp "global" .Values.global.huggingface "tag" .Chart.AppVersion) | quote }}
1115
{{- end -}}
1216

1317
{{- define "test.imagePullSecrets" -}}
1418
{{ include "hf.common.images.renderPullSecrets" (dict "images" (list .Values.images) "context" $) }}
15-
{{- end -}}
19+
{{- end -}}

charts/unit-tests/templates/deployment.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ spec:
2121
imagePullPolicy: {{ .Values.images.pullPolicy }}
2222
- name: test-global-registry
2323
image: {{ include "appManager.image" . }}
24-
imagePullPolicy: {{ .Values.images.pullPolicy }}
24+
imagePullPolicy: {{ .Values.images.pullPolicy }}
25+
- name: hello-world
26+
image: {{ include "someApp.image" . }}
27+
imagePullPolicy: {{ .Values.images.pullPolicy }}

charts/unit-tests/tests/deployment_test.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ tests:
6565
path: spec.template.spec.containers[2].image
6666
value: spaces/app-manager:latest
6767

68+
- it: deployment should have the correct image tag reflecting chart appVersion
69+
values:
70+
- test-values.yaml
71+
template: deployment.yaml
72+
asserts:
73+
- equal:
74+
path: spec.template.spec.containers[3].name
75+
value: hello-world
76+
- equal:
77+
path: spec.template.spec.containers[3].image
78+
value: hello/world:1.0.0
79+
6880
- it: deployment shouldn't have imagePullSecret
6981
values:
7082
- test-values.yaml

charts/unit-tests/tests/test-values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ images:
2121
appManager:
2222
repository: spaces/app-manager
2323
tag: latest
24+
someApp:
25+
repository: hello/world

0 commit comments

Comments
 (0)