ArgoWorkflow教程(二)---快速构建流水线:Workflow Template 概念

news/2024/9/17 16:56:00/文章来源:https://www.cnblogs.com/KubeExplorer/p/18369259

argoworkflow-2-model-analyze.png

上一篇我们部署了 ArgoWorkflow,并创建了一个简单的流水线做了个 Demo。本篇主要分析 ArgoWorkflow 中流水线相关的概念,了解概念后才能更好使用 ArgoWorkflow。

本文主要分析以下问题:

  • 1)如何创建流水线? Workflow 中各参数含义
  • 2)WorkflowTemplate 流水线模版如何使用,
  • 3)Workflow、WorkflowTemplate、template 之间的引用关系
  • 4)ArgoWorkflow 流水线最佳实践

1.基本概念

ArgoWorkflow 中包括以下几个概念:

  • Workflow:流水线,真正运行的流水线实例,类似于 Tekton 中的 pipelinerun
  • WorkflowTemplate:流水线模板,可以基于模板创建流水线,类似于 Tekton 中的 pipeline
    • ClusterWorkflowTemplate:集群级别的流水线模板,和 WorkflowTemplate 的关系类似于 K8s 中的 Role 和 ClusterRole
  • templates:Workflow 或者 WorkflowTemplate/ClusterWorkflowTemplate 的最小组成单位,流水线由多个 template 组成,可以理解为流水线中的某一个步骤。

WorkflowTemplate 和 ClusterWorkflowTemplate 暂时统称为 Template。

Workflow、Template(大写)、template(小写)之间的关系如下:

arg-workflow-template-ref.png

三者间关系比较复杂,官方也有提到这块因为一些历史遗留问题导致命名上比较混乱

个人感觉下面这种方式比较好理解:

  • template(小写):为 Template(大写)的基本组成单位,可以理解为流水线中的步骤
  • Template(大写):一条完整的流水线,一般由多个 template(小写) 组成
  • Workflow:真正运行的流水线实例,一般由 Template 直接创建,类似于流水线运行记录,每一条记录就是一个 Workflow

理清基本概念之后,接下来就看下看具体对象的分析。

2.Workflow

Workflow 是Argo中最重要的资源,具有两个重要功能:

  • 1)工作流定义
  • 2)工作流状态存储

先看下 Workflow 是怎么样的,以下是一个简单的 Workflow 例子:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:generateName: steps-
spec:entrypoint: hello           # We reference our first "template" heretemplates:- name: hello               # The first "template" in this Workflow, it is referenced by "entrypoint"steps:                    # The type of this "template" is "steps"- - name: hellotemplate: whalesay    # We reference our second "template" herearguments:parameters: [{name: message, value: "hello"}]- name: whalesay             # The second "template" in this Workflow, it is referenced by "hello"inputs:parameters:- name: messagecontainer:                # The type of this "template" is "container"image: docker/whalesaycommand: [cowsay]args: ["{{inputs.parameters.message}}"]

整个 Workflow 对象核心内容分为以下三部分:

  • templates:模板列表,此处定义了流水线中的所有步骤以及步骤之间的先后顺序。
  • entrypoint: 流水线入口,类似于代码中的 main 方法,此处一般引用某一个 template invocators 即可。
  • parameters:流水线中用到的参数,包括 arguments 块中的全局参数和 inputs 块中的局部参数两种

entrypoint

Workflow 中必须要指定 entrypoint,entrypoint 作为任务的执行起点,类似于程序中的 main 方法。

templates

ArgoWorkflow 当前支持 6 种 template,接下来挨个分析一下。

container

和 Kubernetes container spec 是一致的,这个类型的 template 就是启动一个 container,用户可以指定image、command、args 等信息来控制具体执行的动作。

  - name: whalesaycontainer:image: docker/whalesaycommand: [cowsay]args: ["hello world"]

script

