{{- if .Values.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
  labels:
    app: {{ template "haproxy-ingress.name" . }}
    chart: {{ template "haproxy-ingress.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  name: {{ template "haproxy-ingress.fullname" . }}
  namespace: {{ .Release.Namespace }}
rules:
  - apiGroups:
      - ""
    resources:
      - pods
      - secrets
      - namespaces
    verbs:
      - get
  - apiGroups:
      - ""
    resources:
      - configmaps
      - endpoints
    verbs:
      - get
      - create
      - update
{{- if .Values.rbac.security.enable }}
  - apiGroups:
      - extensions
    resources:
      - podsecuritypolicies
    resourceNames:
      - {{ template "haproxy-ingress.fullname" . }}
    verbs:
      - use
{{- end -}}
{{- end -}}
