From bfc62b0a5839f1e6e4aa67fbfbab90bc7bb02488 Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Fri, 14 Apr 2023 10:44:06 +0300 Subject: [PATCH] Add void caps for nvidia when no gpu is selected (#385) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes https://github.com/truecharts/charts/issues/7955 Fixes transcoding issue https://discord.com/channels/830763548678291466/1096125658498867252/1096146172911030282 **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** **📃 Notes:** **✔️ Checklist:** - [ ] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [ ] ⚠️ My changes generate no new warnings - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🪞 I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --- .../tests/container/envFixed_test .yaml | 12 +++++- .../tests/initContainer/data_test.yaml | 43 +++++++++++++++++++ .../initContainer/data_upgrade_test.yaml | 43 +++++++++++++++++++ .../tests/pod/securityContext.yaml | 4 ++ library/common/Chart.yaml | 2 +- .../templates/lib/container/_fixedEnv.tpl | 2 + .../templates/lib/pod/_podSecurityContext.tpl | 2 +- 7 files changed, 105 insertions(+), 3 deletions(-) diff --git a/library/common-test/tests/container/envFixed_test .yaml b/library/common-test/tests/container/envFixed_test .yaml index 84e52529..d8c0e1f8 100644 --- a/library/common-test/tests/container/envFixed_test .yaml +++ b/library/common-test/tests/container/envFixed_test .yaml @@ -45,6 +45,8 @@ tests: value: "0022" - name: UMASK_SET value: "0022" + - name: NVIDIA_DRIVER_CAPABILITIES + value: "void" - name: S6_READ_ONLY_ROOT value: "1" @@ -87,6 +89,8 @@ tests: value: "0022" - name: UMASK_SET value: "0022" + - name: NVIDIA_DRIVER_CAPABILITIES + value: "void" - name: PUID value: "568" - name: USER_ID @@ -143,6 +147,8 @@ tests: value: "0022" - name: UMASK_SET value: "0022" + - name: NVIDIA_DRIVER_CAPABILITIES + value: "void" - name: PUID value: "568" - name: USER_ID @@ -198,6 +204,8 @@ tests: value: "0022" - name: UMASK_SET value: "0022" + - name: NVIDIA_DRIVER_CAPABILITIES + value: "void" - name: PUID value: "568" - name: USER_ID @@ -260,7 +268,7 @@ tests: - name: S6_READ_ONLY_ROOT value: "1" - - it: should create the correct fixed envs with GPU and overrided on container level + - it: should create the correct fixed envs with GPU and overridden on container level set: scaleGPU: - gpu: @@ -351,6 +359,8 @@ tests: value: "0022" - name: UMASK_SET value: "0022" + - name: NVIDIA_DRIVER_CAPABILITIES + value: "void" - name: PUID value: "0" - name: USER_ID diff --git a/library/common-test/tests/initContainer/data_test.yaml b/library/common-test/tests/initContainer/data_test.yaml index d6c25629..60c8c387 100644 --- a/library/common-test/tests/initContainer/data_test.yaml +++ b/library/common-test/tests/initContainer/data_test.yaml @@ -135,6 +135,8 @@ tests: value: "0022" - name: "UMASK_SET" value: "0022" + - name: NVIDIA_DRIVER_CAPABILITIES + value: "void" - name: "S6_READ_ONLY_ROOT" value: "1" - name: "key" @@ -187,3 +189,44 @@ tests: - documentIndex: *deploymentDoc isNull: path: spec.template.spec.initContainers[2] + + - it: should NOT generate render init container + set: + render: false + image: + repository: nginx + tag: 1.19.0 + pullPolicy: IfNotPresent + workload: + workload-name: + enabled: true + primary: true + type: Deployment + podSpec: + containers: + container-name1: + enabled: true + primary: true + imageSelector: image + probes: + liveness: + enabled: false + readiness: + enabled: false + startup: + enabled: false + initContainers: + container-name1: + enabled: "{{ .Values.render }}" + type: init + imageSelector: image + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *deploymentDoc + isAPIVersion: + of: apps/v1 + - documentIndex: *deploymentDoc + isNull: + path: spec.template.spec.initContainers diff --git a/library/common-test/tests/initContainer/data_upgrade_test.yaml b/library/common-test/tests/initContainer/data_upgrade_test.yaml index e7987fc4..23591831 100644 --- a/library/common-test/tests/initContainer/data_upgrade_test.yaml +++ b/library/common-test/tests/initContainer/data_upgrade_test.yaml @@ -140,6 +140,8 @@ tests: value: "0022" - name: "UMASK_SET" value: "0022" + - name: NVIDIA_DRIVER_CAPABILITIES + value: "void" - name: "S6_READ_ONLY_ROOT" value: "1" - name: "key" @@ -189,3 +191,44 @@ tests: - documentIndex: *deploymentDoc isNull: path: spec.template.spec.initContainers[2] + + - it: should NOT generate render init container + set: + render: false + image: + repository: nginx + tag: 1.19.0 + pullPolicy: IfNotPresent + workload: + workload-name: + enabled: true + primary: true + type: Deployment + podSpec: + containers: + container-name1: + enabled: true + primary: true + imageSelector: image + probes: + liveness: + enabled: false + readiness: + enabled: false + startup: + enabled: false + initContainers: + container-name1: + enabled: "{{ .Values.render }}" + type: upgrade + imageSelector: image + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *deploymentDoc + isAPIVersion: + of: apps/v1 + - documentIndex: *deploymentDoc + isNull: + path: spec.template.spec.initContainers diff --git a/library/common-test/tests/pod/securityContext.yaml b/library/common-test/tests/pod/securityContext.yaml index ddeed5c7..5f642fa9 100644 --- a/library/common-test/tests/pod/securityContext.yaml +++ b/library/common-test/tests/pod/securityContext.yaml @@ -284,6 +284,7 @@ tests: supplementalGroups: - 1000 - 44 + - 107 sysctls: [] - documentIndex: &otherDeploymentDoc 1 isKind: @@ -332,6 +333,7 @@ tests: supplementalGroups: - 1000 - 44 + - 107 sysctls: [] - documentIndex: &otherDeploymentDoc 1 isKind: @@ -382,6 +384,7 @@ tests: supplementalGroups: - 1000 - 44 + - 107 sysctls: [] - documentIndex: &otherDeploymentDoc 1 isKind: @@ -394,6 +397,7 @@ tests: fsGroupChangePolicy: OnRootMismatch supplementalGroups: - 44 + - 107 sysctls: [] - it: should pass with with device assigned to selected pod diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index f65562dc..172a4123 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 12.4.6 +version: 12.4.7 diff --git a/library/common/templates/lib/container/_fixedEnv.tpl b/library/common/templates/lib/container/_fixedEnv.tpl index 625467af..032997cb 100644 --- a/library/common/templates/lib/container/_fixedEnv.tpl +++ b/library/common/templates/lib/container/_fixedEnv.tpl @@ -47,6 +47,8 @@ objectData: The object data to be used to render the container. {{- $fixed = mustAppend $fixed (dict "k" "UMASK_SET" "v" $UMASK) -}} {{- if eq (include "tc.v1.common.lib.container.resources.gpu" (dict "rootCtx" $rootCtx "objectData" $objectData "returnBool" true)) "true" -}} {{- $fixed = mustAppend $fixed (dict "k" "NVIDIA_DRIVER_CAPABILITIES" "v" (join "," $nvidiaCaps)) -}} + {{- else -}} + {{- $fixed = mustAppend $fixed (dict "k" "NVIDIA_DRIVER_CAPABILITIES" "v" "void") -}} {{- end -}} {{/* If running as root and PUID is set (0 or greater), set related envs */}} {{- if and (or (eq (int $secContext.runAsUser) 0) (eq (int $secContext.runAsGroup) 0)) (ge (int $PUID) 0) -}} diff --git a/library/common/templates/lib/pod/_podSecurityContext.tpl b/library/common/templates/lib/pod/_podSecurityContext.tpl index 2e93fab0..4a1497ac 100644 --- a/library/common/templates/lib/pod/_podSecurityContext.tpl +++ b/library/common/templates/lib/pod/_podSecurityContext.tpl @@ -52,7 +52,7 @@ objectData: The object data to be used to render the Pod. {{- end -}} {{- if $gpuAdded -}} - {{- $_ := set $secContext "supplementalGroups" (concat $secContext.supplementalGroups (list 44)) -}} + {{- $_ := set $secContext "supplementalGroups" (concat $secContext.supplementalGroups (list 44 107)) -}} {{- end -}} {{- if $deviceAdded -}}