script 实际上是 container 的封装,spec 和 container 一致,同时增加了 source 字段,用于定义一个脚本,脚本的运行结果会记录到{{tasks.<NAME>.outputs.result}} or {{steps.<NAME>.outputs.result}}

script 可以理解为简化了使用 container 来执行脚本的配置

  - name: gen-random-intscript:image: python:alpine3.6command: [python]source: |import randomi = random.randint(1, 100)print(i)

resource

Resource 类型的 template 用于操作集群中的资源,action 参数表示具体的动作,支持 get, create, apply, delete, replace, patch。

  - name: k8s-owner-referenceresource:action: createmanifest: |apiVersion: v1kind: ConfigMapmetadata:generateName: owned-eg-data:some: value

suspend

Suspend 类型的 template 比较简单,就是用于暂停流水线执行。

默认会一直阻塞直到用户通过argo resume命令手动恢复,或者通过duration 参数指定暂停时间,到时间后会自动恢复。

  - name: delaysuspend:duration: "20s"

steps

Steps 用于处理模版之间的关系,具体包含两方面:

  • 1)哪些任务需要运行
  • 2)这些任务按照什么先后顺序运行

看下面这个例子:

  - name: hello-hello-hellosteps:- - name: step1template: prepare-data- - name: step2atemplate: run-data-first-half- name: step2btemplate: run-data-second-half

哪些任务需要运行?

该 steps 则定义了要运行 step1、step2a、step2b 3 个 template。

这些任务按照什么先后顺序运行?

steps 中元素定义的先后顺序就是各个任务的执行先后顺序,在这里就是 step1 先运行,然后 step2a、step2b 并行运行。

注意:仔细看 yaml 中 step2a 和 step2b 是同一个元素中的,steps 是一个二维数组, 定义如下:

type Template struct {Steps []ParallelSteps `json:"steps,omitempty" protobuf:"bytes,11,opt,name=steps"`
}
type ParallelSteps struct {Steps []WorkflowStep `json:"-" protobuf:"bytes,1,rep,name=steps"`
}

转换为 json 形式就像这样:

{"steps": [["step1"],["step2a", "step2b"]]
}

这样应该比较清晰了,先后顺序一目了然

dag

Dag template 的作用和 steps 是一样的。

这里的 DAG 就是 Directed Acyclic Graph 这个 DAG。

DAG 和 Steps 区别在于任务先后顺序的定义上:

  • Steps 以定义先后顺序作为 template 执行先后顺序
  • DAG 则可以定义任务之间的依赖,由 argo 根据依赖自行生成最终的运行的先后顺序

看下面这个例子:

  - name: diamonddag:tasks:- name: Atemplate: echo- name: Bdependencies: [A]template: echo- name: Cdependencies: [A]template: echo- name: Ddependencies: [B, C]template: echo

DAG 中新增了 dependencies 字段,可以指定当前步骤依赖的的依赖。

哪些任务需要运行?

该 steps 则定义了要运行 A、B、C、D 4 个任务。

这些任务按照什么先后顺序运行?

不如 Steps 那么直接,需要根据 dependencies 分析依赖关系。

A 没有依赖,因此最先执行,B、C 都只依赖于 A,因此会再 A 后同时执行,D 则依赖于 B、C,因此会等B、C都完成后才执行。

转换为 json 形式如下:

{"steps": [["A"],["B", "C"],["D"]]
}

ps:相比之下 steps 方式更为直接,任务先后顺序一目了然。如果整个 Workflow 中所有任务先后顺序理清楚了就推荐使用 steps,如果很复杂,只知道每个任务之间的依赖关系那就直接用 DAG,让 ArgoWorkflow 计算。

template definitions & template invocators

大家可以发现,steps、dag 模板和另外 4 个不一样,他们都是可以指定多个 template 的。

