首页 > 解决方案 > 通过基于 webhook 有效载荷数据键的 argo 事件触发 argo 工作流模板

问题描述

我正在寻找一种使用 webhook json 有效负载键触发工作流的方法,例如如果有效负载是 {"action":"copy","id":"someid"}

在触发器上

triggers:
   template:
    - "group1"
      "use this template if action key is 'copy'"
    - "group2"
      "use this template" if action key is 'move'"

我创建了一个示例传感器文件,但是 argo sersor 抱怨 eventSourceName 使用了多次。

apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
  name: testing-sensor
spec:
  template:
    serviceAccountName: argo 
  dependencies:
    - name: data
      eventSourceName: testhook
      eventName: test
      filters:
        data:
          - path: body.message
            type: string
            value:
              - copy
    
    - name: data1
      eventSourceName: testhook
      eventName: test
      filters:
        data:
          - path: body.message
            type: string
            value:
              - move
  triggers:
    - template:
        conditions: "data"
        name: group-1
        
    - template:
        conditions: "data1"
        name: group-2
         

如果有人可以提供帮助,那就太好了

标签: argo-events

解决方案


您应该在传感器中使用数据过滤器。(示例传感器。)

它看起来像这样:

apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
  name: data-filter
spec:
  dependencies:
    - name: test-dep
      eventSourceName: webhook
      eventName: example
      filters:
        data:
          - path: body.action
            type: string
            value:
              - "copy"
  triggers:
    - template:
        name: data-workflow
        k8s:
          group: argoproj.io
          version: v1alpha1
          resource: workflows
          operation: create
# ...

推荐阅读