【问题标题】:What's the best way to inject a yaml file into an Argo workflow step?将 yaml 文件注入 Argo 工作流程步骤的最佳方法是什么?
【发布时间】:2020-03-19 12:03:31
【问题描述】:

总结:

我们有一个 golang 应用程序,可以根据请求将 Argo 工作流提交到 Kubernetes 集群。我想将一个 yaml 文件传递​​给其中一个步骤,我想知道这样做的选项是什么。

环境:

  • Argo:v2.4.2
  • K8s:1.13.12-gke.25

其他细节:

最终,我想将此文件传递给测试步骤,如下例所示:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: test-
spec:
  entrypoint: test
  templates:
  - name: test
    container:
      image: gcr.io/testproj/test:latest
      command: [bash]
      source: |
        python test.py --config_file_path=/path/to/config.yaml

此步骤中使用的图像将具有一个 python 脚本,该脚本接收该文件的路径然后访问它。

要使用 golang 提交 Argo 工作流,我们使用以下依赖项:

谢谢。

【问题讨论】:

  • 你要在哪一步通过yaml,可以分享一下工作流模板吗?
  • @Crou 谢谢你的评论。由于雇主的政策,我无法分享代码,但我将发布一个可能具有足够代表性的基本示例。

标签: go kubernetes argo-workflows argoproj


【解决方案1】:

选项1:将文件作为参数传递

Workflow parameters 通常是一小段文字或数字。但如果您的 yaml 文件相当小,您可以对其进行字符串编码并将其作为参数传递。

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: test-
spec:
  entrypoint: test
  arguments:
    parameters:
    - name: yaml
      value: "string-encoded yaml"
  templates:
  - name: test
    container:
      image: gcr.io/testproj/test:latest
      command: [bash]
      source: |
        # In this case, the string-encoding should be BASH-compatible.
        python test.py --config_file_as_string="{{inputs.parameters.message}}"

选项 2:将文件作为工件传递

Argo 支持多种类型的artifacts。对于您的用例来说,最简单的可能是 raw parameter 类型。

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: test-
spec:
  entrypoint: test
  templates:
  - name: test
    inputs:
      artifacts:
      - name: yaml
        path: /path/to/config.yaml
        raw:
          data: |
            this is
            the raw file
            contents
    container:
      image: gcr.io/testproj/test:latest
      command: [bash]
      source: |
        python test.py --config_file_path=/path/to/config.yaml

除了raw,Argo 还支持“S3、Artifactory、HTTP、[和] Git”工件(我认为还有其他)。

例如,如果您选择使用 S3,则可以从您的 golang 应用上传文件,然后将 S3 存储桶和密钥作为参数传递。

Golang 客户端

我对golang客户端不熟悉,但是传参数肯定是支持的,我觉得传入一个raw参数应该也是支持的。

【讨论】:

  • 感谢您的回复。我想我会选择参数选项。我们要传递的文件内容相对较小。
猜你喜欢
  • 2020-03-03
  • 1970-01-01
  • 2020-08-26
  • 2021-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-01
相关资源
最近更新 更多