{{- if .Values.rbac.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ include "iperf3-monitor.serviceAccountName" . }}
  labels:
    {{- include "iperf3-monitor.labels" . | nindent 4 }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: {{ include "iperf3-monitor.fullname" . }}-role
  labels:
    {{- include "iperf3-monitor.labels" . | nindent 4 }}
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: {{ include "iperf3-monitor.fullname" . }}-rb
  labels:
    {{- include "iperf3-monitor.labels" . | nindent 4 }}
subjects:
  - kind: ServiceAccount
    name: {{ include "iperf3-monitor.serviceAccountName" . }}
    namespace: {{ .Release.Namespace }}
roleRef:
  kind: ClusterRole
  name: {{ include "iperf3-monitor.fullname" . }}-role
  apiGroup: rbac.authorization.k8s.io
{{- end -}}