mirror of
https://github.com/truenas/charts.git
synced 2026-06-17 15:38:49 +08:00
add runtimeclassname
This commit is contained in:
191
library/common-test/tests/pod/runtime_class_name_test.yaml
Normal file
191
library/common-test/tests/pod/runtime_class_name_test.yaml
Normal file
@@ -0,0 +1,191 @@
|
||||
suite: pod runtime class name test
|
||||
templates:
|
||||
- common.yaml
|
||||
tests:
|
||||
- it: should pass with empty runtimeClassName
|
||||
set:
|
||||
podOptions:
|
||||
runtimeClassName: ""
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
asserts:
|
||||
- documentIndex: &deploymentDoc 0
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *deploymentDoc
|
||||
isNull:
|
||||
path: spec.template.spec.runtimeClassName
|
||||
|
||||
- it: should pass with runtimeClassName from "global"
|
||||
set:
|
||||
podOptions:
|
||||
runtimeClassName: some-runtime-class
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
asserts:
|
||||
- documentIndex: *deploymentDoc
|
||||
equal:
|
||||
path: spec.template.spec.runtimeClassName
|
||||
value: some-runtime-class
|
||||
|
||||
- it: should pass with runtimeClassName from "pod"
|
||||
set:
|
||||
podOptions:
|
||||
runtimeClassName: some-runtime-class
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
runtimeClassName: some-other-runtime-class
|
||||
asserts:
|
||||
- documentIndex: *deploymentDoc
|
||||
equal:
|
||||
path: spec.template.spec.runtimeClassName
|
||||
value: some-other-runtime-class
|
||||
|
||||
- it: should pass with runtimeClassName from "pod" with tpl
|
||||
set:
|
||||
runtimeClass: some-other-runtime-class
|
||||
podOptions:
|
||||
runtimeClassName: some-runtime-class
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
runtimeClassName: "{{ .Values.runtimeClass }}"
|
||||
asserts:
|
||||
- documentIndex: *deploymentDoc
|
||||
equal:
|
||||
path: spec.template.spec.runtimeClassName
|
||||
value: some-other-runtime-class
|
||||
|
||||
- it: should pass with runtimeClassName from ixChartContext with targetSelector
|
||||
set:
|
||||
scaleGPU:
|
||||
- gpu:
|
||||
key: value
|
||||
targetSelector:
|
||||
controller-name1:
|
||||
- container-name1
|
||||
controller-name3:
|
||||
- container-name1
|
||||
global:
|
||||
ixChartContext:
|
||||
addNvidiaRuntimeClass: true
|
||||
nvidiaRuntimeClassName: ix-runtime
|
||||
podOptions:
|
||||
runtimeClassName: some-class
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
runtimeClassName: some-other-class
|
||||
controller-name2:
|
||||
enabled: true
|
||||
primary: false
|
||||
type: DaemonSet
|
||||
podSpec:
|
||||
runtimeClassName: some-class
|
||||
controller-name3:
|
||||
enabled: true
|
||||
primary: false
|
||||
type: StatefulSet
|
||||
podSpec:
|
||||
runtimeClassName: some-class
|
||||
asserts:
|
||||
- documentIndex: *deploymentDoc
|
||||
equal:
|
||||
path: spec.template.spec.runtimeClassName
|
||||
value: ix-runtime
|
||||
- documentIndex: &daemonSetDoc 1
|
||||
isKind:
|
||||
of: DaemonSet
|
||||
- documentIndex: *daemonSetDoc
|
||||
equal:
|
||||
path: spec.template.spec.runtimeClassName
|
||||
value: some-class
|
||||
- documentIndex: &statefulSetDoc 2
|
||||
isKind:
|
||||
of: StatefulSet
|
||||
- documentIndex: *statefulSetDoc
|
||||
equal:
|
||||
path: spec.template.spec.runtimeClassName
|
||||
value: ix-runtime
|
||||
|
||||
- it: should pass with runtimeClassName from ixChartContext without targetSelector (on primary controller)
|
||||
set:
|
||||
scaleGPU:
|
||||
- gpu:
|
||||
key: value
|
||||
global:
|
||||
ixChartContext:
|
||||
addNvidiaRuntimeClass: true
|
||||
nvidiaRuntimeClassName: ix-runtime
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Job
|
||||
podSpec:
|
||||
runtimeClassName: some-other-class
|
||||
controller-name2:
|
||||
enabled: true
|
||||
primary: false
|
||||
type: CronJob
|
||||
schedule: "* * * * *"
|
||||
podSpec: {}
|
||||
asserts:
|
||||
- documentIndex: &jobDoc 0
|
||||
isKind:
|
||||
of: Job
|
||||
- documentIndex: *jobDoc
|
||||
equal:
|
||||
path: spec.template.spec.runtimeClassName
|
||||
value: ix-runtime
|
||||
- documentIndex: &cronJobDoc 1
|
||||
isKind:
|
||||
of: CronJob
|
||||
- documentIndex: *cronJobDoc
|
||||
isNull:
|
||||
path: spec.jobTemplate.spec.template.spec.runtimeClassName
|
||||
|
||||
- it: should pass with runtimeClassName not set from ixChartContext without gpu value
|
||||
set:
|
||||
scaleGPU:
|
||||
- gpu: {}
|
||||
targetSelector:
|
||||
controller-name1:
|
||||
- container-name1
|
||||
global:
|
||||
ixChartContext:
|
||||
addNvidiaRuntimeClass: true
|
||||
nvidiaRuntimeClassName: ix-runtime
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Job
|
||||
podSpec:
|
||||
runtimeClassName: some-other-class
|
||||
asserts:
|
||||
- documentIndex: *jobDoc
|
||||
isKind:
|
||||
of: Job
|
||||
- documentIndex: *jobDoc
|
||||
equal:
|
||||
path: spec.template.spec.runtimeClassName
|
||||
value: some-other-class
|
||||
@@ -42,12 +42,16 @@
|
||||
| controllers.[controller-name].podSpec.tolerations.value | `string` | ❌/✅ | ✅ | | Toleration's `value`. Required only when `operator` = `Equal` |
|
||||
| controllers.[controller-name].podSpec.tolerations.effect | `string` | ❌ | ✅ | | Toleration's `effect`.(NoExecute, NoSchedule, PreferNoSchedule) |
|
||||
| controllers.[controller-name].podSpec.tolerations.tolerationSeconds | `int` | ❌ | ❌ | | Toleration's `tolerationSeconds`. |
|
||||
| controllers.[controller-name].podSpec.runtimeClassName | `string` | ✅ | ❌ | `{{ .Values.podOptions.runtimeClassName }}` ("") | Pod's runtimeClassName |
|
||||
|
||||
---
|
||||
|
||||
Notes
|
||||
|
||||
> `dnsPolicy` is set automatically to `ClusterFirstWithHostNet` when `hostNetwork` is `true`
|
||||
> `runtimeClassName` will ignore any value set and use the `.Values.global.ixChartContext.nvidiaRuntimeClassName`,
|
||||
> if a GPU is assigned to a container and Scale Middleware sets `.Values.global.ixChartContext.addNvidiaRuntimeClass` to `true`.
|
||||
> Note that it will only set the `runtimeClassName` on the pod that this container belongs to.
|
||||
|
||||
---
|
||||
|
||||
@@ -125,4 +129,5 @@ controllers:
|
||||
- operator: Exists
|
||||
effect: NoExecute
|
||||
tolerationSeconds: 3600
|
||||
runtimeClassName: some-runtime-class
|
||||
```
|
||||
|
||||
48
library/common/1.0.0/templates/lib/pod/_runtimeClassName.tpl
Normal file
48
library/common/1.0.0/templates/lib/pod/_runtimeClassName.tpl
Normal file
@@ -0,0 +1,48 @@
|
||||
{{/* Returns Runtime Class Name */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.lib.pod.runtimeClassName" (dict "rootCtx" $ "objectData" $objectData) }}
|
||||
rootCtx: The root context of the template. It is used to access the global context.
|
||||
objectData: The object data to be used to render the Pod.
|
||||
*/}}
|
||||
{{- define "ix.v1.common.lib.pod.runtimeClassName" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $runtime := "" -}}
|
||||
|
||||
{{/* Initialize from the "defaults" */}}
|
||||
{{- with $rootCtx.Values.podOptions.runtimeClassName -}}
|
||||
{{- $runtime = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override from the pod values, if defined */}}
|
||||
{{- with $objectData.podSpec.runtimeClassName -}}
|
||||
{{- $runtime = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if hasKey $rootCtx.Values.global "ixChartContext" -}}
|
||||
{{- if $rootCtx.Values.global.ixChartContext.addNvidiaRuntimeClass -}}
|
||||
|
||||
{{- range $rootCtx.Values.scaleGPU -}}
|
||||
{{- if .gpu -}} {{/* Make sure it has a value... */}}
|
||||
|
||||
{{- if (kindIs "map" .targetSelector) -}}
|
||||
{{- range $podName, $containers := .targetSelector -}}
|
||||
{{- if eq $objectData.shortName $podName -}} {{/* If the pod is selected */}}
|
||||
{{- $runtime = $rootCtx.Values.global.ixChartContext.nvidiaRuntimeClassName -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- else if $objectData.primary -}}
|
||||
|
||||
{{/* If the pod is primary and no targetSelector is given, assign to primary */}}
|
||||
{{- $runtime = $rootCtx.Values.global.ixChartContext.nvidiaRuntimeClassName -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $runtime -}}
|
||||
{{- end -}}
|
||||
Reference in New Issue
Block a user