CI/CD Integration
- Workflows work well as CI/CD pipelines: build, test, scan, deploy
- Typical shape is a
dag(parallel build/test/scan stages) with aresourceorkubectlstep for deploy - Artifacts (source,
dist) pass between stages through the artifact repo - Approval gate = a
suspend: {}template, continue withargo resume <wf>
- - name: approval-gate
template: approval
when: '{{workflow.parameters.environment}} == production'
- Image builds in a pod use kaniko (no docker daemon in the cluster)
container:
image: gcr.io/kaniko-project/executor:latest
args:
- --dockerfile=/build/Dockerfile
- --context=/build
- --destination=myregistry/myapp:{{inputs.parameters.tag}}
- Deploy with a
resourcetemplate (action: apply) or a kubectl image, needs RBAC for the workflow SA - Verify with
kubectl rollout status deployment/myapp -n <ns>and a curl smoke test
Triggering workflows
CLI
argo submit workflow.yaml
argo submit workflow.yaml -p environment=production -p version=v2.0.0
argo submit --watch workflow.yaml
argo submit --from workflowtemplate/build-template -p repo-url=https://github.com/example/app.git
kubectl / k8s API
kubectl create -f workflow.yaml(usecreatewithgenerateName,applyneeds a fixed name)- Instantiate a template with
workflowTemplateRef
apiVersion: argoproj.io/v1alpha1
## Prune
kind: Workflow
metadata:
generateName: from-template-
## Prune
spec:
workflowTemplateRef:
name: build-template
arguments:
parameters:
- name: repo-url
value: 'https://github.com/example/app.git'
HTTP API
- Served by argo-server (port 2746)
curl -X POST https://argo-server:2746/api/v1/workflows/argo/submit \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"resourceKind": "WorkflowTemplate", "resourceName": "build-template",
"submitOptions": {"parameters": ["repo-url=https://github.com/example/app.git"]}}'
POST /api/v1/workflows/<ns>with the workflow JSON creates one directly
Argo Events
- Sensor with a
k8strigger (operation: create) whose resource is aWorkflow - EventSource (webhook, etc) -> Sensor -> Workflow
triggers:
- template:
name: workflow-trigger
k8s:
operation: create
source:
resource:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: triggered-workflow-
spec: ...
WorkflowTemplate vs ClusterWorkflowTemplate
- Reusable workflow definitions
- WorkflowTemplate: namespaced, only usable in its own namespace
- ClusterWorkflowTemplate: cluster scoped, usable from any namespace
- Same spec as a
Workflow, withentrypoint,arguments,templates
- Same spec as a
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: build-template
namespace: argo
spec:
entrypoint: build-pipeline
arguments:
parameters:
- name: repo-url
- name: branch
value: 'main'
templates:
- name: build-pipeline
## Prune
steps: ...
- Two ways to use them
workflowTemplateRef- run the whole template as a workflowtemplateRef- call a single template from a template
# whole template (cluster one needs clusterScope)
spec:
workflowTemplateRef:
name: common-tests
clusterScope: true
# one template out of a WorkflowTemplate
- name: deploy-dev
templateRef:
name: deploy-template
template: deploy
# clusterScope: true for a ClusterWorkflowTemplate
arguments:
parameters:
- name: environment
value: development
- Override parameters in the referencing
Workflowarguments - Manage them with
argo template create|list|get|deleteandargo cluster-template ...
CronWorkflow
- Runs a workflow on a schedule,
spec.workflowSpecis a normal workflow spec
apiVersion: argoproj.io/v1alpha1
kind: CronWorkflow
metadata:
name: nightly-build
namespace: argo
spec:
schedule: '0 2 * * *'
timezone: 'America/Los_Angeles'
startingDeadlineSeconds: 0
concurrencyPolicy: Replace
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 3
suspend: false
workflowSpec:
entrypoint: build
templates: ...
- Standard cron syntax:
minute hour day-of-month month day-of-week0 * * * *hourly,0 9 * * 1Mondays 9am,*/15 * * * *every 15 min,0 18 * * 1-5weekdays 6pm
timezone- IANA name, defaults to the controller’s timezone (usually UTC)concurrencyPolicy(defaultAllow)Allow- overlapping runs OKReplace- stop the running one, start the new oneForbid- skip the new run if one is still running
startingDeadlineSeconds- how late a missed run may still start- History:
successfulJobsHistoryLimit/failedJobsHistoryLimit workflowSpeccan useworkflowTemplateRefinstead of inline templates
workflowSpec:
workflowTemplateRef:
name: cleanup-template
arguments:
parameters:
- name: retention-days
value: '30'
suspend: truestops new runs
argo cron create cron.yaml
argo cron list
argo cron suspend nightly-build
argo cron resume nightly-build
Remember
-
WorkflowTemplate = namespaced, ClusterWorkflowTemplate = cluster-wide (
clusterScope: truewhen referencing) -
workflowTemplateReffor whole workflow,templateReffor a single template -
Triggers: CLI, kubectl, argo-server API, Argo Events
-
CronWorkflow = schedule +
concurrencyPolicy+suspend