_primaryValidation.tpl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. {{/* Containers Basic Validation */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.container.primaryValidation" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
  4. */}}
  5. {{- define "ix.v1.common.lib.container.primaryValidation" -}}
  6. {{- $objectData := .objectData -}}
  7. {{- $rootCtx := .rootCtx -}}
  8. {{/* Initialize values */}}
  9. {{- $hasPrimary := false -}}
  10. {{- $hasEnabled := false -}}
  11. {{/* Go over the contaienrs */}}
  12. {{- range $name, $container := $objectData.podSpec.containers -}}
  13. {{/* If container is enabled */}}
  14. {{- if $container.enabled -}}
  15. {{- $hasEnabled = true -}}
  16. {{/* And container is primary */}}
  17. {{- if and (hasKey $container "primary") ($container.primary) -}}
  18. {{/* Fail if there is already a primary container */}}
  19. {{- if $hasPrimary -}}
  20. {{- fail "Container - Only one container can be primary per workload" -}}
  21. {{- end -}}
  22. {{- $hasPrimary = true -}}
  23. {{- end -}}
  24. {{- end -}}
  25. {{- end -}}
  26. {{/* Require at least one primary container, if any enabled */}}
  27. {{- if and $hasEnabled (not $hasPrimary) -}}
  28. {{- fail "Container - At least one enabled container must be primary per workload" -}}
  29. {{- end -}}
  30. {{- end -}}