{{- if .Values.rbac.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ include "gemini.fullname" . }}-controller
  labels:
    {{- include "gemini.labels" . | nindent 4 }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: {{ include "gemini.fullname" . }}-controller
  labels:
    {{- include "gemini.labels" . | nindent 4 }}
rules:
  - apiGroups:
      - gemini.fairwinds.com
    resources:
      - snapshotgroups
    verbs:
      - get
      - list
      - watch
      - create
      - update
      - delete
  - apiGroups:
      - snapshot.storage.k8s.io
      - ''
    resources:
      - volumesnapshots
      - persistentvolumeclaims
    verbs:
      - get
      - list
      - create
      - update
      - delete
  - apiGroups:
      - apiextensions.k8s.io
    resources:
      - customresourcedefinitions
    verbs:
      - get
      - create
      - delete
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: {{ include "gemini.fullname" . }}-controller
  labels:
    {{- include "gemini.labels" . | nindent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ include "gemini.fullname" . }}-controller
subjects:
  - kind: ServiceAccount
    name: {{ include "gemini.fullname" . }}-controller
    namespace: {{ .Release.Namespace }}
{{- end }}
