{{- if .Values.webhook.enabled }}
{{- if .Values.webhook.serviceAccount.create }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ include "snapshot-validation-webhook.serviceAccountName" . }}
  labels:
    {{- include "snapshot-validation-webhook.labels" . | nindent 4 }}
{{- end }}
{{- if .Values.webhook.rbac.create }}
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ include "snapshot-validation-webhook.fullname" . }}
rules:
  - apiGroups: ["snapshot.storage.k8s.io"]
    resources: ["volumesnapshotclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["groupsnapshot.storage.k8s.io"]
    resources: ["volumegroupsnapshotclasses"]
    verbs: ["get", "list", "watch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ include "snapshot-validation-webhook.fullname" . }}
subjects:
  - kind: ServiceAccount
    name: {{ include "snapshot-validation-webhook.serviceAccountName" . }}
    namespace: {{ .Release.Namespace }}
roleRef:
  kind: ClusterRole
  name: {{ include "snapshot-validation-webhook.fullname" . }}
  apiGroup: rbac.authorization.k8s.io
{{- end }}
{{- end }}
