{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ include "helm-dashboard.serviceAccountName" . }}
  labels:
    {{- include "helm-dashboard.labels" . | nindent 4 }}
  {{- with .Values.serviceAccount.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ include "helm-dashboard.serviceAccountName" . }}
rules:
  - apiGroups: ["*"]
    resources: ["*"]
  {{- if .Values.dashboard.allowWriteActions }}
    verbs: ["get", "list", "watch", "create", "delete", "patch", "update"]
  {{- else }}
    verbs: ["get", "list", "watch"]
  {{- end }}
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: {{ include "helm-dashboard.serviceAccountName" . }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ include "helm-dashboard.serviceAccountName" . }}
subjects:
  - kind: ServiceAccount
    namespace: {{ .Release.Namespace }}
    name: {{ include "helm-dashboard.serviceAccountName" . }}
