{{- if .Values.rbac.create -}}
# Helm 3.1 supports a lookup template tag to create a secret if it does not exist
# but we can't yet restrict to helm 3.1, hence manually doing this with an initContainer.
# in the post upgrade job.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: {{ template "kubeapps.apprepository-job-postupgrade.fullname" . }}
  labels:{{ include "kubeapps.extraAppLabels" . | nindent 4 }}
    app: {{ template "kubeapps.apprepository.fullname" . }}
rules:
  - apiGroups:
      - ""
    resources:
      - secrets
    verbs:
      - get
      - create
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ template "kubeapps.apprepository-job-postupgrade.fullname" . }}
  labels:{{ include "kubeapps.extraAppLabels" . | nindent 4 }}
    app: {{ template "kubeapps.apprepository.fullname" . }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ template "kubeapps.apprepository-job-postupgrade.fullname" . }}
subjects:
  - kind: ServiceAccount
    name: {{ template "kubeapps.apprepository-job-postupgrade.fullname" . }}
    namespace: {{ .Release.Namespace }}
{{- end -}}
