fix(resources): correctly handle "0" gpu (#389)

**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->
⚒️ Fixes https://github.com/truecharts/charts/issues/8004
⚒️ Fixes https://github.com/truecharts/charts/issues/8013 (OVPN needs
MKNOD)

**⚙️ 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?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ 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._
This commit is contained in:
Stavros Kois
2023-04-15 13:06:56 +03:00
committed by GitHub
parent 5e83604a29
commit 30bbceed01
8 changed files with 197 additions and 6 deletions

View File

@@ -13,6 +13,11 @@ tests:
env:
key: value
key1: value1
envList:
- name: key2
value: value2
- name: key3
value: value3
workload: &workload
main:
enabled: true
@@ -102,6 +107,18 @@ tests:
content:
name: key1
value: value1
- documentIndex: *DeploymentDocument
contains:
path: spec.template.spec.containers[1].env
content:
name: key2
value: value2
- documentIndex: *DeploymentDocument
contains:
path: spec.template.spec.containers[1].env
content:
name: key3
value: value3
- documentIndex: *DeploymentDocument
contains:
path: spec.template.spec.containers[1].volumeMounts

View File

@@ -628,6 +628,147 @@ tests:
cpu: 10m
memory: 50Mi
- it: should assign GPU on the selected pod/container with multiple GPUs
set:
image: *image
global:
ixChartContext:
addNvidiaRuntimeClass: true
nvidiaRuntimeClassName: nvidia
scaleGPU:
- gpu:
nvidia.com/gpu: 1
amd.com/gpu: 0
targetSelector:
workload-name1:
- container-name1
- container-name2
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
probes: *probes
container-name2:
enabled: true
primary: false
imageSelector: image
probes: *probes
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
equal:
path: spec.template.spec.runtimeClassName
value: nvidia
- documentIndex: *deploymentDoc
isSubset:
path: spec.template.spec.containers[0]
content:
resources:
limits:
cpu: 4000m
memory: 8Gi
nvidia.com/gpu: "1"
requests:
cpu: 10m
memory: 50Mi
- documentIndex: *deploymentDoc
isSubset:
path: spec.template.spec.containers[1]
content:
resources:
limits:
cpu: 4000m
memory: 8Gi
nvidia.com/gpu: "1"
requests:
cpu: 10m
memory: 50Mi
- it: should assign multiple GPU on the selected pod/container with multiple selected GPUs
set:
image: *image
global:
ixChartContext:
addNvidiaRuntimeClass: true
nvidiaRuntimeClassName: nvidia
scaleGPU:
- gpu:
nvidia.com/gpu: 1
amd.com/gpu: 0
targetSelector:
workload-name1:
- container-name1
- gpu:
nvidia.com/gpu: 0
amd.com/gpu: 1
targetSelector:
workload-name1:
- container-name2
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
probes: *probes
container-name2:
enabled: true
primary: false
imageSelector: image
probes: *probes
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
equal:
path: spec.template.spec.runtimeClassName
value: nvidia
- documentIndex: *deploymentDoc
isSubset:
path: spec.template.spec.containers[0]
content:
resources:
limits:
cpu: 4000m
memory: 8Gi
nvidia.com/gpu: "1"
requests:
cpu: 10m
memory: 50Mi
- documentIndex: *deploymentDoc
isSubset:
path: spec.template.spec.containers[1]
content:
resources:
limits:
cpu: 4000m
memory: 8Gi
amd.com/gpu: "1"
requests:
cpu: 10m
memory: 50Mi
# Failures
- it: should fail with empty requests
set:
@@ -868,3 +1009,28 @@ tests:
asserts:
- failedTemplate:
errorMessage: Container - Expected non-empty <scaleGPU> <value>
- it: should fail with no value in gpu
set:
image: *image
scaleGPU:
- gpu:
key:
targetSelector:
workload-name1:
- container-name1
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
probes: *probes
asserts:
- failedTemplate:
errorMessage: Container - Expected non-empty <scaleGPU> <value>

View File

@@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 12.4.11
version: 12.4.12

View File

@@ -7,12 +7,15 @@ probes:
liveness:
enabled: true
port: {{ .Values.addons.codeserver.service.ports.codeserver.port }}
path: "/"
readiness:
enabled: true
port: {{ .Values.addons.codeserver.service.ports.codeserver.port }}
path: "/"
startup:
enabled: true
port: {{ .Values.addons.codeserver.service.ports.codeserver.port }}
path: "/"
imageSelector: "codeserverImage"
imagePullPolicy: {{ .Values.codeserverImage.pullPolicy }}
securityContext:

View File

@@ -27,8 +27,8 @@ securityContext:
- NET_RAW
- SYS_MODULE
{{- with $.Values.addons.vpn.env }}
env:
{{- with $.Values.addons.vpn.env }}
{{- . | toYaml | nindent 2 }}
{{- end -}}

View File

@@ -23,10 +23,11 @@ securityContext:
add:
- NET_ADMIN
- NET_RAW
- MKNOD
- SYS_MODULE
{{- with $.Values.addons.vpn.env }}
env:
{{- with $.Values.addons.vpn.env }}
{{- . | toYaml | nindent 2 }}
{{- end }}
{{- if and .Values.addons.vpn.openvpn.username .Values.addons.vpn.openvpn.password }}

View File

@@ -23,10 +23,12 @@ securityContext:
add:
- NET_ADMIN
- NET_RAW
- SETUID
- SETGID
- SYS_MODULE
{{- with $.Values.addons.vpn.env }}
env:
{{- with $.Values.addons.vpn.env }}
{{- . | toYaml | nindent 2 }}
{{- end }}
SEPARATOR: ";"

View File

@@ -75,10 +75,12 @@ objectData: The object data to be used to render the container.
{{- if not $returnBool -}}
{{- range $gpu := $gpuResource -}}
{{- range $k, $v := $gpu -}}
{{- if not $v -}}
{{- if or (kindIs "invalid" $v) (eq (toString $v) "") -}}
{{- fail "Container - Expected non-empty <scaleGPU> <value>" -}}
{{- end }}
{{- end -}} {{/* Don't try to schedule 0 GPUs */}}
{{- if gt (int $v) 0 }}
{{ $k }}: {{ $v | quote }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- else -}}