{{- if and (not .Values.config.server.encryptionKeySecretRef) .Values.config.server.autoGenerateEncryptionKey }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ include "marmot.fullname" . }}-encryption-key-manager
  labels:
    {{- include "marmot.labels" . | nindent 4 }}
    app.kubernetes.io/component: encryption-key-manager
  annotations:
    "helm.sh/hook": pre-install,pre-upgrade
    "helm.sh/hook-weight": "-10"
    "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ include "marmot.fullname" . }}-encryption-key-manager
subjects:
- kind: ServiceAccount
  name: {{ include "marmot.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
{{- end }}
{{- if .Values.operator.enabled }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ include "marmot.fullname" . }}-run-watcher
  labels:
    {{- include "marmot.labels" . | nindent 4 }}
    app.kubernetes.io/component: run-watcher
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ include "marmot.fullname" . }}-run-watcher
subjects:
- kind: ServiceAccount
  name: {{ include "marmot.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
{{- end }}
