{{- if .Values.serviceAccount.create -}}
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ include "vault-operator.fullname" . }}
  labels:
    helm.sh/chart: {{ include "vault-operator.chart" . }}
subjects:
- kind: ServiceAccount
  name: {{ include "vault-operator.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
roleRef:
  kind: ClusterRole
  name: {{ include "vault-operator.fullname" . }}
  apiGroup: rbac.authorization.k8s.io
{{- end }}
{{- if .Values.psp.enabled }}
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: psp:{{ include "vault-operator.fullname" . }}
  labels:
    helm.sh/chart: {{ include "vault-operator.chart" . }}
subjects:
- kind: ServiceAccount
  name: {{ include "vault-operator.serviceAccountName" . }}
roleRef:
  kind: Role
  name: psp:{{ include "vault-operator.fullname" . }}
  apiGroup: rbac.authorization.k8s.io
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: psp:{{ .Values.psp.vaultSA }}
  labels:
    helm.sh/chart: {{ include "vault-operator.chart" . }}
subjects:
- kind: ServiceAccount
  name: {{ .Values.psp.vaultSA }}
roleRef:
  kind: Role
  name: psp:{{ .Values.psp.vaultSA }}
  apiGroup: rbac.authorization.k8s.io
{{- end }}