前面分别介绍了 ArgoWorkflow 中的 6 种 template,实际上可以按照具体作用将这 6 个 template 分为 template definitions(模板定义)以及 template invocators(模板调用器)两种。

  • template definitions(模板定义):该类型 template 用于定义具体步骤要执行的内容,例子中的 whalesay 模板就是该类型
    • 包含 container, script, resource, suspend 等类型
  • template invocators(模板调用器):该类型 template 用于组合其他 template definitions(模版定义) ,定义步骤间的执行顺序等,例子中的 hello 模板就是该类型。
  • 一般 entrypoint 指向的就是该类型的模板
  • 包含dagsteps 两种类型,例子中的 hello 模板就是 steps 类型。

吐槽一下:template 这里有点绕,如果能将 模板定义 、模板调用器 拆分为两个不同的对象就比较清晰。

了解完 template 分类之后再回头看之前的 Workflow 例子就比较清晰了:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:generateName: steps-
spec:entrypoint: hello           # We reference our first "template" heretemplates:- name: hello               # The first "template" in this Workflow, it is referenced by "entrypoint"steps:                    # The type of this "template" is "steps"- - name: hellotemplate: whalesay    # We reference our second "template" herearguments:parameters: [{name: message, value: "hello"}]- name: whalesay             # The second "template" in this Workflow, it is referenced by "hello"inputs:parameters:- name: messagecontainer:                # The type of this "template" is "container"image: docker/whalesaycommand: [cowsay]args: ["{{inputs.parameters.message}}"]
  • 1)首先 whalesay 模板是一个 container 类型的 template,因此是 template definitions(模板定义)
  • 2)其次 hello 是一个 steps 类型的 template,因此是 template invocators(模板调用器)
    • 在该调用器中 steps 字段中定义了一个名为 hello 的步骤,该步骤引用的就是 whalesay template
  • 3)entrypoint 指定的是 hello 这个 template invocators(模板调用器)

接下来就是 Workflow 中另一重要对象 entrypoit。

entrypoint

entrypoint 作为任务的执行起点,类似于程序中的 main 方法,每个 Workflow 中都必须要指定 entrypoint。

注意:只有被 entrypoint 指定的任务才会运行,因此,entrypoint 一般只会指定 Steps 和 DAG 类型的 template,也就是template invocators(模板调用器)。然后由 Steps 中的 steps 或者 DAG中的 tasks 来指定多个任务。

因此,并不是 Workflow 中写了的 templates 都会执行。

看下面这个例子:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:generateName: steps-
spec:entrypoint: hello           # We reference our first "template" heretemplates:- name: hello               # The first "template" in this Workflow, it is referenced by "entrypoint"steps:                    # The type of this "template" is "steps"- - name: hellotemplate: whalesay    # We reference our second "template" herearguments:parameters: [{name: message, value: "hello"}]- name: whalesay             # The second "template" in this Workflow, it is referenced by "hello"inputs:parameters:- name: messagecontainer:                # The type of this "template" is "container"image: docker/whalesaycommand: [cowsay]args: ["{{inputs.parameters.message}}"]

Entrypoint 指定 hello,然后 hello 是一个 steps 类型的 template,也就是template invocators。然后在 hello template 的 steps 中指定了 whalesay 这个 template,最终 whalesay template 为 container 类型,也就是 template definitions。这里就是最终要运行的任务。

当然,entrypoint 也可以指定 template definitions(模板定义)类型的 template,不过这样只能运行一个任务,就像这样:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:generateName: steps-
spec:entrypoint: whalesaytemplates:- name: whalesay    container:image: docker/whalesaycommand: [cowsay]args: ["hello"]

至此,我们应该基本搞清楚了 Workflow 对象(参数部分除外)。接下来就看一下最后一部分,parameters。

Demo

列出几个复杂一点点的 Workflow,看一下是不是真的搞懂 Workflow 了。

下面是一个包含 4个任务的 Workflow:

  • 1)首先打印 hello
  • 2)然后执行一段 python 脚本,生成随机数
  • 3)sleep 20s
  • 4)创建一个 Configmap

