_runtimeClassName.tpl 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. {{/* Returns Runtime Class Name */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.pod.runtimeClassName" (dict "rootCtx" $ "objectData" $objectData) }}
  4. rootCtx: The root context of the chart.
  5. objectData: The object data to be used to render the Pod.
  6. */}}
  7. {{- define "ix.v1.common.lib.pod.runtimeClassName" -}}
  8. {{- $rootCtx := .rootCtx -}}
  9. {{- $objectData := .objectData -}}
  10. {{- $runtime := "" -}}
  11. {{/* Initialize from the "defaults" */}}
  12. {{- with $rootCtx.Values.podOptions.runtimeClassName -}}
  13. {{- $runtime = tpl . $rootCtx -}}
  14. {{- end -}}
  15. {{/* Override from the pod values, if defined */}}
  16. {{- with $objectData.podSpec.runtimeClassName -}}
  17. {{- $runtime = tpl . $rootCtx -}}
  18. {{- end -}}
  19. {{- if hasKey $rootCtx.Values.global "ixChartContext" -}}
  20. {{- if $rootCtx.Values.global.ixChartContext.addNvidiaRuntimeClass -}}
  21. {{- range $rootCtx.Values.scaleGPU -}}
  22. {{- if .gpu -}} {{/* Make sure it has a value... */}}
  23. {{- $gpuAssigned := false -}}
  24. {{- range $k, $v := .gpu -}}
  25. {{- if $v -}} {{/* Consider assigned only if value is not "0" or "" */}}
  26. {{- $gpuAssigned = true -}}
  27. {{- end -}}
  28. {{- end -}}
  29. {{- if $gpuAssigned -}} {{/* If GPU is actually assigned */}}
  30. {{- if (kindIs "map" .targetSelector) -}}
  31. {{- range $podName, $containers := .targetSelector -}}
  32. {{- if eq $objectData.shortName $podName -}} {{/* If the pod is selected */}}
  33. {{- $runtime = $rootCtx.Values.global.ixChartContext.nvidiaRuntimeClassName -}}
  34. {{- end -}}
  35. {{- end -}}
  36. {{- else if $objectData.primary -}}
  37. {{/* If the pod is primary and no targetSelector is given, assign to primary */}}
  38. {{- $runtime = $rootCtx.Values.global.ixChartContext.nvidiaRuntimeClassName -}}
  39. {{- end -}}
  40. {{- end -}}
  41. {{- end -}}
  42. {{- end -}}
  43. {{- end -}}
  44. {{- end -}}
  45. {{- $runtime -}}
  46. {{- end -}}