apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: kubectl-delete
  labels:
    dagweave.io/catalog-item: kubectl-delete
  annotations:
    dagweave.io/catalog-version: "1.0.6"
    dagweave.io/catalog-category: "Kubernetes"
spec:
  entrypoint: delete
  templates:
    - name: delete
      metadata:
        annotations:
          # Dagweave Local reads these off the body, the only part of an item that lands in a user's file.
          dagweave.io/local-support: unsupported
          dagweave.io/local-support-reason: >-
            This step shells out to kubectl delete with whatever identity the pod is
            given. On Dagweave Local that is the default service account of the hidden
            cluster's argo namespace, which holds no delete permission on anything at
            all. kubectl sends the delete without reading the object first, so what
            comes back is a refusal rather than a missing object, and --ignore-not-found
            does not cover a refusal. The step fails, which is at least honest: what you
            told it to delete is on a cluster this run cannot reach, and it is still
            there.
      inputs:
        parameters:
          # Resource kind, e.g. deployment, service, configmap.
          - name: kind
          - name: name
          - name: namespace
            default: default
      container:
        # bitnami/kubectl:latest
        image: bitnami/kubectl@sha256:bedd34c910e2a5ce9836813d16444af449d7fe07a29136d59f34e861e8e660c5
        command: [sh, -c]
        # Deletes a single named resource using the in-cluster serviceAccount.
        # --ignore-not-found makes the step idempotent.
        args:
          - |
            set -eu
            kubectl delete "${KIND}" "${NAME}" -n "${NAMESPACE}" --ignore-not-found
        env:
          - name: KIND
            value: "{{inputs.parameters.kind}}"
          - name: NAME
            value: "{{inputs.parameters.name}}"
          - name: NAMESPACE
            value: "{{inputs.parameters.namespace}}"
