_tolerations.tpl 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. {{/* Returns Tolerations */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.pod.tolerations" (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.tolerations" -}}
  8. {{- $rootCtx := .rootCtx -}}
  9. {{- $objectData := .objectData -}}
  10. {{- $tolerations := list -}}
  11. {{/* Initialize from the "global" option */}}
  12. {{- with $rootCtx.Values.podOptions.tolerations -}}
  13. {{- $tolerations = . -}}
  14. {{- end -}}
  15. {{/* Override from the "pod" option */}}
  16. {{- with $objectData.podSpec.tolerations -}}
  17. {{- $tolerations = . -}}
  18. {{- end -}}
  19. {{- range $tolerations -}}
  20. {{/* Expand values */}}
  21. {{- $operator := (tpl (.operator | default "") $rootCtx) -}}
  22. {{- $key := (tpl (.key | default "") $rootCtx) -}}
  23. {{- $value := (tpl (.value | default "") $rootCtx) -}}
  24. {{- $effect := (tpl (.effect | default "") $rootCtx) -}}
  25. {{- $tolSeconds := .tolerationSeconds -}}
  26. {{- $operators := (list "Exists" "Equal") -}}
  27. {{- if not (mustHas $operator $operators) -}}
  28. {{- fail (printf "Expected <tolerations.operator> to be one of [%s] but got [%s]" (join ", " $operators) $operator) -}}
  29. {{- end -}}
  30. {{- if and (eq $operator "Equal") (or (not $key) (not $value)) -}}
  31. {{- fail "Expected non-empty <tolerations.key> and <tolerations.value> with <tolerations.operator> set to [Equal]" -}}
  32. {{- end -}}
  33. {{- if and (eq $operator "Exists") $value -}}
  34. {{- fail (printf "Expected empty <tolerations.value> with <tolerations.operator> set to [Exists], but got [%s]" $value) -}}
  35. {{- end -}}
  36. {{- $effects := (list "NoExecute" "NoSchedule" "PreferNoSchedule") -}}
  37. {{- if and $effect (not (mustHas $effect $effects)) -}}
  38. {{- fail (printf "Expected <tolerations.effect> to be one of [%s], but got [%s]" (join ", " $effects) $effect) -}}
  39. {{- end -}}
  40. {{- if and (not (kindIs "invalid" $tolSeconds)) (not (mustHas (kindOf $tolSeconds) (list "int" "float64"))) -}}
  41. {{- fail (printf "Expected <tolerations.tolerationSeconds> to be a number, but got [%s]" $tolSeconds) -}}
  42. {{- end }}
  43. - operator: {{ $operator }}
  44. {{- with $key }}
  45. key: {{ $key }}
  46. {{- end -}}
  47. {{- with $effect }}
  48. effect: {{ $effect }}
  49. {{- end -}}
  50. {{- with $value }}
  51. value: {{ . }}
  52. {{- end -}}
  53. {{- if (mustHas (kindOf $tolSeconds) (list "int" "float64")) }}
  54. tolerationSeconds: {{ $tolSeconds }}
  55. {{- end -}}
  56. {{- end -}}
  57. {{- end -}}