_restartPolicy.tpl 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. {{/* Returns Restart Policy */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.pod.restartPolicy" (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.restartPolicy" -}}
  8. {{- $rootCtx := .rootCtx -}}
  9. {{- $objectData := .objectData -}}
  10. {{- $policy := "Always" -}}
  11. {{/* Initialize from the "defaults" */}}
  12. {{- with $rootCtx.Values.podOptions.restartPolicy -}}
  13. {{- $policy = tpl . $rootCtx -}}
  14. {{- end -}}
  15. {{/* Override from the pod values, if defined */}}
  16. {{- with $objectData.podSpec.restartPolicy -}}
  17. {{- $policy = tpl . $rootCtx -}}
  18. {{- end -}}
  19. {{- $policies := (list "Never" "Always" "OnFailure") -}}
  20. {{- if not (mustHas $policy $policies) -}}
  21. {{- fail (printf "Expected <restartPolicy to be one of [%s] but got [%s]" (join ", " $policies) $policy) -}}
  22. {{- end -}}
  23. {{- $types := (list "Deployment") -}}
  24. {{- if and (ne "Always" $policy) (mustHas $objectData.type $types) -}}
  25. {{- fail (printf "Expected <restartPolicy to be [Always] for [%s] but got [%s]" $objectData.type $policy) -}}
  26. {{- end -}}
  27. {{- $types := (list "Job" "CronJob") -}}
  28. {{- if and (eq "Always" $policy) (mustHas $objectData.type $types) -}}
  29. {{- fail (printf "Expected <restartPolicy to be [OnFailure, Never] for [%s] but got [%s]" $objectData.type $policy) -}}
  30. {{- end -}}
  31. {{- $policy -}}
  32. {{- end -}}