# This job is meant primarily for cleaning up on CI systems.
# Using this on production systems, especially those that have multiple releases of Contour, will be destructive.
{{- if .Values.customResourceDefinitions.cleanup }}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ template "contour.fullname" . }}-cleanup
  namespace: {{ .Release.Namespace }}
  annotations:
    "helm.sh/hook": pre-delete
    "helm.sh/hook-weight": "3"
    "helm.sh/hook-delete-policy": hook-succeeded
  labels:
    app.kubernetes.io/name: {{ include "contour.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "contour.chart" . }}
spec:
  template:
    metadata:
      name: contour-cleanup
    spec:
      serviceAccountName: {{ include "contour.fullname" . }}
      containers:
        - name: kubectl
          image: docker.io/bitnami/kubectl:1.14.1
          imagePullPolicy: IfNotPresent
          command:
            - /bin/sh
            - -c
            - >
              kubectl delete httpproxy --all;
              kubectl delete ingressroutes --all;
              kubectl delete tlscertificatedelegation --all;
              kubectl delete crd -l app.kubernetes.io/name=contour
      restartPolicy: OnFailure
{{- end }}