提供了 steps 和 dag 两种写法,可以对比下

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:generateName: steps-
spec:entrypoint: hellotemplates:- name: hello              steps:          - - name: hellotemplate: whalesayarguments:parameters: [{name: message, value: "hello"}]- - name: runscripttemplate: gen-random-int- - name: sleeptemplate: delay- - name: create-cmtemplate: k8s-owner-reference# - name: diamond#   dag:#     tasks:#     - name: hello#       template: whalesay#       arguments:#         parameters: [{name: message, value: "hello"}]#     - name: runscript#       dependencies: [hello]#       template: gen-random-int#     - name: sleep#       template: delay#       dependencies: [runscript]#     - name: create-cm#       template: k8s-owner-reference#       dependencies: [sleep]- name: whalesayinputs:parameters:- name: messagecontainer:image: docker/whalesaycommand: [cowsay]args: ["{{inputs.parameters.message}}"]- name: gen-random-intscript:image: python:alpine3.6command: [python]source: |import randomi = random.randint(1, 100)print(i)- name: k8s-owner-referenceresource:action: createmanifest: |apiVersion: v1kind: ConfigMapmetadata:generateName: owned-eg-data:host: lixueduan.comwx: 探索云原生- name: delaysuspend:duration: "20s"

parameters

Workflow 中的参数可以分为以下两种:

  • 形参:在 template(template definitions) 中通过 inputs 字段定义需要哪些参数,可以指定默认值
  • 实参:在 template(template invocators) 中通过 arguments 字段为参数赋值,覆盖 inputs 中的默认值

以上仅为个人理解

inputs 形式参数

template 中可以使用 spec.templates[*].inputs 字段来指定形式参数,在 template 中可以通过{{inputs.parameters.$name}} 语法来引用参数。

下面这个例子则是声明了 template 需要一个名为 message 的参数,这样调用方在使用该 template 时就知道需要传哪些参数过来。

  templates:- name: whalesay-templateinputs:parameters:- name: messagecontainer:image: docker/whalesaycommand: [cowsay]args: ["{{inputs.parameters.message}}"]

当然也可以指定默认值

  templates:- name: whalesay-templateinputs:parameters:- name: messagevalue: "default message"container:image: docker/whalesaycommand: [cowsay]args: ["{{inputs.parameters.message}}"]

注意:如果未指定默认值,则调用该 template 时必须指定该参数,有默认值则可以不指定。

arguments 实际参数

spec.arguments用于定义要传递的实际参数,这部分参数在当前 Workflow 下的所有 Template 中都可以使用,可以使用 {{workflow.parameters.$name}} 语法来引用。

例如下面这个例子中指定了一个名为 message 的参数,并赋值为 hello world。

  arguments:parameters:- name: messagevalue: hello world

参数复用

除了在 steps/dag 中指定 arguments,甚至可以直接在 Workflow 中指定,然后 steps/dag 中通过{{workflow.parameters.$name}} 语法进行引用。这样即可实现参数复用,Workflow 中定义一次,steps/dag 中可以多次引用。

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:generateName: example-
spec:entrypoint: mainarguments:parameters:- name: workflow-param-1templates:- name: maindag:tasks:- name: step-A template: step-template-Aarguments:parameters:- name: template-param-1value: "{{workflow.parameters.workflow-param-1}}"- name: step-template-Ainputs:parameters:- name: template-param-1script:image: alpinecommand: [/bin/sh]source: |echo "{{inputs.parameters.template-param-1}}"

Demo

通过下面这个 Demo 来理解参数传递:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:generateName: steps-
spec:entrypoint: hello           # We reference our first "template" heretemplates:- name: hello               # The first "template" in this Workflow, it is referenced by "entrypoint"steps:                    # The type of this "template" is "steps"- - name: hellotemplate: whalesay    # We reference our second "template" herearguments:parameters: [{name: message, value: "hello"}]- name: whalesay             # The second "template" in this Workflow, it is referenced by "hello"inputs:parameters:- name: messagecontainer:                # The type of this "template" is "container"image: docker/whalesaycommand: [cowsay]args: ["{{inputs.parameters.message}}"]

上述例子中,template whalesay 定义了需要一个名为 message 的参数,同时在 steps template 中引用 whalesay 时通过 arguments 指定了参数 message 的值为 hello。因此最终会打印出 hello。

3.WorkflowTemplate

官方原文:

A WorkflowTemplate is a definition of a Workflow that lives in your cluster.

WorkflowTemplate 就是 Workflow 的定义,WorkflowTemplate 描述了这个流水线的详细信息,包括有哪些任务,任务之间的先后顺序等等。

根据前面对 Workflow 的描述可知,我们能直接创建 Workflow 对象来运行流水线,不过这种方式存在的一些问题:

  • 1)如果 template 比较多的话,Workflow 对象就会特别大,修改起来比较麻烦
  • 2)模板无法共享,不同 Workflow 都需要写一样的 template,或者同一个 template 会出现在不同的 Workflow yaml 中。

因此,关于 Workflow 和 WorkflowTemplate 的最佳实践:将 template 存到 WorkflowTemplate,Workflow 中只引用 Template 并提供参数即可。

而 ArgoWorkflow 中的工作流模板根据范围不同分为 WorkflowTemplateClusterWorkflowTemplate 两种。

  • WorkflowTemplate:命名空间范围,只能在同一命名空间引用
  • ClusterWorkflowTemplate:集群范围,任意命名空间都可以引用

WorkflowTemplate

下面是一个简单的 WorkflowTemplate:

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:name: workflow-template-submittablenamespace: default
spec:entrypoint: whalesay-templatearguments:parameters:- name: messagevalue: tpl-argument-defaulttemplates:- name: whalesay-templateinputs:parameters:- name: messagevalue: tpl-input-defaultcontainer:image: docker/whalesaycommand: [cowsay]args: ["{{inputs.parameters.message}}"]

可以看到 WorkflowTemplate 和 Workflow 参数是一模一样,这里就不在赘述了。

只需要将 kind 由 Workflow 替换为 WorkflowTemplate 即可实现转换。

workflowMetadata

workflowMetadata 是 Template 中独有的一个字段,主要用于存储元数据后续由这个 Template 创建出的 Workflow 都会自动携带上这些信息

通过这些信息可以追踪到 Workflow 是由哪个 Template 创建的。

使用方式就像下面这样,workflowMetadata 中指定了一个 label

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:name: workflow-template-submittable
spec:workflowMetadata:labels:example-label: example-value

然后由该 Template 创建的 Workflow 对象都会携带这个 label:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:annotations:workflows.argoproj.io/pod-name-format: v2creationTimestamp: "2023-10-27T06:26:13Z"generateName: workflow-template-hello-world-generation: 2labels:example-label: example-valuename: workflow-template-hello-world-5w7ssnamespace: default

ClusterWorkflowTemplate

类似于 WorkflowTemplate,可以理解为 k8s 中的 Role 和 ClusterRole 的关系,作用域不同罢了。

和 WorkflowTemplate 所有参数都一致,只是将 yaml 中的 kind 替换为 ClusterWorkflowTemplate 即可。

4.TemplateRef

创建好 WorkflowTemplate 之后就可以在 Workflow 中使用 TemplateRef 直接引用对应模板了,这样 Workflow 对象就会比较干净。

对于 WorkflowTemplate 的引用也有两种方式:

  • 1)workflowTemplateRef:引用完整的 WorkflowTemplate,Workflow 中只需要指定全局参数即可
  • 2)templateRef:只引用某一个 template,Workflow 中还可以指定其他的 template、entrypoint 等信息。

workflowTemplateRef

可以通过workflowTemplateRef字段直接引用 WorkflowTemplate。

注意📢:这里需要 Workflow 和 WorkflowTemplate 在同一个命名空间

