_rules.tpl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. {{- /* resourceNames */}}
  38. {{- if .resourceNames }}
  39. resourceNames:
  40. {{- range .resourceNames -}}
  41. {{- if not . -}}
  42. {{- fail "RBAC - Expected non-empty entry in <rbac.rules.resourceNames>" -}}
  43. {{- end }}
  44. - {{ tpl . $rootCtx | quote }}
  45. {{- end -}}
  46. {{- end -}}
  47. {{- /* verbs */}}
  48. verbs:
  49. {{- range .verbs -}}
  50. {{- if not . -}}
  51. {{- fail "RBAC - Expected non-empty entry in <rbac.rules.verbs>" -}}
  52. {{- end }}
  53. - {{ tpl . $rootCtx | quote }}
  54. {{- end -}}
  55. {{- end -}}
  56. {{- end -}}