_rules.tpl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. {{/* Returns Rules for rbac */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.rbac.rules" (dict "rootCtx" $ "objectData" $objectData) }}
  4. rootCtx: The root context of the chart.
  5. objectData: The object data to be used to render the RBAC.
  6. */}}
  7. {{/* Parses service accounts, and checks if RBAC have selected any of them */}}
  8. {{- define "ix.v1.common.lib.rbac.rules" -}}
  9. {{- $rootCtx := .rootCtx -}}
  10. {{- $objectData := .objectData -}}
  11. {{- if not $objectData.rules -}}
  12. {{- fail "RBAC - Expected non-empty <rbac.rules>" -}}
  13. {{- end -}}
  14. {{- range $objectData.rules -}}
  15. {{- if not .apiGroups -}}
  16. {{- fail "RBAC - Expected non-empty <rbac.rules.apiGroups>" -}}
  17. {{- end -}}
  18. {{- if not .resources -}}
  19. {{- fail "RBAC - Expected non-empty <rbac.rules.resources>" -}}
  20. {{- end -}}
  21. {{- if not .verbs -}}
  22. {{- fail "RBAC - Expected non-empty <rbac.rules.verbs>" -}}
  23. {{- end -}}
  24. {{- /* apiGroups */}}
  25. - apiGroups:
  26. {{- range .apiGroups }}
  27. - {{ tpl . $rootCtx | quote }}
  28. {{- end -}}
  29. {{- /* resources */}}
  30. resources:
  31. {{- range .resources -}}
  32. {{- if not . -}}
  33. {{- fail "RBAC - Expected non-empty entry in <rbac.rules.resources>" -}}
  34. {{- end }}
  35. - {{ tpl . $rootCtx | quote }}
  36. {{- end -}}
  37. {{- /* verbs */}}
  38. verbs:
  39. {{- range .verbs -}}
  40. {{- if not . -}}
  41. {{- fail "RBAC - Expected non-empty entry in <rbac.rules.verbs>" -}}
  42. {{- end }}
  43. - {{ tpl . $rootCtx | quote }}
  44. {{- end -}}
  45. {{- end -}}
  46. {{- end -}}