{{ if .Values.rbac.install }}
{{- $serviceName := include "jenkins.fullname" . -}}
apiVersion: rbac.authorization.k8s.io/{{ required "A valid .Values.rbac.apiVersion entry required!" .Values.rbac.apiVersion }}
kind: {{ .Values.rbac.roleBindingKind }}
metadata:
  name: {{ $serviceName }}-role-binding
  labels:
    app: {{ $serviceName }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ .Values.rbac.roleRef }}
subjects:
- kind: ServiceAccount
  name: {{ $serviceName }}
  namespace: {{ .Release.Namespace }}
{{ end }}