为 Argo-Events 传感器触发器负载定义键值对

Define key value pair for Argo-Events sensor trigger payload

我正在尝试使用自定义键值对填充 Argo-Events 传感器 Nats 触发器负载。这些值不是依赖项的一部分。有人知道这样做的方法吗?

来自文档:

Payload is the list of key-value extracted from an event payload to construct the request payload.

传感器定义:

apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
  name: minio-sensor
spec:
  dependencies:
    - name: test-dep
      eventSourceName: minio
      eventName: example
  triggers:
    - template:
        name: nats-trigger
        nats:
          # NATS Server URL
          url: nats.argo-events.svc:4222
          # Name of the subject
          subject: minio-events
          payload:
            - someKey: someValue
            - src:
                dependencyName: test-dep
                dataKey: notification.0.s3.object.key
              dest: fileName

终于找到解决办法了。实际上是两个。 (最好使用Argo-Events版本>=1.6.0)

  1. 修改依赖项的事件主体。
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
  name: minio-sensor
spec:
  dependencies:
    - name: test-dep
      eventSourceName: minio
      eventName: example
      transform:
        script: |-
          event.body.someKey='someValue'
          return event
  triggers:
    - template:
        name: nats-trigger
        nats:
          # NATS Server URL
          url: nats.argo-events.svc:4222
          # Name of the subject
          subject: minio-events
          payload:
            - src:
                dependencyName: test-dep
                dataKey: body.someKey
              dest: someKey
            - src:
                dependencyName: test-dep
                dataKey: notification.0.s3.object.key
              dest: fileName
  1. 为 non-existing 路径使用默认值。
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
  name: minio-sensor
spec:
  dependencies:
    - name: test-dep
      eventSourceName: minio
      eventName: example
  triggers:
    - template:
        name: nats-trigger
        nats:
          # NATS Server URL
          url: nats.argo-events.svc:4222
          # Name of the subject
          subject: minio-events
          payload:
            - src:
                dependencyName: test-dep
                dataKey: body.non-existing
                value: someValue
              dest: someKey
            - src:
                dependencyName: test-dep
                dataKey: notification.0.s3.object.key
              dest: fileName