apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: kubectl-rollout-restart
  labels:
    dagweave.io/catalog-item: kubectl-rollout-restart
  annotations:
    dagweave.io/catalog-version: "1.0.0"
    dagweave.io/catalog-category: "Kubernetes"
spec:
  entrypoint: restart
  templates:
    - name: restart
      metadata:
        annotations:
          dagweave.io/local-support: unsupported
          dagweave.io/local-support-reason: >-
            This step runs kubectl 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. The restart patches
            a workload in the apps group, which that account cannot touch, so the step fails
            on a 403 rather than touching anything. The cluster you meant is one this run
            cannot reach.
      inputs:
        parameters:
          - name: kind
            default: "deployment"
          - name: name
          - name: namespace
            default: "default"
          - name: wait
            default: "true"
          - name: timeout
            default: "300s"
      retryStrategy:
        limit: "2"
        retryPolicy: OnError
        backoff:
          duration: 10s
          factor: "2"
          maxDuration: 2m
      container:
        # cgr.dev/chainguard/kubectl:latest-dev
        image: cgr.dev/chainguard/kubectl@sha256:98f9c337808ecf5d5e80b79af4345762a3d8c803ebf8c857d2dddabf885107ba
        command: [sh, -c]
        args:
          - |
            set -eu
            kubectl rollout restart "${KIND}/${NAME}" -n "${NAMESPACE}"
            if [ "${WAIT}" = "true" ]; then
              kubectl rollout status "${KIND}/${NAME}" -n "${NAMESPACE}" --timeout="${TIMEOUT}"
            fi
        env:
          - name: KIND
            value: "{{inputs.parameters.kind}}"
          - name: NAME
            value: "{{inputs.parameters.name}}"
          - name: NAMESPACE
            value: "{{inputs.parameters.namespace}}"
          - name: WAIT
            value: "{{inputs.parameters.wait}}"
          - name: TIMEOUT
            value: "{{inputs.parameters.timeout}}"
        resources:
          requests:
            cpu: 50m
            memory: 64Mi
          limits:
            memory: 256Mi
