{{- if .Values.controller.enabled }}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ include "hoard.fullname" . }}-controller
  labels:
    app.kubernetes.io/name: {{ include "hoard.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "hoard.chart" . }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: {{ include "hoard.fullname" . }}-controller
  labels:
    app.kubernetes.io/name: {{ include "hoard.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "hoard.chart" . }}
rules:
- apiGroups:
  - monax.io
  resources:
  - sharedsecrets
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - secrets
  verbs:
  - create
  - update
  - delete
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: {{ include "hoard.fullname" . }}-controller
  labels:
    app.kubernetes.io/name: {{ include "hoard.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "hoard.chart" . }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ include "hoard.fullname" . }}-controller
subjects:
- apiGroup: ""
  kind: ServiceAccount
  name: {{ include "hoard.fullname" . }}-controller
  namespace: {{ .Release.Namespace }}
{{- end }}