apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: kubectl-apply
  labels:
    dagweave.io/catalog-item: kubectl-apply
  annotations:
    dagweave.io/catalog-version: "1.0.6"
    dagweave.io/catalog-category: "Kubernetes"
spec:
  entrypoint: apply
  templates:
    - name: apply
      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 and applies with whatever identity the pod
            is given. On Dagweave Local that is the default service account of the
            hidden cluster's argo namespace, which Argo's quick-start install grants
            create, get and patch on pods and create and get on workflows, and nothing
            anywhere else. Point the step at the argo namespace with a Pod or a Workflow
            in hand and the object really is created, in a cluster you cannot see and
            did not choose, and the step exits 0 as though it had reached yours. Every
            other kind, and every other namespace including this item's own default, is
            refused by RBAC and the step fails. Apply against the cluster you mean.
      inputs:
        parameters:
          # Inline manifest YAML to apply. Used when manifest-path is blank.
          - name: manifest
            default: ""
          # Path to a manifest file to apply instead of the inline manifest.
          - name: manifest-path
            default: ""
          - name: namespace
            default: default
      container:
        # bitnami/kubectl:latest
        image: bitnami/kubectl@sha256:bedd34c910e2a5ce9836813d16444af449d7fe07a29136d59f34e861e8e660c5
        command: [sh, -c]
        # Applies against the cluster using the pod's in-cluster serviceAccount.
        # Prefers manifest-path when set, otherwise pipes the inline manifest.
        args:
          - |
            set -eu
            if [ -n "${MANIFEST_PATH}" ]; then
              kubectl apply -n "${NAMESPACE}" -f "${MANIFEST_PATH}"
            else
              printf '%s' "${MANIFEST}" | kubectl apply -n "${NAMESPACE}" -f -
            fi
        env:
          - name: MANIFEST
            value: "{{inputs.parameters.manifest}}"
          - name: MANIFEST_PATH
            value: "{{inputs.parameters.manifest-path}}"
          - name: NAMESPACE
            value: "{{inputs.parameters.namespace}}"
