ArgoWorkflow教程(六)---无缝实现步骤间参数传递
之前我们分析了,Workflow、WorkflowTemplate 、template 3 者之间如何传递参数。
本文主要分析同一个 Workflow 中的不同 step 之间实现参数传递,比如将上一个步骤的输出作为下一个步骤的结果进行使用(而非以文件方式传递)。
1. 概述
然后就是之前只分析了 Workflow、WorkflowTemplate 、template 3 者之间如何传递参数,今天继续分析一下步骤之间如何传递参数。
要实现步骤间参数传递,需要实现两个功能:
1)导出结果
2)导入参数
基于之前的知识,要实现这两个功能,可以想到的一种方式就是使用 artifact:
- 导出结果:将参数写入文件,然后以 artifact 保存到 s3
- 导入参数:下一个 step 下载 artifact 并从中获取参数。
确实可以实现功能,但是有点蹩脚,毕竟 artifact 主要是用于保存文件的。argoworkflow 中也直接提供了对应的 feature 来供大家使用。
2. 步骤间参数传递
- 将结果导出为 Output Parameter
- 将上一步的 Output Parameter 导入为当前步骤的 Input Parameter
完整 Demo 如下:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: output-parameter-
spec:
entrypoint: output-parameter
templates:
- name: output-parameter
steps:
- - name: generate-parameter
template: whalesay
- - name: consume-parameter
template: print-message
arguments:
parameters:
# Pass the hello-param output from the generate-parameter step as the message input to print-message
- name: message
value: "{{steps.generate-parameter.outputs.parameters.hello-param}}"
- name: whalesay
container:
image: docker/whalesay:latest
command: [sh, -c]
args: ["echo -n hello world > /tmp/hello_world.txt"] # generate the content of hello_world.txt
outputs:
parameters:
- name: hello-param # name of output parameter
valueFrom:
path: /tmp/hello_world.txt # set the value of hello-param to the contents of this hello-world.txt
- name: print-message
inputs:
parameters:
- name: message
container:
image: docker/whalesay:latest
command: [cowsay]
args: ["{{inputs.parameters.message}}"]
导出结果
- name: whalesay
container:
image: docker/whalesay:latest
command: [sh, -c]
args: ["echo -n hello world > /tmp/hello_world.txt"] # generate the content of hello_world.txt
outputs:
parameters:
- name: hello-param # name of output parameter
valueFrom:
path: /tmp/hello_world.txt # set the value of hello-param to the contents of this hello-world.txt
首先是 step 的内容,这里为了简单,就只有一个 echo 命令,将结果(hello world)写入到文件
/tmp/hello_world.txt
中。
然后就是到处结果了:
outputs:
parameters:
- name: hello-param # name of output parameter
valueFrom:
path: /tmp/hello_world.txt # set the value of hello-param to the contents of this hello-world.txt
定义了一个 output 参数,名为 hello-param,该参数的 value 从 /tmp/hello_world.txt
文件中获取,最终得到的 value 就是之前写入的 hello world
。
至此,我们就讲当前步骤的结果导出成了一个 Output Parameter,可以在后续步骤使用了。
导入参数
后续步骤,其实很简单,和普通步骤一样的,通过 Input Parameter 定义参数,然后在使用的使用通过语法{{inputs.parameters.name}}
引用即可。
- name: print-message
inputs:
parameters:
- name: message
container:
image: docker/whalesay:latest
command: [cowsay]
args: ["{{inputs.parameters.message}}"]
唯一区别在于,这个参数的来源,之前我们都是直接讲参数定义在 Workflow 中的,这里需要改成引用之前步骤导出的 Output Parameter,就像这样:
spec:
entrypoint: output-parameter
templates:
- name: output-parameter
steps:
- - name: generate-parameter
template: whalesay
- - name: consume-parameter
template: print-message
arguments:
parameters:
# Pass the hello-param output from the generate-parameter step as the message input to print-message
- name: message
value: "{{steps.generate-parameter.outputs.parameters.hello-param}}"
在 arguments.parameters 中直接引用了之前步骤的 Output Parameter,语法为 {{steps.$stepName.outputs.parameters.$parameterName}}
。
之前我们导出结果的步骤名为 generate-parameter,然后导出的参数名为 hello-param,因此这里就使用{{steps.generate-parameter.outputs.parameters.hello-param}}
来引用该参数。
内置的 result 参数
除了我们手动导出的参数之外,ArgoWorkflow 还会默认生成一个 Output Parameter,他就是 result。
和其他 Output Parameter 一样,可以通过 {{steps.$stepName.outputs.parameters.$parameterName}}
语法进行引用。
这个 result 参数会捕获最大 256KB 的标准输出作为 value,因此他可以包含以下内容:
- 1)script 的运行结果
- 2)容器的标准输出
- 3)...
只要是在容器中输出到标准输出的,内容都可以被 result 捕获。
【ArgoWorkflow 系列】持续更新中,搜索公众号【探索云原生】订阅,阅读更多文章。
3. 小结
本文主要分析了 Argo 中的 Workflow 中怎么传递参数还是比较简单的:
- 1)通过 Output Parameter 导出参数
- 2)在 arguments.parameters 中引用上一步导出的参数
最后介绍了一下内置的 result Output Parameter ,可以用于获取容器中的标准输出。
ArgoWorkflow教程(六)---无缝实现步骤间参数传递的更多相关文章
- 数据库 MySQL Jdbc JDBC的六个固定步骤
*0 案例: a)在JavaScript中使用正则表达式,在JS中正则表达式的定界符是:// var regexp = /^[0-9]+$/; if(regexp.test(nu ...
- Swift中文教程(六)--枚举和结构
原文:Swift中文教程(六)--枚举和结构 Enumerations 枚举 使用 enum 来创建一个枚举.跟Classes(类)和其他类型的命名方式一样,枚举也可以有Method(方法). enu ...
- PySide——Python图形化界面入门教程(六)
PySide——Python图形化界面入门教程(六) ——QListView和QStandardItemModel 翻译自:http://pythoncentral.io/pyside-pyqt-tu ...
- Elasticsearch入门教程(六):Elasticsearch查询(二)
原文:Elasticsearch入门教程(六):Elasticsearch查询(二) 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:h ...
- CRL快速开发框架系列教程六(分布式缓存解决方案)
本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...
- C#微信公众号开发系列教程六(被动回复与上传下载多媒体文件)
微信公众号开发系列教程一(调试环境部署) 微信公众号开发系列教程一(调试环境部署续:vs远程调试) C#微信公众号开发系列教程二(新手接入指南) C#微信公众号开发系列教程三(消息体签名及加解密) C ...
- 无废话ExtJs 入门教程六[按钮:Button]
无废话ExtJs 入门教程六[按钮:Button] extjs技术交流,欢迎加群(201926085) 继上一节内容,我们在表单里加了个两个按钮“提交”与重置.如下所示代码区的第68行位置, butt ...
- [转]Android Studio系列教程六--Gradle多渠道打包
转自:http://www.stormzhang.com/devtools/2015/01/15/android-studio-tutorial6/ Android Studio系列教程六--Grad ...
- Android Studio系列教程六--Gradle多渠道打包
Android Studio系列教程六--Gradle多渠道打包 2015 年 01 月 15 日 DevTools 本文为个人原创,欢迎转载,但请务必在明显位置注明出处!http://stormzh ...
- Laravel教程 六:表单 Forms
Laravel教程 六:表单 Forms 此文章为原创文章,未经同意,禁止转载. Form laravel 5.2 之后请使用 laravelcollective/html 替换 illuminate ...
随机推荐
- Jmeter函数助手11-BeanShell
BeanShell函数用于简单的计算或者运行编程脚本. 表达式求值:填入脚本代码或脚本文件${__BeanShell(source("test.bsh"))} 存储结果的变量名(可 ...
- 【MongoDB】Re05 分片集群(Win平台搭建)
分片副本集1 (3实例) 主1 从1 裁1 分片副本集2 (3实例) 主1 从1 裁1 配置副本集(3实例) 主1 从2 路由(2配置) 用Windows平台搭建 配置目录设置: ├─config ...
- 强化学习中的“sample efficiency”应该如何翻译 —— “样本效率”还是“采样效率”
问题: 强化学习中的"sample efficiency"应该如何翻译 -- "样本效率"还是"采样效率" 答案: 具体看上下文内容.如果是 ...
- MindSpore1.3.0 GPU pip方式安装 —— Ubuntu18.04系统 (最终安装结果为成功)需要管理员权限,sudo安装
官网地址: https://www.mindspore.cn/install =========================================================== 安 ...
- python代码实现将PDF文件转为文本及其对应的音频
代码地址: https://github.com/TiffinTech/python-pdf-audo ============================================ imp ...
- 简化数据流:Apache SeaTunnel实现多表同步的高效指南
Apache SeaTunnel除了单表之间的数据同步之外,也支持单表同步到多表,多表同步到单表,以及多表同步到多表,下面简单举例说明如何实现这些功能. 单表 to 单表 一个source,一个sin ...
- # Apache SeaTunnel 究竟是什么?
作者 | Shawn Gordon 翻译 | Debra Chen 原文链接 | What the Heck is Apache SeaTunnel? 我在2023年初开始注意到Apache SeaT ...
- StartImage.DLL使用说明
StartImage.DLL使用说明 一.库的引入 库包含以下物件,请按照要求将以下库映入到项目中 StartImage.dll StartImage.lib StartImage.h 二.注意事项 ...
- 关于Vue + element plus包装Component理解
关于Vue + element plus包装Component理解 一.关于编写思路 我以设计el-select选择框进行举例说明 父组件与Component传递params与Function使用Pr ...
- 2023上海理工大学校内选拔赛A-D题
前言 不要在意标题,既然是随记,就随性点() 今天参加了2023年中国高校计算机大赛-团队程序设计天梯赛(GPLT)上海理工大学校内选拔赛(同步赛)_ACM/NOI/CSP/CCPC/ICPC算法编程 ...