{
  "name": "kubectl-run-job",
  "title": "Run a one-off Kubernetes Job",
  "category": "Kubernetes",
  "tags": [
    "kubectl",
    "kubernetes"
  ],
  "version": "1.0.0",
  "date": "2026-10-18",
  "notes": "Initial release.",
  "latest": true,
  "installable": true,
  "url": "https://catalog.dagweave.com/api/v1/items/kubectl-run-job/1.0.0.json",
  "templateUrl": "https://catalog.dagweave.com/api/v1/items/kubectl-run-job/1.0.0/template.yaml",
  "entrypoint": "run",
  "parameters": [
    {
      "name": "image",
      "title": "Image",
      "description": "Container image the Job runs.",
      "type": "string",
      "required": true,
      "example": "postgres:18-alpine"
    },
    {
      "name": "name",
      "title": "Name",
      "description": "Name for the Job. It must not already exist in the namespace.",
      "type": "string",
      "required": true,
      "example": "reindex-2026-10"
    },
    {
      "name": "cleanup",
      "title": "Cleanup",
      "description": "Set to \"true\" to delete the Job once its log has been shown.",
      "type": "string",
      "required": false,
      "default": "true",
      "enum": [
        "true",
        "false"
      ]
    },
    {
      "name": "command",
      "title": "Command",
      "description": "Shell command to run in the image, which needs sh. Leave blank to run the image's own entrypoint.",
      "type": "string",
      "required": false,
      "default": "",
      "example": "pg_isready -h db.default.svc"
    },
    {
      "name": "namespace",
      "title": "Namespace",
      "description": "Namespace the resource lives in.",
      "type": "string",
      "required": false,
      "default": "default",
      "example": "default"
    },
    {
      "name": "service-account",
      "title": "Service account",
      "description": "Service account the Job runs as. Leave blank for the namespace default.",
      "type": "string",
      "required": false,
      "default": ""
    },
    {
      "name": "timeout-seconds",
      "title": "Timeout seconds",
      "description": "Seconds to wait for the Job to finish before failing the step.",
      "type": "string",
      "required": false,
      "default": "600"
    }
  ],
  "images": [
    {
      "ref": "cgr.dev/chainguard/kubectl@sha256:98f9c337808ecf5d5e80b79af4345762a3d8c803ebf8c857d2dddabf885107ba",
      "repository": "cgr.dev/chainguard/kubectl",
      "tag": "latest-dev",
      "digest": "sha256:98f9c337808ecf5d5e80b79af4345762a3d8c803ebf8c857d2dddabf885107ba"
    }
  ],
  "install": {
    "kubectl": "kubectl apply -n argo -f https://catalog.dagweave.com/api/v1/items/kubectl-run-job/1.0.0/template.yaml",
    "argo": "argo template create -n argo https://catalog.dagweave.com/api/v1/items/kubectl-run-job/1.0.0/template.yaml"
  },
  "template": "apiVersion: argoproj.io/v1alpha1\nkind: WorkflowTemplate\nmetadata:\n  name: kubectl-run-job\n  labels:\n    dagweave.io/catalog-item: kubectl-run-job\n  annotations:\n    dagweave.io/catalog-version: \"1.0.0\"\n    dagweave.io/catalog-category: \"Kubernetes\"\nspec:\n  entrypoint: run\n  templates:\n    - name: run\n      metadata:\n        annotations:\n          dagweave.io/local-support: unsupported\n          dagweave.io/local-support-reason: \u003e-\n            This step runs kubectl with whatever identity the pod is given. On Dagweave\n            Local that is the default service account of the hidden cluster's argo\n            namespace, which Argo's quick-start install grants create, get and patch on pods\n            and create and get on workflows, and nothing anywhere else. Creating a Job is\n            outside what that account may do, so the step fails on a 403 rather than\n            touching anything. The cluster you meant is one this run cannot reach.\n      inputs:\n        parameters:\n          - name: name\n          - name: image\n          - name: command\n            default: \"\"\n          - name: namespace\n            default: \"default\"\n          - name: service-account\n            default: \"\"\n          - name: timeout-seconds\n            default: \"600\"\n          - name: cleanup\n            default: \"true\"\n      container:\n        # cgr.dev/chainguard/kubectl:latest-dev\n        image: cgr.dev/chainguard/kubectl@sha256:98f9c337808ecf5d5e80b79af4345762a3d8c803ebf8c857d2dddabf885107ba\n        command: [sh, -c]\n        args:\n          - |\n            set -eu\n            set -- \"${NAME}\" -n \"${NAMESPACE}\" --image=\"${IMAGE}\" --dry-run=client -o json\n            if [ -n \"${COMMAND}\" ]; then set -- \"$@\" -- sh -c \"${COMMAND}\"; fi\n            kubectl create job \"$@\" \\\n              | kubectl patch --local -f - --type=merge -p '{\"spec\":{\"backoffLimit\":0}}' -o json \u003e /tmp/job.json\n            if [ -n \"${SERVICE_ACCOUNT}\" ]; then\n              kubectl set serviceaccount --local -f /tmp/job.json \"${SERVICE_ACCOUNT}\" -o json \u003e /tmp/job-sa.json\n              cp /tmp/job-sa.json /tmp/job.json\n            fi\n            kubectl create -f /tmp/job.json\n            status=timeout\n            end=$(( $(date +%s) + TIMEOUT_SECONDS ))\n            while [ \"$(date +%s)\" -lt \"${end}\" ]; do\n              if [ \"$(kubectl get job \"${NAME}\" -n \"${NAMESPACE}\" -o jsonpath='{.status.conditions[?(@.type==\"Complete\")].status}')\" = \"True\" ]; then status=complete; break; fi\n              if [ \"$(kubectl get job \"${NAME}\" -n \"${NAMESPACE}\" -o jsonpath='{.status.conditions[?(@.type==\"Failed\")].status}')\" = \"True\" ]; then status=failed; break; fi\n              sleep 5\n            done\n            kubectl logs \"job/${NAME}\" -n \"${NAMESPACE}\" --all-containers || true\n            if [ \"${CLEANUP}\" = \"true\" ]; then kubectl delete job \"${NAME}\" -n \"${NAMESPACE}\" --wait=false; fi\n            echo \"job ${NAME}: ${status}\"\n            [ \"${status}\" = \"complete\" ]\n        env:\n          - name: NAME\n            value: \"{{inputs.parameters.name}}\"\n          - name: IMAGE\n            value: \"{{inputs.parameters.image}}\"\n          - name: COMMAND\n            value: \"{{inputs.parameters.command}}\"\n          - name: NAMESPACE\n            value: \"{{inputs.parameters.namespace}}\"\n          - name: SERVICE_ACCOUNT\n            value: \"{{inputs.parameters.service-account}}\"\n          - name: TIMEOUT_SECONDS\n            value: \"{{inputs.parameters.timeout-seconds}}\"\n          - name: CLEANUP\n            value: \"{{inputs.parameters.cleanup}}\"\n        resources:\n          requests:\n            cpu: 50m\n            memory: 64Mi\n          limits:\n            memory: 256Mi\n",
  "templateSha256": "41d4568114e12631cdaf3c4311564fda800edf6435791728b4b158b6962f8271",
  "source": "https://github.com/dagweave/catalog/tree/67458f74dbbf913b03177f3cefc69424be85eb1d/catalog/kubectl-run-job",
  "catalogSha": "67458f74dbbf913b03177f3cefc69424be85eb1d"
}
