mirror of
https://github.com/truenas/charts.git
synced 2024-04-21 15:21:45 +00:00
make some functions reusable
This commit is contained in:
@@ -6,10 +6,12 @@
|
||||
{{- end -}}
|
||||
|
||||
{{- define "ix.v1.common.images.selector" -}}
|
||||
{{- $image := get .Values "image" -}}
|
||||
{{- $selected := .Values.imageSelector -}}
|
||||
{{- if hasKey .Values $selected -}}
|
||||
{{- $image = get .Values $selected -}}
|
||||
{{- $root := .root -}}
|
||||
{{- $selectedImage := .selectedImage -}}
|
||||
|
||||
{{- $image := get $root.Values "image" -}}
|
||||
{{- if hasKey $root.Values $selectedImage -}}
|
||||
{{- $image = get $root.Values $selectedImage -}}
|
||||
{{- end -}}
|
||||
{{- include "ix.v1.common.images.image" (dict "imageRoot" $image) -}}
|
||||
{{- end -}}
|
||||
|
||||
@@ -1,28 +1,31 @@
|
||||
{{/* Returns the lifecycle for the container */}}
|
||||
{{- define "ix.v1.common.container.lifecycle" -}}
|
||||
{{- with .Values.lifecycle -}}
|
||||
{{- $root := .root -}}
|
||||
{{- $lifecycle := .lifecycle -}}
|
||||
|
||||
{{- with $lifecycle -}}
|
||||
{{- range $k, $v := . -}}
|
||||
{{- if not (mustHas $k (list "preStop" "postStart")) -}}
|
||||
{{- fail (printf "Invalid key (%s) in lifecycle. Valid keys are preStop and postStart" $k) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if (hasKey .Values.lifecycle "preStop") -}}
|
||||
{{- with .Values.lifecycle.preStop.command }}
|
||||
{{- if (hasKey $lifecycle "preStop") -}}
|
||||
{{- with $lifecycle.preStop.command }}
|
||||
{{- print "preStop:" | nindent 0 }}
|
||||
{{- print "exec:" | nindent 2 }}
|
||||
{{- print "command:" | nindent 4 }}
|
||||
{{- include "ix.v1.common.container.command" (dict "commands" . "root" $) | trim | nindent 6 }}
|
||||
{{- include "ix.v1.common.container.command" (dict "commands" . "root" $root) | trim | nindent 6 }}
|
||||
{{- else -}}
|
||||
{{- fail "No commands were given for preStop lifecycle hook" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if (hasKey .Values.lifecycle "postStart") -}}
|
||||
{{- with .Values.lifecycle.postStart.command }}
|
||||
{{- if (hasKey $lifecycle "postStart") -}}
|
||||
{{- with $lifecycle.postStart.command }}
|
||||
{{- print "postStart:" | nindent 0 }}
|
||||
{{- print "exec:" | nindent 2 }}
|
||||
{{- print "command:" | nindent 4 }}
|
||||
{{- include "ix.v1.common.container.command" (dict "commands" . "root" $) | trim | nindent 6 }}
|
||||
{{- include "ix.v1.common.container.command" (dict "commands" . "root" $root) | trim | nindent 6 }}
|
||||
{{- else -}}
|
||||
{{- fail "No commands were given for postStart lifecycle hook" -}}
|
||||
{{- end -}}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
{{/* Returns the terminationMessagePath for the container */}}
|
||||
{{- define "ix.v1.common.container.termination.messagePath" -}}
|
||||
{{- tpl .Values.termination.messagePath $ }}
|
||||
{{- $msgPath := .msgPath -}}
|
||||
{{- $root := .root -}}
|
||||
|
||||
{{- tpl $msgPath $root -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Returns the terminationMessagePolicy for the container */}}
|
||||
{{- define "ix.v1.common.container.termination.messagePolicy" -}}
|
||||
{{- $policy := (tpl .Values.termination.messagePolicy $) -}}
|
||||
{{- $msgPolicy := .msgPolicy -}}
|
||||
{{- $root := .root -}}
|
||||
|
||||
{{- $policy := (tpl $msgPolicy $root) -}}
|
||||
{{- with $policy -}}
|
||||
{{- if not (mustHas . (list "File" "FallbackToLogsOnError")) }}
|
||||
{{- fail "Not valid option for messagePolicy" -}}
|
||||
|
||||
@@ -9,7 +9,7 @@ So it can work on multiple places, like additional containers and not only the m
|
||||
*/}}
|
||||
{{- define "ix.v1.common.controller.mainContainer" -}}
|
||||
- name: {{ include "ix.v1.common.names.fullname" . }}
|
||||
image: {{ include "ix.v1.common.images.selector" . }}
|
||||
image: {{ include "ix.v1.common.images.selector" (dict "root" . "selectedImage" .Values.imageSelector ) }}
|
||||
imagePullPolicy: {{ include "ix.v1.common.images.pullPolicy" (dict "policy" .Values.image.pullPolicy) }}
|
||||
tty: {{ .Values.tty }}
|
||||
stdin: {{ .Values.stdin }}
|
||||
@@ -25,14 +25,14 @@ So it can work on multiple places, like additional containers and not only the m
|
||||
securityContext:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end -}}
|
||||
{{- with (include "ix.v1.common.container.lifecycle" .) | trim }}
|
||||
{{- with (include "ix.v1.common.container.lifecycle" (dict "lifecycle" .Values.lifecycle "root" $)) | trim }}
|
||||
lifecycle:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end }}
|
||||
{{- with (include "ix.v1.common.container.termination.messagePath" .) | trim }}
|
||||
{{- with (include "ix.v1.common.container.termination.messagePath" (dict "msgPath" .Values.termination.messagePath "root" $)) | trim }}
|
||||
terminationMessagePath: {{ . }}
|
||||
{{- end }}
|
||||
{{- with (include "ix.v1.common.container.termination.messagePolicy" .) | trim }}
|
||||
{{- with (include "ix.v1.common.container.termination.messagePolicy" (dict "msgPolicy" .Values.termination.messagePolicy "root" $)) | trim }}
|
||||
terminationMessagePolicy: {{ . }}
|
||||
{{- end -}}
|
||||
{{- with (include "ix.v1.common.container.envVars" (dict "envs" .Values.env "envList" .Values.envList "root" $) | trim) }}
|
||||
|
||||
Reference in New Issue
Block a user