apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: scale-deployment
  labels:
    dagweave.io/catalog-item: scale-deployment
  annotations:
    dagweave.io/catalog-version: "1.0.6"
    dagweave.io/catalog-category: "Kubernetes"
spec:
  entrypoint: scale
  templates:
    - name: scale
      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 scale with whatever identity the pod is
            given. On Dagweave Local that is the default service account of the hidden
            cluster's argo namespace, whose permissions cover pods, workflows and Argo's
            own task objects, and nothing in the apps group. There is no Deployment it
            can read or patch, so the step fails on a 403 rather than scaling anything
            by accident. The Deployment you meant is on a cluster this run cannot reach.
      inputs:
        parameters:
          - name: name
          - name: namespace
            default: default
          - name: replicas
            default: "1"
      container:
        # bitnami/kubectl:latest
        image: bitnami/kubectl@sha256:bedd34c910e2a5ce9836813d16444af449d7fe07a29136d59f34e861e8e660c5
        command: [sh, -c]
        # Scales a Deployment to N replicas using the in-cluster serviceAccount.
        args:
          - |
            set -eu
            kubectl scale deployment "${NAME}" -n "${NAMESPACE}" --replicas="${REPLICAS}"
        env:
          - name: NAME
            value: "{{inputs.parameters.name}}"
          - name: NAMESPACE
            value: "{{inputs.parameters.namespace}}"
          - name: REPLICAS
            value: "{{inputs.parameters.replicas}}"
