_validation.tpl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. {{/* Service Account Primary Validation */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.serviceAccount.primaryValidation" $ -}}
  4. */}}
  5. {{- define "ix.v1.common.lib.serviceAccount.primaryValidation" -}}
  6. {{/* Initialize values */}}
  7. {{- $hasPrimary := false -}}
  8. {{- $hasEnabled := false -}}
  9. {{- range $name, $serviceAccount := .Values.serviceAccount -}}
  10. {{/* If service account is enabled */}}
  11. {{- if $serviceAccount.enabled -}}
  12. {{- $hasEnabled = true -}}
  13. {{/* And service account is primary */}}
  14. {{- if and (hasKey $serviceAccount "primary") ($serviceAccount.primary) -}}
  15. {{/* Fail if there is already a primary service account */}}
  16. {{- if $hasPrimary -}}
  17. {{- fail "Service Account - Only one service account can be primary" -}}
  18. {{- end -}}
  19. {{- $hasPrimary = true -}}
  20. {{- end -}}
  21. {{- end -}}
  22. {{- end -}}
  23. {{/* Require at least one primary service account, if any enabled */}}
  24. {{- if and $hasEnabled (not $hasPrimary) -}}
  25. {{- fail "Service Account - At least one enabled service account must be primary" -}}
  26. {{- end -}}
  27. {{- end -}}