Skip to content

Commit

Permalink
feat: possibility to override image tag programmatically (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
oOraph authored Feb 23, 2023
1 parent 44d5eff commit a2d3760
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
8 changes: 4 additions & 4 deletions charts/common/templates/_images.tpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Return the proper image name
{{ include "hf.common.images.image" ( dict "imageRoot" .Values.path.to.the.image "global" .Values.global ) }}
{{ include "hf.common.images.image" ( dict "imageRoot" .Values.path.to.the.image "global" .Values.global "tag" .Chart.AppVersion ) }}
*/}}
{{- define "hf.common.images.image" -}}
{{- $useGlobalRegistry := or (not (hasKey .imageRoot "useGlobalRegistry")) .imageRoot.useGlobalRegistry -}}
{{- $registryName := .imageRoot.registry -}}
{{- $repositoryName := .imageRoot.repository -}}
{{- $separator := ":" -}}
{{- $termination := .imageRoot.tag | toString -}}
{{- $termination := .imageRoot.tag | default .tag | toString -}}
{{- if .global }}
{{- if and .global.imageRegistry $useGlobalRegistry }}
{{- $registryName = .global.imageRegistry -}}
Expand All @@ -33,7 +33,7 @@ Return the proper Docker Image Registry Secret Names evaluating values as templa
{{- $pullSecrets := list }}
{{- $context := .context }}

{{- if $context.Values.global.huggingface }}
{{- if and $context $context.Values $context.Values.global $context.Values.global.huggingface $context.Values.global.huggingface.imagePullSecrets }}
{{- range $context.Values.global.huggingface.imagePullSecrets -}}
{{- $pullSecrets = append $pullSecrets (include "hf.common.tplvalues.render" (dict "value" . "context" $context)) -}}
{{- end -}}
Expand All @@ -51,4 +51,4 @@ imagePullSecrets:
- name: {{ . }}
{{- end }}
{{- end }}
{{- end -}}
{{- end -}}
8 changes: 6 additions & 2 deletions charts/unit-tests/templates/_helpers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
{{- end -}}

{{- define "appManager.image" -}}
{{ include "hf.common.images.image" (dict "imageRoot" .Values.images.appManager "global" .Values.global.huggingface) | quote }}
{{ include "hf.common.images.image" (dict "imageRoot" .Values.images.appManager "global" .Values.global.huggingface "tag" .Chart.AppVersion) | quote }}
{{- end -}}

{{- define "someApp.image" -}}
{{ include "hf.common.images.image" (dict "imageRoot" .Values.images.someApp "global" .Values.global.huggingface "tag" .Chart.AppVersion) | quote }}
{{- end -}}

{{- define "test.imagePullSecrets" -}}
{{ include "hf.common.images.renderPullSecrets" (dict "images" (list .Values.images) "context" $) }}
{{- end -}}
{{- end -}}
5 changes: 4 additions & 1 deletion charts/unit-tests/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ spec:
imagePullPolicy: {{ .Values.images.pullPolicy }}
- name: test-global-registry
image: {{ include "appManager.image" . }}
imagePullPolicy: {{ .Values.images.pullPolicy }}
imagePullPolicy: {{ .Values.images.pullPolicy }}
- name: hello-world
image: {{ include "someApp.image" . }}
imagePullPolicy: {{ .Values.images.pullPolicy }}
12 changes: 12 additions & 0 deletions charts/unit-tests/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ tests:
path: spec.template.spec.containers[2].image
value: spaces/app-manager:latest

- it: deployment should have the correct image tag reflecting chart appVersion
values:
- test-values.yaml
template: deployment.yaml
asserts:
- equal:
path: spec.template.spec.containers[3].name
value: hello-world
- equal:
path: spec.template.spec.containers[3].image
value: hello/world:1.0.0

- it: deployment shouldn't have imagePullSecret
values:
- test-values.yaml
Expand Down
2 changes: 2 additions & 0 deletions charts/unit-tests/tests/test-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ images:
appManager:
repository: spaces/app-manager
tag: latest
someApp:
repository: hello/world

0 comments on commit a2d3760

Please sign in to comment.