_rbac.tpl 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. {{/* RBAC Class */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.class.rbac" (dict "rootCtx" $ "objectData" $objectData) }}
  4. rootCtx: The root context of the chart.
  5. objectData:
  6. name: The name of the rbac.
  7. labels: The labels of the rbac.
  8. annotations: The annotations of the rbac.
  9. clusterWide: Whether the rbac is cluster wide or not.
  10. rules: The rules of the rbac.
  11. subjects: The subjects of the rbac.
  12. */}}
  13. {{- define "ix.v1.common.class.rbac" -}}
  14. {{- $rootCtx := .rootCtx -}}
  15. {{- $objectData := .objectData }}
  16. ---
  17. apiVersion: rbac.authorization.k8s.io/v1
  18. kind: {{ ternary "ClusterRole" "Role" $objectData.clusterWide }}
  19. metadata:
  20. name: {{ $objectData.name }}
  21. {{- if not $objectData.clusterWide }}
  22. namespace: {{ $rootCtx.Release.Namespace }}
  23. {{- end }}
  24. {{- $labels := (mustMerge ($objectData.labels | default dict) (include "ix.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}}
  25. {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }}
  26. labels:
  27. {{- . | nindent 4 }}
  28. {{- end -}}
  29. {{- $annotations := (mustMerge ($objectData.annotations | default dict) (include "ix.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}}
  30. {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }}
  31. annotations:
  32. {{- . | nindent 4 }}
  33. {{- end }}
  34. rules:
  35. {{- include "ix.v1.common.lib.rbac.rules" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }}
  36. ---
  37. apiVersion: rbac.authorization.k8s.io/v1
  38. kind: {{ ternary "ClusterRoleBinding" "RoleBinding" $objectData.clusterWide }}
  39. metadata:
  40. name: {{ $objectData.name }}
  41. {{- if not $objectData.clusterWide }}
  42. namespace: {{ $rootCtx.Release.Namespace }}
  43. {{- end }}
  44. {{- $labels := (mustMerge ($objectData.labels | default dict) (include "ix.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}}
  45. {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }}
  46. labels:
  47. {{- . | nindent 4 }}
  48. {{- end -}}
  49. {{- $annotations := (mustMerge ($objectData.annotations | default dict) (include "ix.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}}
  50. {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }}
  51. annotations:
  52. {{- . | nindent 4 }}
  53. {{- end }}
  54. roleRef:
  55. apiGroup: rbac.authorization.k8s.io
  56. kind: {{ ternary "ClusterRole" "Role" $objectData.clusterWide }}
  57. name: {{ $objectData.name }}
  58. subjects:
  59. {{- include "ix.v1.common.lib.rbac.serviceAccount" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }}
  60. {{- include "ix.v1.common.lib.rbac.subjects" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }}
  61. {{- end -}}