4

I'm trying to trigger a pre existing ClusterWorkflowTemplate from a post request in argo/ argo-events.

I've been following the example here, but i don't want to define the workflow in the sensor- I want to separate this.

I can't get the sensor to import and trigger the workflow, what is the problem?

# kubectl apply -n argo-test -f templates/whalesay/workflow-template.yml
apiVersion: argoproj.io/v1alpha1
kind: ClusterWorkflowTemplate
metadata:
  name: workflow-template-submittable
spec:
  entrypoint: whalesay-template
  arguments:
    parameters:
      - name: message
        value: hello world
  templates:
    - name: whalesay-template
      inputs:
        parameters:
          - name: message
      container:
        image: docker/whalesay
        command: [cowsay]
        args: ["{{inputs.parameters.message}}"]
# kubectl apply -n argo-events templates/whalesay/event-source.yml
apiVersion: argoproj.io/v1alpha1
kind: EventSource
metadata:
  name: webhook
spec:
  service:
    ports:
      - port: 12000
        targetPort: 12000
  webhook:
    # event-source can run multiple HTTP servers. Simply define a unique port to start a new HTTP server
    example:
      # port to run HTTP server on
      port: "12000"
      # endpoint to listen to
      endpoint: /example
      # HTTP request method to allow. In this case, only POST requests are accepted
      method: POST
# kubectl apply -n argo-events -f templates/whalesay/sensor.yml
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
  name: workflow
  namespace: argo-events
  finalizers:
    - sensor-controller
spec:
  template:
    serviceAccountName: operate-workflow-sa
  dependencies:
    - name: http-post-trigger
      eventSourceName: webhook
      eventName: example
  triggers:
    - template:
        name: workflow-trigger-1
        argoWorkflow:
          group: argoproj.io
          version: v1alpha1
          kind: Workflow
          operation: submit
          metadata:
            generateName: cluster-workflow-template-hello-world-
          spec:
            entrypoint: whalesay-template
            workflowTemplateRef:
              name: cluster-workflow-template-submittable
              clusterScope: true
# to launch
curl -d '{"message":"this is my first webhook"}' -H "Content-Type: application/json" -X POST http://argo-events-51-210-211-4.nip.io/example
# error
{
    "level": "error",
    "ts": 1627655074.716865,
    "logger": "argo-events.sensor-controller",
    "caller": "sensor/controller.go:69",
    "msg": "reconcile error",
    "namespace": "argo-events",
    "sensor": "workflow",
    "error": "temp ││ late workflow-trigger-1 is invalid: argoWorkflow trigger does not contain an absolute action",
}

References:

1 Answer 1

10

I had to:

  • Ensure that my service account operate-workflow-sa had cluster privileges
  • Correct my sensor.yml syntax spec

Cluster privileges:

# kubectl apply -f ./k8s/workflow-service-account.yml
apiVersion: v1
kind: ServiceAccount
metadata:
  namespace: argo-events
  name: operate-workflow-sa
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: operate-workflow-role
  # namespace: argo-events
rules:
  - apiGroups:
      - argoproj.io
    verbs:
      - "*"
    resources:
      - workflows
      - clusterworkflowtemplates
      - workflowtemplates
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: operate-workflow-role-binding
  namespace: argo-events
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: operate-workflow-role
subjects:
  - kind: ServiceAccount
    name: operate-workflow-sa
    namespace: argo-events

sensor.yml (note the addition of the serviceAccountName for the workflow too):

apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
  name: workflow
  namespace: argo-events
  finalizers:
    - sensor-controller
spec:
  template:
    serviceAccountName: operate-workflow-sa
  dependencies:
    - name: http-post-trigger
      eventSourceName: webhook
      eventName: example
  triggers:
    # https://github.com/argoproj/argo-events/blob/master/api/sensor.md#triggertemplate
    - template:
        name: workflow-trigger-1
        argoWorkflow:
          # https://github.com/argoproj/argo-events/blob/master/api/sensor.md#argoproj.io/v1alpha1.ArgoWorkflowTrigger
          group: argoproj.io
          version: v1alpha1
          resource: Workflow
          operation: submit
          metadata:
            generateName: cluster-workflow-template-hello-world-
          source:
            resource:
              apiVersion: argoproj.io/v1alpha1
              kind: Workflow
              metadata:
                name: special-trigger
              spec:
                serviceAccountName: operate-workflow-sa
                entrypoint: whalesay-template
                workflowTemplateRef:
                  name: whalesay-template
                  clusterScope: true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.