diff --git a/library/common/1.0.0/templates/lib/container/_resouces.tpl b/library/common/1.0.0/templates/lib/container/_resouces.tpl deleted file mode 100644 index ca8c7c7e31..0000000000 --- a/library/common/1.0.0/templates/lib/container/_resouces.tpl +++ /dev/null @@ -1,47 +0,0 @@ -{{/* Returns the resources for the container */}} -{{- define "ix.v1.common.container.resources" -}} - {{- $resources := .resources -}} - {{- $gpu := .gpu -}} - - {{- if or $resources $gpu -}} - {{- with $resources.requests -}} - {{- with (include "ix.v1.common.container.resources.cpuAndMemory" (dict "cpu" .cpu "memory" .memory)) -}} -requests: - {{- . | indent 2 -}} - {{- end -}} - {{- end -}} - {{- if or $resources.limits $gpu -}} - {{- if or $resources.limits.cpu $resources.limits.memory $gpu }} -limits: - {{- include "ix.v1.common.container.resources.cpuAndMemory" (dict "cpu" $resources.limits.cpu "memory" $resources.limits.memory) | indent 2 -}} - {{- include "ix.v1.common.container.resources.gpu" (dict "gpu" $gpu) | indent 2 -}} - {{- end -}} - {{- end -}} - {{- end -}} -{{- end -}} - -{{/* Returns CPU and Memory if applicable */}} -{{- define "ix.v1.common.container.resources.cpuAndMemory" -}} - {{- $cpu := .cpu -}} - {{- $memory := .memory -}} - - {{- with $cpu }} -cpu: {{ . }} - {{- end -}} - {{- with $memory }} -memory: {{ . }} - {{- end -}} -{{- end -}} - -{{/* Returns GPU if applicable */}} -{{- define "ix.v1.common.container.resources.gpu" -}} - {{- $gpu := .gpu -}} - - {{- range $k, $v := $gpu -}} - {{- if not $v -}} - {{- fail (printf "Value is not provided for GPU ( %s)" $k) -}} - {{- else }} -{{ $k }}: {{ $v | quote }} - {{- end -}} - {{- end -}} -{{- end -}} diff --git a/library/common/1.0.0/templates/lib/container/_resources.tpl b/library/common/1.0.0/templates/lib/container/_resources.tpl new file mode 100644 index 0000000000..88fcd13c38 --- /dev/null +++ b/library/common/1.0.0/templates/lib/container/_resources.tpl @@ -0,0 +1,89 @@ +{{/* Returns the resources for the container */}} +{{- define "ix.v1.common.container.resources" -}} + {{- $resources := .resources -}} + {{- $gpu := .gpu -}} + {{- $root := .root -}} + + {{/* Get defaults from global */}} + {{- $defautlResources := $root.Values.global.defaults.resources -}} + {{- $limitsCPU := $defautlResources.limits.cpu -}} + {{- $limitsMemory := $defautlResources.limits.memory -}} + {{- $requestsCPU := $defautlResources.requests.cpu -}} + {{- $requestsMemory := $defautlResources.requests.memory -}} + + {{/* Modify based on user/dev input */}} + {{- with $resources -}} + {{- with $resources.requests -}} + {{- if hasKey . "cpu" -}} + {{- if ne $requestsCPU .cpu -}} + {{- $requestsCPU = .cpu -}} + {{- else if not .cpu -}} {{/* If key exists but it's empty, means user/dev explicitly said "no limit" */}} + {{- $requestsCPU = "" -}} + {{- end -}} + {{- end -}} + {{- if hasKey . "memory" -}} + {{- if ne $requestsMemory .memory -}} + {{- $requestsMemory = .memory -}} + {{- else if not .memory -}} {{/* If key exists but it's empty, means user/dev explicitly said "no limit" */}} + {{- $requestsMemory = "" -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- with $resources.limits -}} + {{- if hasKey . "cpu" -}} + {{- if ne $limitsCPU .cpu -}} + {{- $limitsCPU = .cpu -}} + {{- else if not .cpu -}} {{/* If key exists but it's empty, means user/dev explicitly said "no limit" */}} + {{- $limitsCPU = "" -}} + {{- end -}} + {{- end -}} + {{- if hasKey . "memory" -}} + {{- if ne $limitsMemory .memory -}} + {{- $limitsMemory = .memory -}} + {{- else if not .memory -}} {{/* If key exists but it's empty, means user/dev explicitly said "no limit" */}} + {{- $limitsMemory = "" -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- if or $resources $defautlResources $gpu -}} + {{- if or $requestsCPU $requestsMemory -}} + {{- with (include "ix.v1.common.container.resources.cpuAndMemory" (dict "cpu" $requestsCPU "memory" $requestsMemory)) }} +requests: + {{- . | indent 2 -}} + {{- end -}} + {{- end -}} + {{- if or $limitsCPU $limitsMemory $gpu }} +limits: + {{- include "ix.v1.common.container.resources.cpuAndMemory" (dict "cpu" $limitsCPU "memory" $limitsMemory) | indent 2 -}} + {{- include "ix.v1.common.container.resources.gpu" (dict "gpu" $gpu) | indent 2 -}} + {{- end -}} + {{- end -}} +{{- end -}} + +{{/* Returns CPU and Memory if applicable */}} +{{- define "ix.v1.common.container.resources.cpuAndMemory" -}} + {{- $cpu := .cpu -}} + {{- $memory := .memory -}} + + {{- with $cpu }} +cpu: {{ . }} + {{- end -}} + {{- with $memory }} +memory: {{ . }} + {{- end -}} +{{- end -}} + +{{/* Returns GPU if applicable */}} +{{- define "ix.v1.common.container.resources.gpu" -}} + {{- $gpu := .gpu -}} + + {{- range $k, $v := $gpu -}} + {{- if not $v -}} + {{- fail (printf "Value is not provided for GPU ( %s)" $k) -}} + {{- else }} + {{- $k | nindent 0 }}: {{ $v | quote }} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/library/common/1.0.0/templates/lib/pod/volumes/_hostPath.tpl b/library/common/1.0.0/templates/lib/pod/volumes/_hostPath.tpl index 2f98ce820b..96cc210019 100644 --- a/library/common/1.0.0/templates/lib/pod/volumes/_hostPath.tpl +++ b/library/common/1.0.0/templates/lib/pod/volumes/_hostPath.tpl @@ -2,6 +2,7 @@ {{- $index := .index -}} {{- $vol := .volume -}} {{- $root := .root -}} + {{- include "ix.v1.common.controller.volumes.hostPath.validation" (dict "volume" $vol "root" $root) }} {{/* hostPath validation (if enabled) */}} - name: {{ $index }} hostPath: diff --git a/library/common/1.0.0/templates/lib/pod/volumes/_hostPathValidation.tpl b/library/common/1.0.0/templates/lib/pod/volumes/_hostPathValidation.tpl index 72cbf9a05d..6958b136b6 100644 --- a/library/common/1.0.0/templates/lib/pod/volumes/_hostPathValidation.tpl +++ b/library/common/1.0.0/templates/lib/pod/volumes/_hostPathValidation.tpl @@ -2,7 +2,7 @@ {{- $vol := .volume -}} {{- $root := .root -}} {{- $validate := $root.Values.global.defaults.validateHostPath -}} - W + {{- if (hasKey $vol "validateHostPath") -}} {{- $validate = $vol.validateHostPath -}} {{- end -}}