diff --git a/library/common-test/tests/pod/deployment_container_command-arg_test.yaml b/library/common-test/tests/pod/deployment_container_command-arg_test.yaml index cdde4786..00958774 100644 --- a/library/common-test/tests/pod/deployment_container_command-arg_test.yaml +++ b/library/common-test/tests/pod/deployment_container_command-arg_test.yaml @@ -8,6 +8,27 @@ tests: isKind: of: Deployment + - it: should pass with command set single value + set: + command: entrypoint.sh + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.containers[0].command + value: + - entrypoint.sh + + - it: should pass with command set single value from tpl + set: + cmd: entrypoint.sh + command: "{{ .Values.cmd }}" + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.containers[0].command + value: + - entrypoint.sh + - it: should pass with command set set: command: @@ -54,6 +75,27 @@ tests: - /bin/bash - some_value + - it: should pass with args set with single value + set: + args: --worker + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.containers[0].args + value: + - --worker + + - it: should pass with args set with single value from tpl + set: + some_arg: --worker + args: "{{ .Values.some_arg }}" + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.containers[0].args + value: + - --worker + - it: should pass with args set set: args: @@ -81,6 +123,27 @@ tests: - --port - "9000" + - it: should pass with extraArgs set single value + set: + extraArgs: --worker + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.containers[0].args + value: + - --worker + + - it: should pass with extraArgs set single value from tpl + set: + some_extra_arg: --worker + extraArgs: "{{ .Values.some_extra_arg }}" + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.containers[0].args + value: + - --worker + - it: should pass with extraArgs set set: extraArgs: @@ -145,3 +208,29 @@ tests: - "9000" - --photos - /photos + + - it: should pass with args and extraArgs set - single values + set: + args: --path + extraArgs: /photos + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.containers[0].args + value: + - --path + - /photos + + - it: should pass with args and extraArgs set from tpl - single values + set: + some_arg: --path + some_path: /photos + args: "{{ .Values.some_arg }}" + extraArgs: "{{ .Values.some_path }}" + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.containers[0].args + value: + - --path + - /photos diff --git a/library/common-test/tests/pod/deployment_container_env_test.yaml b/library/common-test/tests/pod/deployment_container_env_test.yaml index 0d0807e5..8e11d6d5 100644 --- a/library/common-test/tests/pod/deployment_container_env_test.yaml +++ b/library/common-test/tests/pod/deployment_container_env_test.yaml @@ -563,3 +563,44 @@ tests: optional: false name: some_name key: some_key + + - it: should pass with envs defined with scaleGPU + set: + scaleGPU: true + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.containers[0].env + value: + - name: TZ + value: "UTC" + - name: UMASK + value: "2" + - name: UMASK_SET + value: "2" + - name: NVIDIA_DRIVER_CAPABILITIES + value: "all" + - name: S6_READ_ONLY_ROOT + value: "1" + + - it: should pass with envs defined with scaleGPU and custom capabilities + set: + scaleGPU: true + nvidiaCaps: + - compute + - utility + asserts: + - equal: + documentIndex: *deploymentDoc + path: spec.template.spec.containers[0].env + value: + - name: TZ + value: "UTC" + - name: UMASK + value: "2" + - name: UMASK_SET + value: "2" + - name: NVIDIA_DRIVER_CAPABILITIES + value: "compute,utility" + - name: S6_READ_ONLY_ROOT + value: "1" diff --git a/library/common/1.0.0/templates/lib/container/_args.tpl b/library/common/1.0.0/templates/lib/container/_args.tpl new file mode 100644 index 00000000..7ca61a7a --- /dev/null +++ b/library/common/1.0.0/templates/lib/container/_args.tpl @@ -0,0 +1,28 @@ +{{/* Args included by the container */}} +{{- define "ix.v1.common.container.args" -}} +{{- $args := .args -}} +{{- $extraArgs := .extraArgs -}} +{{- $root := .root -}} +{{- with $args -}} {{/* args usually defined while developing the chart */}} + {{- if kindIs "string" . -}} +- {{ tpl . $root }} + {{- else }} + {{- tpl (toYaml .) $root }} + {{- end }} +{{- end }} +{{- with $extraArgs }} {{/* extraArgs used in cases that users wants to APPEND to args */}} + {{- if kindIs "string" . }} +- {{ tpl . $root }} + {{- else }} + {{- tpl (toYaml .) $root | nindent 0 }} {{/* This nindent is here beacause... Well I've no idea why, but it works only with this here. Sorry */}} + {{- end }} +{{- end }} +{{- end -}} + +{{/* +A custom dict is expected with args, extraArgs and root. +It's designed to work for mainContainer AND initContainers. +Calling this from an initContainer, wouldn't work, as it would have a different "root" context, +and "tpl" on "$" would cause erors. +That's why the custom dict is expected. +*/}} diff --git a/library/common/1.0.0/templates/lib/container/_command.tpl b/library/common/1.0.0/templates/lib/container/_command.tpl new file mode 100644 index 00000000..1429b9ab --- /dev/null +++ b/library/common/1.0.0/templates/lib/container/_command.tpl @@ -0,0 +1,18 @@ +{{/* Command included by the container */}} +{{- define "ix.v1.common.container.command" -}} +{{- $commands := .commands -}} +{{- $root := .root -}} +{{- if kindIs "string" $commands -}} +- {{ tpl $commands $root }} +{{- else }} + {{- tpl (toYaml $commands) $root }} +{{- end }} +{{- end -}} + +{{/* +A custom dict is expected with commands and root. +It's designed to work for mainContainer AND initContainers. +Calling this from an initContainer, wouldn't work, as it would have a different "root" context, +and "tpl" on "$" would cause erors. +That's why the custom dict is expected. +*/}} diff --git a/library/common/1.0.0/templates/lib/container/_env_vars.tpl b/library/common/1.0.0/templates/lib/container/_env_vars.tpl index 8f9b9057..cf58c8ac 100644 --- a/library/common/1.0.0/templates/lib/container/_env_vars.tpl +++ b/library/common/1.0.0/templates/lib/container/_env_vars.tpl @@ -1,6 +1,8 @@ {{/* Environment Variables included by the container */}} {{- define "ix.v1.common.container.envVars" -}} -{{- with .Values.env -}} +{{- $envs := .envs -}} +{{- $root := .root -}} +{{- with $envs -}} {{- range $k, $v := . -}} {{- $name := $k -}} {{- $value := $v -}} @@ -10,7 +12,7 @@ - name: {{ $name | quote }} {{- if not (kindIs "map" $value) }} {{- if or (kindIs "string" $value) }} {{/* Single values are parsed as string (eg. int, bool) */}} - {{- $value = tpl $value $ }} {{/* Expand Value */}} + {{- $value = tpl $value $root }} {{/* Expand Value */}} {{- end }} value: {{ quote $value }} {{- else if kindIs "map" $value }} {{/* If value is a dict... */}} @@ -33,9 +35,17 @@ {{- else }} {{- fail "Not a valid valueFrom reference. Valid options are (configMapKeyRef and secretKeyRef)" -}} {{- end }} - name: {{ tpl (required (printf " for the keyRef is not defined in (%s)" $name) $value.name) $ }} {{/* Expand name and key */}} - key: {{ tpl (required (printf " for the keyRef is not defined in (%s)" $name) $value.key) $ }} + name: {{ tpl (required (printf " for the keyRef is not defined in (%s)" $name) $value.name) $root }} {{/* Expand name and key */}} + key: {{ tpl (required (printf " for the keyRef is not defined in (%s)" $name) $value.key) $root }} {{- end }} {{- end }} {{- end }} {{- end -}} + +{{/* +A custom dict is expected with envs and root. +It's designed to work for mainContainer AND initContainers. +Calling this from an initContainer, wouldn't work, as it would have a different "root" context, +and "tpl" on "$" would cause erors. +That's why the custom dict is expected. +*/}} diff --git a/library/common/1.0.0/templates/lib/controller/_container.tpl b/library/common/1.0.0/templates/lib/controller/_container.tpl index 1a07ba50..aaf53efc 100644 --- a/library/common/1.0.0/templates/lib/controller/_container.tpl +++ b/library/common/1.0.0/templates/lib/controller/_container.tpl @@ -3,30 +3,20 @@ - name: {{ include "ix.v1.common.names.fullname" . }} image: {{/* TODO: */}} imagePullPolicy: {{ .Values.image.pullPolicy }} - {{- with .Values.command }} + {{- if .Values.command }} command: - {{- if kindIs "string" . }} - - {{ tpl . $ }} - {{- else }} - {{- tpl (toYaml .) $ | nindent 4 }} - {{- end }} + {{- $context := dict -}} {{/* Create a new context and pass it to envVars include, so tpl can work. */}} + {{- $_ := set $context "commands" .Values.command -}} + {{- $_ := set $context "root" $ -}} + {{- include "ix.v1.common.container.command" $context | nindent 4 }} {{- end }} {{- if or (.Values.extraArgs) (.Values.args) }} args: - {{- with .Values.args }} {{/* args usually defined while developing the chart */}} - {{- if kindIs "string" . }} - - {{ tpl . $ }} - {{- else }} - {{- tpl (toYaml .) $ | nindent 4 }} - {{- end }} - {{- end }} - {{- with .Values.extraArgs }} {{/* extraArgs used in cases that users wants to APPEND to args */}} - {{- if kindIs "string" . }} - - {{ tpl . $ }} - {{- else }} - {{- tpl (toYaml .) $ | nindent 4 }} - {{- end }} - {{- end }} + {{- $context := dict -}} {{/* Create a new context and pass it to envVars include, so tpl can work. */}} + {{- $_ := set $context "args" .Values.args -}} + {{- $_ := set $context "extraArgs" .Values.extraArgs -}} + {{- $_ := set $context "root" $ -}} + {{- include "ix.v1.common.container.args" $context | nindent 4 }} {{- end }} {{- if .Values.tty }} tty: true @@ -60,9 +50,9 @@ {{- if not (.Values.scaleGPU) }} - name: NVIDIA_VISIBLE_DEVICES value: "void" - {{- else }} {{/* TODO: Discuss if we want to pass specific capabilites */}} + {{- else }} - name: NVIDIA_DRIVER_CAPABILITIES - value: "all" + value: {{ join "," .Values.nvidiaCaps | quote }} {{- end }} {{- if and (or (not .Values.podSecurityContext.runAsUser) (not .Values.podSecurityContext.runAsGroup)) (or .Values.security.PUID (eq (.Values.security.PUID | int) 0)) }} {{/* If root user or root group and a PUID is set, set PUID and related envs */}} - name: PUID @@ -82,7 +72,10 @@ - name: S6_READ_ONLY_ROOT value: "1" {{- end }} - {{- include "ix.v1.common.container.envVars" . | nindent 4 }} + {{- $context := dict -}} {{/* Create a new context and pass it to envVars include, so tpl can work. */}} + {{- $_ := set $context "envs" .Values.env -}} + {{- $_ := set $context "root" $ -}} + {{- include "ix.v1.common.container.envVars" $context | nindent 4 }} {{- end -}} {{/* diff --git a/library/common/1.0.0/values.yaml b/library/common/1.0.0/values.yaml index 3b22cde5..ded40873 100644 --- a/library/common/1.0.0/values.yaml +++ b/library/common/1.0.0/values.yaml @@ -79,6 +79,10 @@ termination: # -- Used to add SCALE GPU configuration scaleGPU: +# -- Set specific NVIDIA Capabilities +nvidiaCaps: + - all + # -- Set Container Timezone TZ: UTC @@ -95,6 +99,7 @@ security: # configMapKeyRef | secretKeyRef: # name: object-name | "{{ .Values.objectName }}" # key: key-name | "{{ .Values.some_key }}" +# optional: false (ony with secretKeyRef) env: {} controller: