3

用例是我们考虑通过带有 PubSub 的 Argo 事件触发 Argo 工作流。PubSub 不保证一条消息只传递一次。是否有一种简单的方法可以防止工作流在已经运行时再次被触发?

类似于 CronWorkflows的concurrencyPolicy设置。

有一些东西要看 - 让我们假设whalesay工作流程:

apiVersion: argoproj.io/v1alpha1
kind: Workflow                  # new type of k8s spec
metadata:
  name: hello-world    # name of the workflow spec
  namespace: argo
spec:
  entrypoint: whalesay          # invoke the whalesay template
  templates:
  - name: whalesay              # name of the template
    container:
      image: docker/whalesay
      command: [cowsay]
      args: ["hello world"]
      resources:                # limit the resources
        limits:
          memory: 32Mi
          cpu: 100m

我发现了以下两个有希望的问题 - 但我未能提取此问题的解决方案。

4

1 回答 1

3

如果您只需要确保工作流不会同时运行多个实例,请使用 Argo 的内置同步功能。

apiVersion: v1
kind: ConfigMap
metadata:
 name: my-config
data:
  workflow: "1"  # Only one workflow can run at given time in particular namespace

---

apiVersion: argoproj.io/v1alpha1
kind: Workflow 
metadata:
  name: hello-world
spec:
  entrypoint: whalesay
  synchronization:
    semaphore:
      configMapKeyRef:
        name: my-config
        key: workflow
  templates:
  - name: whalesay
    container:
      image: docker/whalesay
# ...

如果您想避免两次处理相同的消息,您可以在工作流中添加一个步骤,以便在消息 ID 在数据库中(或类似的东西)时提前退出。

于 2021-02-23T18:20:57.037 回答