{{ if .Values.tekton.pruner.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: tekton-resource-pruner
  labels:
    {{- include "edp-tekton.labels" . | nindent 4 }}
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tekton-resource-pruner
  labels:
    {{- include "edp-tekton.labels" . | nindent 4 }}
rules:
  - apiGroups:
      - tekton.dev
    verbs:
      - get
      - list
      - delete
    resources:
      - pipelineruns
  - apiGroups:
      - ''
    verbs:
      - get
    resources:
      - ConfigMap
    resourceNames:
      - tekton-resource-pruner-scripts
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: tekton-resource-pruner
  labels:
    {{- include "edp-tekton.labels" . | nindent 4 }}
subjects:
  - kind: ServiceAccount
    name: tekton-resource-pruner
    namespace: {{ .Release.Namespace }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: tekton-resource-pruner
{{ end }}
