The Argo Workflows REST API allows the workflow engine to work programmatically with other systems and applications to create, submit, and manage workflows, monitor their status, retrieve results, build custom applications, and integrating Argo Workflows into existing CI/CD pipelines and automation.
Use the API
To demonstrate how to use the Argo Workflows API, we'll use curl to send an HTTP request to the Argo server.
This guide assumed a workflow server has been deployed by following Argo Workflows guide.
This uses the same workflow YAML as the CLI guide.
Create a file named workflow.yaml, expand the section below, and copy/paste the contents into the file.
Click to expand - workflow.yaml
apiVersion:argoproj.io/v1alpha1kind:Workflowmetadata:generateName:gpu-sayspec:entrypoint:mainactiveDeadlineSeconds:300# Cancel operation if not finished in 5 minutesttlStrategy:secondsAfterCompletion:86400# Clean out old workflows after a day# Parameters can be passed/overridden via the argo CLI.# To override the printed message, run `argo submit` with the -p option:# $ argo submit examples/arguments-parameters.yaml -p messages='["CoreWeave", "Is", "Fun"]'arguments:parameters: - name:messagesvalue:'["Argo", "Is", "Awesome"]' - name:foovalue:"bar"templates: - name:mainsteps: - - name:echotemplate:gpu-echoarguments:parameters: - name:messagevalue:"{{item}}"withParam:"{{workflow.parameters.messages}}" - name:gpu-echoinputs:parameters: - name:messageretryStrategy:limit:1script:image:nvidia/cuda:11.4.1-runtime-ubuntu20.04command: [bash]source:| nvidia-smi echo "Input was: {{inputs.parameters.message}}" resources:requests:memory:128Micpu:500m# Half a corelimits:nvidia.com/gpu:1# Allocate one GPUaffinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:# This will REQUIRE the Pod to be run on a system with a GPU with 8 or 16GB VRAMnodeSelectorTerms: - matchExpressions: - key:gpu.nvidia.com/vramoperator:Invalues: - "8" - "16"
The API needs the workflow to be converted from YAML to JSON. Assuming yq is installed:
yqeval-o=jsonworkflow.yaml>workflow.json
Retrieve the Bearer token for the deployment by running the commands below for the client OS.
# Replace my-workflow with the deployment name.export ARGO_NAME=my-workflow# Use kubectl to find the name of the secret for the ${ARGO_NAME}-argo-client ServiceAccount.export SECRET=$(kubectlgetsa ${ARGO_NAME}-argo-client-o=jsonpath='{.secrets[0].name}')# Extract the token (a Kubernetes Secret), base64 decode it, and prepend "Bearer " to the string. This is the Bearer token.
export ARGO_TOKEN="Bearer $(kubectlgetsecret $SECRET -o=jsonpath='{.data.token}' |base64--decode)"# Display the Bearer token on the screen.echo $ARGO_TOKEN
# Replace "my-workflow" with the deployment name.$ARGO_NAME="my-workflow"# Use kubectl to find the name of the secret for the ${ARGO_NAME}-argo-client ServiceAccount.$SECRET=$(kubectl get sa $ARGO_NAME-argo-client -o=jsonpath='{.secrets[0].name}')# Extract the token (a Kubernetes Secret).$DATA_TOKEN=$(kubectl get secret $SECRET -o=jsonpath='{.data.token}')# base64 decode the token$DECODE_64=[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($DATA_TOKEN))# Prepend "Bearer " to the string. This is the Bearer token.$ARGO_TOKEN="Bearer $DECODE_64"# Display the Bearer token on the screen.Write-Output $ARGO_TOKEN