apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: helm-upgrade
  labels:
    dagweave.io/catalog-item: helm-upgrade
  annotations:
    dagweave.io/catalog-version: "1.0.4"
    dagweave.io/catalog-category: "Kubernetes"
spec:
  entrypoint: upgrade
  templates:
    - name: upgrade
      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: >-
            helm keeps its release history in Secrets in the target namespace. On
            Dagweave Local the pod runs as the default service account of the hidden
            cluster's argo namespace, which has no permission on secrets, on namespaces,
            or on anything a chart usually creates, so helm is refused as soon as it
            looks that history up and the step fails on a 403. Nothing is installed,
            here or on the cluster you meant.
      inputs:
        parameters:
          - name: release
          # Chart reference: a chart name (with repo-url) or an oci:// / local path.
          - name: chart
          - name: namespace
            default: default
          # Inline values.yaml content applied with -f.
          - name: values-inline
            default: ""
          # Chart repository URL, passed as --repo when set.
          - name: repo-url
            default: ""
      container:
        # alpine/helm:3.22.1
        image: alpine/helm@sha256:8191701ad1f82ee3695c87211fcbfe6d7b1bb7df92ac1c8de9ccdb0995a6a2c1
        command: [sh, -c]
        # helm upgrade --install (idempotent) against the in-cluster
        # serviceAccount. Optional --repo and inline values file.
        args:
          - |
            set -eu
            set --
            if [ -n "${REPO_URL}" ]; then set -- "$@" --repo "${REPO_URL}"; fi
            if [ -n "${VALUES}" ]; then
              printf '%s' "${VALUES}" > /tmp/values.yaml
              set -- "$@" -f /tmp/values.yaml
            fi
            helm upgrade --install "${RELEASE}" "${CHART}" \
              --namespace "${NAMESPACE}" --create-namespace "$@"
        env:
          - name: RELEASE
            value: "{{inputs.parameters.release}}"
          - name: CHART
            value: "{{inputs.parameters.chart}}"
          - name: NAMESPACE
            value: "{{inputs.parameters.namespace}}"
          - name: VALUES
            value: "{{inputs.parameters.values-inline}}"
          - name: REPO_URL
            value: "{{inputs.parameters.repo-url}}"