就像这样:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:generateName: workflow-template-hello-world-
spec:arguments:parameters:- name: messagevalue: "from workflow"workflowTemplateRef:name: workflow-template-submittable

workflowTemplateRef 指定要引用的 Template 名字即可,这一句就相当于把对应 Template 中 spec 字段下的所有内容都搬过来了,包括 entrypoint、template 等。

Workflow 中一般只需要通过 argument 字段来实现参数覆盖,当然也可以不指定,若 Workflow 中不指定参数则会使用 Template 中提供的默认值

一个最精简的 Workflow 如下:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:generateName: workflow-template-hello-world-
spec:workflowTemplateRef:name: workflow-template-submittable

只有 workflowTemplateRef 字段,未提供 argument 参数。

和前面的 Workflow 对比起来,内容就更少了,因为大部分都写在 WorkflowTemplate 里了,Workflow 中一般只需要指定参数就行。

clusterWorkflowTemplateRef

和 workflowTemplateRef 类似,只需要增加 clusterScope: true 配置即可。

默认为 false,即 WorkflowTemplate

就像这样:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:generateName: workflow-template-hello-world-
spec:entrypoint: whalesaytemplates:- name: whalesaysteps:                              # You should only reference external "templates" in a "steps" or "dag" "template".- - name: call-whalesay-templatetemplateRef:                  # You can reference a "template" from another "WorkflowTemplate or ClusterWorkflowTemplate" using this fieldname: cluster-workflow-template-whalesay-template   # This is the name of the "WorkflowTemplate or ClusterWorkflowTemplate" CRD that contains the "template" you wanttemplate: whalesay-template # This is the name of the "template" you want to referenceclusterScope: true          # This field indicates this templateRef is pointing ClusterWorkflowTemplatearguments:                    # You can pass in arguments as normalparameters:- name: messagevalue: "hello world"

核心部分:

  workflowTemplateRef:name: cluster-workflow-template-submittableclusterScope: true

当指定为集群范围时,ArgoWorkflow 会去搜索 ClusterWorkflowTemplate 对象,否则会在当前命名空间搜索 WorkflowTemplate。

templateRef

除了使用 workflowTemplateRef / clusterWorkflowTemplateRef 引用整个 WorkflowTemplate 之外,还可以使用 templateRef 参数来实现引用 WorkflowTemplate 中的某一个 template。

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:generateName: workflow-template-hello-world-
spec:entrypoint: whalesaytemplates:- name: whalesaysteps:                              # You should only reference external "templates" in a "steps" or "dag" "template".- - name: call-whalesay-templatetemplateRef:                  # You can reference a "template" from another "WorkflowTemplate" using this fieldname: workflow-template-1   # This is the name of the "WorkflowTemplate" CRD that contains the "template" you wanttemplate: whalesay-template # This is the name of the "template" you want to referencearguments:                    # You can pass in arguments as normalparameters:- name: messagevalue: "hello world"

核心为:

          templateRef:name: workflow-template-1template: whalesay-template

参数分析:

  • name 指的是 WorkflowTemplate 名称,即 workflow-template-1 这个 WorkflowTemplat
  • template 指的就是 template 的名称 ,即 workflow-template-1 这个 WorkflowTemplat 中的名为 whalesay-template 的 template

注意📢:根据官方文档,最好不要在 stepsdag 这两个template invocators(模板调用器)之外使用 templateRef 。

原文如下:

You should never reference another template directly on a template object (outside of a steps or dag template). This behavior is deprecated, no longer supported, and will be removed in a future version.

Parameters

WorkflowTemplate 中使用参数和 Workflow 基本一致,没有太大区别。

  • template definitions 中通过 inputs 字段定义需要的参数
  • template invocators 中通过 arguments 字段为参数复制

Workflow 中引用 WorkflowTemplate 时可以再次定义 arguments 以覆盖 WorkflowTemplate 中的默认参数。

最佳实践

根据 workflowTemplateRef 和 templateRef 描述可以得出以下最佳实践:

  • 1)workflowTemplateRef 使用:WorkflowTemplate 中定义完整流水线内容,包括 entrypoint、template,Workflow 中通过 workflowTemplateRef 引用并通过 argument 指定参数覆盖默认值。
  • 2)templateRef 使用:WorkflowTemplate 中不定义完整流水线内容,只定义常用 template,Workflow 中需要使用该类型 template 时,通过 templateRef 引用,而不是在 Workflow 中再定义一次该 template。

第一种情况 WorkflowTemplate 可以称为流水线模板,第二种情况下 WorkflowTemplate 充当 template-utils 角色。


【ArgoWorkflow 系列】持续更新中,搜索公众号【探索云原生】订阅,阅读更多文章。


5.小结

本文主要分析了 ArgoWorkflow 中的 Workflow、WorkflowTemplate、template 对象及其之间的联系。

1)Workflow 对象:由 templates、entrypoint 组成。

  • templates:按照作用分为 template definitions(模板定义)以及 template invocators(模板调用器)
    • template definitions:用于定义具体步骤要执行的内容,包括 container、script、resource、suspend
    • template invocators:用于组合其他模板,控制任务先后顺序,包括 steps、dag
  • entrypoint:任务执行起点

2)WorkflowTemplate/ClusterWorkflowTemplate 对象:和 Workflow 对象一致,但只用于定义流水线,不可运行

  • Workflow 中可以通过 WorkflowTemplateRef/clusterWorkflowTemplateRef 引用整个 WorkflowTemplate
  • 或者通过 templateRef 引用某个 template

3)Parameters:分为形参和实参

  • inputs:形参,申明该 template 需要使用哪些参数,可指定默认值
  • arguments:实参,为对应 template 中的参数赋值,会覆盖 inputs 提供的默认值

4)参数优先级:

  • Workflow arguments > WorkflowTemplate arguments > WorkflowTemplate inputs

最后则是Workflow、WorkflowTemplate、template 这三者之间的关系

arg-workflow-template-ref.png

5)一些最佳实践:

WorkflowTemplate

  • 1)可以用作流水线模版:WorkflowTemplate 中定义全部的 entrypoint 和 templates,Workflow 中通过 WorkflowTemplateRef 引入即可使用
  • 2)用作 template-utils:WorkflowTemplate 中仅包含常用的 template,Workflow 中要使用时通过 templateRef 引入,避免重复定义 template

steps 和 dag 选择

  • steps 方式更为直接,任务先后顺序一目了然,但是需要理清所有任务的先后顺序
  • dag 则不够直观,但是填写时只需要知道某个任务的依赖关系就可以添加新任务

建议:如果整个 Workflow 中所有任务先后顺序理清楚了就推荐使用 steps,如果很复杂,只知道每个任务之间的依赖关系那就直接用 DAG,让 ArgoWorkflow 计算。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/784230.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

神经网络之卷积篇:详解单层卷积网络(One layer of a convolutional network)

详解单层卷积网络 如何构建卷积神经网络的卷积层,下面来看个例子。已经写了如何通过两个过滤器卷积处理一个三维图像,并输出两个不同的44矩阵。假设使用第一个过滤器进行卷积,得到第一个44矩阵。使用第二个过滤器进行卷积得到另外一个44矩阵。最终各自形成一个卷积神经网络层…

小小的引用计数,大大的性能考究

本文基于 Netty 4.1.56.Final 版本进行讨论在上篇文章《聊一聊 Netty 数据搬运工 ByteBuf 体系的设计与实现》 中,笔者详细地为大家介绍了 ByteBuf 整个体系的设计,其中笔者觉得 Netty 对于引用计数的设计非常精彩,因此将这部分设计内容专门独立出来。Netty 为 ByteBuf 引入…

【生化代谢基础笔记】RNA 合成

