Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

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 a resource or kubectl step for deploy
  • Artifacts (source, dist) pass between stages through the artifact repo
  • Approval gate = a suspend: {} template, continue with argo 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 resource template (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 (use create with generateName, apply needs 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 k8s trigger (operation: create) whose resource is a Workflow
  • 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, with entrypoint, arguments, templates
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 workflow
    • templateRef - 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 Workflow arguments
  • Manage them with argo template create|list|get|delete and argo cluster-template ...

CronWorkflow

  • Runs a workflow on a schedule, spec.workflowSpec is 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-week
    • 0 * * * * hourly, 0 9 * * 1 Mondays 9am, */15 * * * * every 15 min, 0 18 * * 1-5 weekdays 6pm
  • timezone - IANA name, defaults to the controller’s timezone (usually UTC)
  • concurrencyPolicy (default Allow)
    • Allow - overlapping runs OK
    • Replace - stop the running one, start the new one
    • Forbid - skip the new run if one is still running
  • startingDeadlineSeconds - how late a missed run may still start
  • History: successfulJobsHistoryLimit / failedJobsHistoryLimit
  • workflowSpec can use workflowTemplateRef instead of inline templates
workflowSpec:
  workflowTemplateRef:
    name: cleanup-template
  arguments:
    parameters:
      - name: retention-days
        value: '30'
  • suspend: true stops 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: true when referencing)

  • workflowTemplateRef for whole workflow, templateRef for a single template

  • Triggers: CLI, kubectl, argo-server API, Argo Events

  • CronWorkflow = schedule + concurrencyPolicy + suspend

  • Lab 05: Workflow Templates

  • Workflow templates

  • Cron workflows

  • REST API