{{- if .Values.enabled.clusterMode }}
{{- $namespace := .Release.Namespace -}}
{{- $applicationName := .Values.appName.clusterMode -}}
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ $applicationName }}
  namespace: {{ $namespace }}
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ $applicationName }}
  namespace: {{ $namespace }}
rules:
  - apiGroups:
      - ""
    resources:
      - endpoints
    verbs:
      - get
      - watch
      - list
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: {{ $applicationName }}
  namespace: {{ $namespace }}
subjects:
  - kind: ServiceAccount
    name: {{ $applicationName }}
    namespace: {{ $namespace }}
roleRef:
  kind: Role
  name: {{ $applicationName }}
  apiGroup: rbac.authorization.k8s.io
---
{{- end }}
