ArgoWorkflow教程(六)---无缝实现步骤间参数传递

news/2024/10/10 13:34:37

argoworkflow-6-parameter-passing-between-steps.png

之前我们分析了,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-parametertemplates:- name: output-parametersteps:- - name: generate-parametertemplate: whalesay- - name: consume-parametertemplate: print-messagearguments:parameters:# Pass the hello-param output from the generate-parameter step as the message input to print-message- name: messagevalue: "{{steps.generate-parameter.outputs.parameters.hello-param}}"- name: whalesaycontainer:image: docker/whalesay:latestcommand: [sh, -c]args: ["echo -n hello world > /tmp/hello_world.txt"]  # generate the content of hello_world.txtoutputs:parameters:- name: hello-param  # name of output parametervalueFrom:path: /tmp/hello_world.txt # set the value of hello-param to the contents of this hello-world.txt- name: print-messageinputs:parameters:- name: messagecontainer:image: docker/whalesay:latestcommand: [cowsay]args: ["{{inputs.parameters.message}}"]

导出结果

- name: whalesaycontainer:image: docker/whalesay:latestcommand: [sh, -c]args: ["echo -n hello world > /tmp/hello_world.txt"]  # generate the content of hello_world.txtoutputs:parameters:- name: hello-param  # name of output parametervalueFrom: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 parametervalueFrom: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-messageinputs:parameters:- name: messagecontainer:image: docker/whalesay:latestcommand: [cowsay]args: ["{{inputs.parameters.message}}"]

唯一区别在于,这个参数的来源,之前我们都是直接讲参数定义在 Workflow 中的,这里需要改成引用之前步骤导出的 Output Parameter,就像这样:

spec:entrypoint: output-parametertemplates:- name: output-parametersteps:- - name: generate-parametertemplate: whalesay- - name: consume-parametertemplate: print-messagearguments:parameters:# Pass the hello-param output from the generate-parameter step as the message input to print-message- name: messagevalue: "{{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 ,可以用于获取容器中的标准输出。

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

OOOPS:零样本实现360度开放全景分割,已开源 | ECCV24

全景图像捕捉360的视场(FoV),包含了对场景理解至关重要的全向空间信息。然而,获取足够的训练用密集标注全景图不仅成本高昂,而且在封闭词汇设置下训练模型时也受到应用限制。为了解决这个问题,论文定义了一个新任务,称为开放全景分割(Open Panoramic Segmentation,OPS…

如何将React项目,部署到Web服务器的Tomcat 上

将 React 应用部署到 Tomcat 服务器上通常需要将其构建为静态文件,然后将这些文件放入 Tomcat 的 webapps 目录。以下是具体步骤: 步骤指南 1. 构建 React 应用 首先,你需要在本地构建你的 React 应用。npm run build这会在项目根目录下生成一个 build 文件夹,里面包含了优…

实时显示和拍照存储,IFD-x让你实时掌握温度信息 非接触式热成像仪器红外线成像

实时显示和拍照存储,IFD-x让你实时掌握温度信息 非接触式热成像仪器红外线成像非接触式热成像仪器,IFD-x采用红外阵列高精度温度传感器和先进的软件算法。它能够对视场范围内的任何物体进行红外成像,成像分辨率达到512*384像素,温度灵敏度为0.1℃,绝对精度为1.5℃,刷新频…

USB 鼠标的实现

目录前言5 USB 标准请求5.1 USB 标准设备请求的结构5.2 GET_DESCRIPTOR 请求5.3 SET_ADDRESS 请求5.4 SET_CONFIGURATION 请求6 设备描述符的实现9 配置描述符集合的结构9.1 配置描述符结构9.2 接口描述符的结构9.3 端点描述符的结构9.4 HID 描述符的结构9.5 [示例:描述符]11 …

USB 概述及协议基础

《圈圈教你学 USB》第 1 章学习笔记1 USB 是什么?1)USB(Universal Serial Bus,通用串行总线)2 USB 的特点1)USB 协议版本与速度:来源:https://www.usbzh.com/article/detail-199.html2)开发 USB 常用网站: https://www.usb.org3 USB 的拓扑结构USB 是主从结构,主机为…

AI云平台介绍

AI云平台是基于云计算基础设施,集成机器学习、深度学习、自然语言处理、计算机视觉等先进AI技术,通过云端服务的形式,向用户提供数据预处理、模型训练、模型部署、预测推理等一系列AI开发与应用服务的平台。AI云平台是基于云计算基础设施,集成机器学习、深度学习、自然语言…

无人直播自动化回复客户咨询

我们插件是根据页面元素变动进行自动化操作的,想要实现网页版自动化,必须了解html以及dom结构,还有xpath定位方法。 各大直播后台页面结构不一样,所以要进行兼容处理,我们一个插件支持以下直播或客服平台 唯一客服浏览器插件 十年开发经验程序员,离职全心创业中,历时三年…

【日记】生巧好好吃!(701 字)

正文今天才发现昨天寒露。不过昨天很冷,今天倒挺暖和,太阳很好。下午上班,觉得这么好的太阳不做点什么很亏,于是转身回去拿了被子。晚上下班去收,被子上面落的全是桂花。那时候天色已暗,天边有一种低沉但通透的蓝。一般这种时候温度都很低了。秋天真的到了啊……主管买的…