{{- if .Values.podSecurityPolicies.enabled }}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
  name: {{ template "elasticsearch-exporter.fullname" . }}
  labels:
    chart: {{ template "elasticsearch-exporter.chart" . }}
    app: {{ template "elasticsearch-exporter.name" . }}
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ template "elasticsearch-exporter.fullname" . }}
subjects:
- kind: ServiceAccount
  {{- if .Values.serviceAccount.create  }}
  name: {{ template "elasticsearch-exporter.fullname" . }}
  {{- else }}
  name: {{ .Values.serviceAccount.name }}
  {{- end }}
  namespace: {{ .Release.Namespace }}
{{- end }}
