Get hands-on experience with Helm's Function capabilities.
estimated time: 10m
In this Tutorial we are going to have a basic look on how function works and what are the benefits of using them.
-
Cd to Lab03 and open the existing "Video" chart with visual studio code.
-
We are going to change the file called _helpers.tpl which holds the function definitions.
-
By using your amazing Reverse Engineering skils , Google , Helm Docs and Co-Pilot , perform the following :
- on deployment.yaml line 31 add the container security context from the values file.
- add a function called "video.image" that is concating the ACR name (Values.acr) the image name and the appVersion of the chart e.g "vicorpacr.azurecr.io"/indexing-service:1.16.0"
NOTE: the places to change / add code are marked with +++ADD_CODE_HERE+++
- Run the template in Lint Mode to ensure it is not missing values and/or has the right allignments.
Challange:_ What if Some day we would like to support Digest Tags and not Image Tags ?
helm lint video
Solution
on the _helpers.tpl function add the following {{/*
VI Image name
*/}}
{{- define "Video.image" -}}
{{- $separator := ":" -}}
{{- $termination := 1.16 | toString -}}
{{- if .Values.image.digest }}
{{- $separator = "@" -}}
{{- $termination = .Values.image.digest | toString -}}
{{- end -}}
{{- printf "%s/%s%s%s" .Values.image.acr .Values.image.repository $separator $termination }}
{{- end }}
Then , open deployment.yaml and change
securityContext:
+++ADD_CODE_HERE+++
image: +++ADD_CODE_HERE+++
to
securityContext:
{{- toYaml .Values.securityContext | nindent 10 }}
image: {{ include "Video.image" . }}