1

我正在探索一种在 Argo 工作流程中读取 K8S 资源的简单方法。当前的文档主要关注创建/修补条件(https://argoproj.github.io/argo/examples/#kubernetes-resources),而我很好奇是否可以执行“action:get”,额外资源状态(或完整资源)的一部分并将其作为工件或结果输出传递到下游。有任何想法吗?

4

1 回答 1

2

action: get不是 Argo 提供的功能。

但是,它很容易kubectl在 Pod 中使用,然后将 JSON 输出发送到输出参数。这使用 BASH 脚本将 JSON 发送到result输出参数,但显式输出参数或输出工件也是可行的选项。

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: kubectl-bash-
spec:
  entrypoint: kubectl-example
  templates:
  - name: kubectl-example
    steps:
    - - name: generate
        template: get-workflows
    - - name: print
        template: print-message
        arguments:
          parameters:
          - name: message
            value: "{{steps.generate.outputs.result}}"
  - name: get-workflows
    script:
      image: bitnami/kubectl:latest
      command: [bash]
      source: |
        some_workflow=$(kubectl get workflows -n argo | sed -n 2p | awk '{print $1;}')
        kubectl get workflow "$some_workflow" -ojson
  - name: print-message
    inputs:
      parameters:
      - name: message
    container:
      image: alpine:latest
      command: [sh, -c]
      args: ["echo result was: '{{inputs.parameters.message}}'"]

请记住,kubectl它将使用工作流的 ServiceAccount 的权限运行。请务必使用有权访问您想要获取的资源的 ServiceAccount 提交工作流。

于 2020-11-23T14:35:25.643 回答