kubernetes - 使用 "resource"模板/步骤和 "get"操作提取 Argo 工作流程中的资源并传递到下游步骤?

标签 kubernetes argo-workflows

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

最佳答案

更新:

现在支持

action: get:https://github.com/argoproj/argo-workflows/blob/246d4f44013b545e963106a9c43e9cee397c55f7/examples/k8s-wait-wf.yaml#L46

原始答案:

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

但是,可以轻松地在 Pod 中使用 kubectl,然后将 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" -n argo -ojson
  - name: print-message
    inputs:
      parameters:
      - name: message
    container:
      image: alpine:latest
      command: [sh, -c]
      args: ["echo result was: '{{inputs.parameters.message}}'"]

请记住,kubectl 将使用工作流的 ServiceAccount 的权限运行。请务必submit the Workflow using a ServiceAccount它可以访问您想要获取的资源。

关于kubernetes - 使用 "resource"模板/步骤和 "get"操作提取 Argo 工作流程中的资源并传递到下游步骤?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64969070/

相关文章:

kubernetes - 在 Kubernetes 中禁用 cronjob

azure - Argo 工作流程中的卷节点关联性冲突

kubernetes - 如何从另一个现有的Pod创建一个新的Kubernetes Pod?

jenkins - Kubernetes Jenkins 插件 - slaves 总是离线

kubernetes - Terraform 污点资源命名约定 (v0.11.13)

kubernetes - helm chart yaml 模板中是否有任何子字符串函数?

java - 如何通过提交适当的 .YAML 文件以编程方式调用 Argo

synchronization - 如果 Argo Workflow 已经在运行,如何防止重新提交?

kubernetes - Argo Workflow 未将输入参数传递给 WorkflowTemplate

ssl - 有没有办法将配置传递给 Nginx Ingress Controller