argoproj / argo-events

Event-driven Automation Framework for Kubernetes
https://argoproj.github.io/argo-events/
Apache License 2.0
2.34k stars 729 forks source link

Trigger argoworkflow from cluster workflow template and workflow template yaml file #1678

Open rwong2888 opened 2 years ago

rwong2888 commented 2 years ago

Would like the ability to trigger argo workflow with cluster workflow template or workflow template

zhongdai commented 2 years ago

This can be done, and here is the example Sensor, it triggers a Workflow based on a ClusterWorkflowTemplate - cluster-workflow-template-submittable.

Just be noted,

apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
  name: sensor-webhook-1
  namespace: argo-events
spec:
  template:
    serviceAccountName: operate-workflow-sa
  dependencies:
    - name: test-dep
      eventSourceName: es-webhook
      eventName: example
  triggers:
    - template:
        name: webhook-workflow-trigger-1
        k8s:
          group: argoproj.io
          version: v1alpha1
          resource: workflows
          operation: create
          source:
            resource:
              apiVersion: argoproj.io/v1alpha1
              kind: Workflow
              metadata:
                generateName: cluster-wftmpl-triggered-by-sensor-1-
                # namespace: argo-events
              spec:
                serviceAccountName: workflow-pods-sa # default is `default`
                nodeSelector:
                  usage: generic-workload
                entrypoint: whalesay-template
                arguments:
                  parameters:
                  - name: message
                    value: "from workflow not cluster template"
                workflowTemplateRef:
                  name: cluster-workflow-template-submittable
                  clusterScope: true
          parameters:
            - src:
                dependencyName: test-dep
                dataKey: body.message
              dest: spec.arguments.parameters.0.value
rwong2888 commented 2 years ago

That is not exactly what I want... Your source is a Workflow, I'd like to point to my git repo that points to a path of a clusterworkflow template or workflow template, but have it execute a workflow based on that. Is that possible?

zhongdai commented 2 years ago

In this case, you may need to update the title to make it clear. What do you need - create a Workflow based on a YAML file from a Git repo. When we say WorkflowTemplate or ClusterWorkflowTemplate, usually we are referring to the already created resources in the cluster, but not the YAML files.

rwong2888 commented 2 years ago

Updated the title

maxisam commented 2 years ago

@rwong2888 I think this is what you want https://github.com/argoproj/argo-events/blob/master/examples/tutorials/03-trigger-sources/sensor-git.yaml

Although this will trigger a workflow. I don't understand why do you want to trigger a template. Because template can just live in the cluster. workflow is the one need to be triggered.

rwong2888 commented 2 years ago

@maxisam , that is not quite what I want to accomplish. It's a bit of duplicate work to create a workflow that is the same as a (cluster)workflow template.