{{- if .Values.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: {{ template "kubeapps.db-secret-jobs-cleanup.fullname" . }}
  annotations:
    helm.sh/hook: post-delete
    helm.sh/hook-delete-policy: hook-succeeded
    helm.sh/hook-weight: "-10"
  labels:{{ include "kubeapps.extraAppLabels" . | nindent 4 }}
    app: {{ template "kubeapps.db-secret-jobs-cleanup.fullname" . }}
rules:
  - apiGroups:
      - ""
    resources:
      - secrets
    verbs:
      - delete
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ template "kubeapps.db-secret-jobs-cleanup.fullname" . }}
  annotations:
    helm.sh/hook: post-delete
    helm.sh/hook-delete-policy: hook-succeeded
    helm.sh/hook-weight: "-10"
  labels:{{ include "kubeapps.extraAppLabels" . | nindent 4 }}
    app: {{ template "kubeapps.db-secret-jobs-cleanup.fullname" . }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: {{ template "kubeapps.db-secret-jobs-cleanup.fullname" . }}
subjects:
  - kind: ServiceAccount
    name: {{ template "kubeapps.db-secret-jobs-cleanup.fullname" . }}
    namespace: {{ .Release.Namespace }}
{{- end -}}