第一节 原核生物转录的模板和酶⚠️ RNA合成需要:DNA Template,NTP,RNA pol,其他蛋白质因子,$Mg^{2+}$一、原核生物转录模板模板链(Template strand) VS 编码链(Coding strand)模板链为合成模板另一股单链为编码链,mRNA 碱基序列与编码链一致二、RNA 聚合酶催化 RNA …

暑假集训CSP提高模拟 25

暑假集训CSP提高模拟 25 组题人: @KafuuChinocpp | @H_Kaguya\(T1\) P235.可持久化线段树 \(0pts\)弱化版: SP11470 TTM - To the moon标记永久化主席树板子。点击查看代码 const ll p=998244353; ll a[100010]; struct PDS_SMT {ll root[100010],rt_sum;struct SegmentTree{…

[Flink] Flink 序列化器

Flink 序列化器依赖包及版本信息org.apache.kafka:kafka-clients:${kafka-clients.version=2.4.1}org.apache.flink:flink-java:${flink.version=1.12.6} org.apache.flink:flink-clients_${scala.version=2.11}:${flink.version} org.apache.flink:flink-streaming-java_${sca…

怎么在pycharm里面写.md文件

一、插件安装 如果不清楚自己的PyCharm是否自带Markdown,可以在File - settings - Plugins - installed中查看是否有“Markdown”插件。 如果没有安装,可以在File - settings - Plugins - Marketplace中搜索“Markdown”安装。二、创建Markdown文件 在Pycharm中,Markdown(.m…

香城档案利用 NocoBase 快速实现智能档案管理

探索香城档案如何通过 NocoBase 革新档案管理,通过智能系统和强大的自动化技术提高效率。关于档案管理行业 档案管理历史悠久,最早可追溯至周朝。周文王姬昌非常重视档案管理,他命令手下的管理者将这些文献和档案进行整理和分类,然后存放在专门的档案馆中。这些档案馆也被称…

无线露点监测仪器在线式4G/WiFi传输MQTT协议对接云平台

无线露点温度环境检测仪器,传感变送器。4G/WiFi/LoRa无线传输,在线式监测压缩空气露点,高精度,具备加热抗结露功能,适用于电池生产、半导体制造、干燥系统、实验室等高精度控制湿度的场景。配套云平台可在手机app电脑端远程查看实时历史数据。

vCenter通过修改主机配置文件来重置ESXi主机root密码

背景:管理员一般通过vCenter来管理ESXi主机,时间长了,ESXi主机的root密码忘记了,本文主要介绍在vCenter中通过修改主机配置文件来修改ESXI主机的root密码,不用重启ESXI主机。 1、提取主机配置文件 选中要操作的主机,右键选择“主机配置文件”>>点击“提取主机配置文…

「代码随想录算法训练营」第四十二天 | 单调栈 part2

42. 接雨水题目链接:https://leetcode.cn/problems/trapping-rain-water/ 文章讲解:https://programmercarl.com/0042.接雨水.html 题目难度:困难 视频讲解:https://www.bilibili.com/video/BV1uD4y1u75P/ 题目状态:这道题目在LeetCode Top100中做过,使用两种方法,再回顾…

深入理解双变量(二元)正态投影:理论基础、直观解释与应用实例

在统计学和机器学习中,理解变量之间的关系对于构建预测模型和分析数据至关重要。探索这些关系的一种基本技术是双变量投影 bivariate projection。它依赖于二元正态分布的概念,所以又被称为二元投影。这种技术允许我们根据另一个变量来检验和预测一个变量的行为,利用它们之间的…

校验和

1. 对应数据位累加和: 需确认协议规定是从哪一位累加到哪一位,以及对应到代码中rd_cnt[7:0]是从第几位累加到第几位。//校验和 reg [15:0] rcvCLJ_SUM; always @(posedge SYS_CLK or negedge sys_rst_n ) beginif(!sys_rst_n) rcvCLJ_SUM <= 16d0;else if(rd_cnt>8d2 &…