{{- if .Values.serviceAccount.create -}}
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ include "vault-operator.fullname" . }}
  labels:
    helm.sh/chart: {{ include "vault-operator.chart" . }}
rules:
- apiGroups:
  - vault.banzaicloud.com
  resources:
  - "*"
  verbs:
  - "*"
- apiGroups:
  - ""
  resources:
  - events
  - pods
  - services
  - configmaps
  - secrets
  verbs:
  - "*"
- apiGroups:
  - ""
  resources:
  - namespaces
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - apps
  - extensions
  resources:
  - replicasets
  verbs:
  - get
- apiGroups:
  - apps
  - extensions
  resources:
  - deployments
  - deployments/finalizers
  - statefulsets
  verbs:
  - "*"
- apiGroups:
  - apiextensions.k8s.io
  resources:
  - customresourcedefinitions
  verbs:
  - get
{{- if .Capabilities.APIVersions.Has "route.openshift.io/v1/Route" }}
- apiGroups:
  - route.openshift.io
  resources:
  - routes
  - routes/custom-host
  verbs:
  - list
  - get
  - create
  - update
  - watch
{{- end }}
- apiGroups:
  - extensions
  - networking.k8s.io
  resources:
  - ingresses
  verbs:
  - list
  - get
  - create
  - update
  - watch
- apiGroups:
  - monitoring.coreos.com
  resources:
  - servicemonitors
  verbs:
  - update
  - list
  - get
  - create
  - watch
- apiGroups:
  - coordination.k8s.io
  resources:
  - leases
  verbs:
  - "*"
{{- end }}
{{- if .Values.psp.enabled }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: psp:{{ include "vault-operator.fullname" . }}
rules:
- apiGroups:
  - policy
  resourceNames:
  - {{ include "vault-operator.fullname" . }}
  resources:
  - podsecuritypolicies
  verbs:
  - use
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: psp:{{ .Values.psp.vaultSA }}
rules:
- apiGroups:
  - policy
  resourceNames:
  - {{ .Values.psp.vaultSA }}
  resources:
  - podsecuritypolicies
  verbs:
  - use
{{- end }}
