{{- if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1beta1
{{- if .Values.rbac.clusterWide }}
kind: ClusterRoleBinding
{{- else }}
kind: RoleBinding
{{- end }}
metadata:
  name: {{ template "telegraf.fullname" . }}
subjects:
  - kind: ServiceAccount
    name: {{ template "telegraf.fullname" . }}
    namespace: {{ .Release.Namespace }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  {{- if .Values.rbac.clusterWide }}
  kind: ClusterRole
  {{- else }}
  kind: Role
  {{- end }}
  name: {{ template "telegraf.fullname" . }}
{{- end }}