123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- {{- define "vm.port.from.flag" -}}
- {{- $port := .default -}}
- {{- with .flag -}}
- {{- $port = regexReplaceAll ".*:(\\d+)" . "${1}" -}}
- {{- end -}}
- {{- $port -}}
- {{- end }}
- {{- /*
- Return true if the detected platform is Openshift
- Usage:
- {{- include "vm.isOpenshift" . -}}
- */ -}}
- {{- define "vm.isOpenshift" -}}
- {{- $Capabilities := (.helm).Capabilities | default .Capabilities -}}
- {{- if $Capabilities.APIVersions.Has "security.openshift.io/v1" -}}
- {{- true -}}
- {{- end -}}
- {{- end -}}
- {{- /*
- Render a compatible securityContext depending on the platform.
- Usage:
- {{- include "vm.securityContext" (dict "securityContext" .Values.containerSecurityContext "helm" .) -}}
- */ -}}
- {{- define "vm.securityContext" -}}
- {{- $securityContext := .securityContext -}}
- {{- $Values := (.helm).Values | default .Values -}}
- {{- $adaptMode := (((($Values).global).compatibility).openshift).adaptSecurityContext | default "" -}}
- {{- if or (eq $adaptMode "force") (and (eq $adaptMode "auto") (include "vm.isOpenshift" .)) -}}
- {{- $securityContext = omit $securityContext "fsGroup" "runAsUser" "runAsGroup" -}}
- {{- if not $securityContext.seLinuxOptions -}}
- {{- $securityContext = omit $securityContext "seLinuxOptions" -}}
- {{- end -}}
- {{- end -}}
- {{- omit $securityContext "enabled" | toYaml -}}
- {{- end -}}
- {{- /*
- Render probe
- */ -}}
- {{- define "vm.probe" -}}
- {{- /* undefined value */ -}}
- {{- $null := (fromYaml "value: null").value -}}
- {{- $probe := dig .type (default dict) .app.probe -}}
- {{- $probeType := "" -}}
- {{- $defaultProbe := default dict -}}
- {{- if ne (dig "httpGet" $null $probe) $null -}}
- {{- /* httpGet probe */ -}}
- {{- $defaultProbe = dict "path" (include "vm.probe.http.path" .) "scheme" (include "vm.probe.http.scheme" .) "port" (include "vm.probe.port" .) -}}
- {{- $probeType = "httpGet" -}}
- {{- else if ne (dig "tcpSocket" $null $probe) $null -}}
- {{- /* tcpSocket probe */ -}}
- {{- $defaultProbe = dict "port" (include "vm.probe.port" .) -}}
- {{- $probeType = "tcpSocket" -}}
- {{- end -}}
- {{- $defaultProbe = ternary (default dict) (dict $probeType $defaultProbe) (empty $probeType) -}}
- {{- $probe = mergeOverwrite $defaultProbe $probe -}}
- {{- range $key, $value := $probe -}}
- {{- if and (has (kindOf $value) (list "object" "map")) (ne $key $probeType) -}}
- {{- $_ := unset $probe $key -}}
- {{- end -}}
- {{- end -}}
- {{- tpl (toYaml $probe) . -}}
- {{- end -}}
- {{- /*
- HTTP GET probe path
- */ -}}
- {{- define "vm.probe.http.path" -}}
- {{- index .app.extraArgs "http.pathPrefix" | default "" | trimSuffix "/" -}}/health
- {{- end -}}
- {{- /*
- HTTP GET probe scheme
- */ -}}
- {{- define "vm.probe.http.scheme" -}}
- {{- ternary "HTTPS" "HTTP" (.app.extraArgs.tls | default false) -}}
- {{- end -}}
- {{- /*
- Net probe port
- */ -}}
- {{- define "vm.probe.port" -}}
- {{- dig "ports" "name" "http" (.app | dict) -}}
- {{- end -}}
- {{- define "vm.arg" -}}
- {{- if and (empty .value) (not (kindIs "bool" .value)) }}
- {{- .key -}}
- {{- else if and (kindIs "bool" .value) .value -}}
- -{{ ternary "" "-" (eq (len .key) 1) }}{{ .key }}
- {{- else -}}
- -{{ ternary "" "-" (eq (len .key) 1) }}{{ .key }}={{ .value }}
- {{- end -}}
- {{- end -}}
- {{- /*
- command line arguments
- */ -}}
- {{- define "vm.args" -}}
- {{- $args := default list -}}
- {{- range $key, $value := . -}}
- {{- if not $key -}}
- {{- fail "Empty key in command line args is not allowed" -}}
- {{- end -}}
- {{- if kindIs "slice" $value -}}
- {{- range $v := $value -}}
- {{- $args = append $args (include "vm.arg" (dict "key" $key "value" $v)) -}}
- {{- end -}}
- {{- else -}}
- {{- $args = append $args (include "vm.arg" (dict "key" $key "value" $value)) -}}
- {{- end -}}
- {{- end -}}
- {{- toYaml (dict "args" $args) -}}
- {{- end -}}
|