{{- if .Values.rbac.enabled -}}
{{- if .Values.rbac.create -}}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: {{ include "freeleaps-data-backup.fullname" . }}-role
  labels:
    app: {{ include "freeleaps-data-backup.name" . }}
    component: backup
    {{- include "freeleaps-data-backup.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
  resources: ["persistentvolumeclaims"]
  verbs: ["get", "list"]
- apiGroups: ["snapshot.storage.k8s.io"]
  resources: ["volumesnapshots", "volumesnapshotclasses"]
  verbs: ["get", "list", "create", "update", "patch", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: {{ include "freeleaps-data-backup.fullname" . }}-rolebinding
  labels:
    app: {{ include "freeleaps-data-backup.name" . }}
    component: backup
    {{- include "freeleaps-data-backup.labels" . | nindent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ include "freeleaps-data-backup.fullname" . }}-role
subjects:
- kind: ServiceAccount
  name: {{ .Values.serviceAccount.name }}
  namespace: {{ .Values.backup.namespace }}
{{- end }}
{{- end }} 