如何在argo工作流的单个循环中传递多个列表



我想使用argo模板在单个循环中传递多个列表的元素

我有如下3个列表

effect = ["Allow", "Allow", "Allow"]
resource = ["*", "*", "*"]
action = ["ec2:CreateTags", "ec2:DescribeInstances", "ec2:AuthorizeSecurityGroupIngress"]

我有一个IAM策略,我需要用argo模板构建。下面的IAM策略在每个循环中从3个列表中获取元素。我们如何在一个循环中传递这三个list元素?

我参考了argo文档,只有withItems/withParams循环可用,它一次只接受一个列表

我尝试了下面的方法,但是,它不工作

- name: policy
value: |-
<<-EOP
{
"Effect": "{{item.1}}",
"Action": "{{item.2}}",
"Resource": "{{item.3}}"
}
EOP
withTogether:
- "{{inputs.parameters.effect}}"
- "{{inputs.parameters.actions}}"
- "{{inputs.parameters.resources}}"

如果在argo中不支持,是否有其他方法可以实现这一点?

不要使用withItems/withParams进行简单的JSON操作。Argo工作流用至少一个Pod表示这些循环的每次迭代。这是缓慢。

我建议使用一种熟悉的编程语言和一个脚本模板来完成这项工作。

Argo有一个简单的内置"表达式标签"模板工具,您可以使用它来执行相同的突变。

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: so-69180308-
spec:
arguments:
parameters:
- name: effects
value: '["Allow", "Allow", "Allow"]'
- name: resources
value: '["*", "*", "*"]'
- name: actions
value: '["ec2:CreateTags", "ec2:DescribeInstances", "ec2:AuthorizeSecurityGroupIngress"]'
entrypoint: main
templates:
- name: main
script:
env:
- name: POLICIES
value: >-
{{=
toJson(
map(
0..(len(jsonpath(workflow.parameters['effects'], '$'))-1),
{
{
effect: jsonpath(workflow.parameters['effects'], '$')[#],
resource: jsonpath(workflow.parameters['resources'], '$')[#],
action: jsonpath(workflow.parameters['actions'], '$')[#]
}
}
)
)
}}
image: debian:9.4
command: [bash]
source: |
echo "$POLICIES"

输出:

[{"action":"ec2:CreateTags","effect":"Allow","resource":"*"},{"action":"ec2:DescribeInstances","effect":"Allow","resource":"*"},{"action":"ec2:AuthorizeSecurityGroupIngress","effect":"Allow","resource":"*"}]

我不建议使用表达式标记。它是一种不太为人所知的语言,对其他人来说维护起来会更加困难。

最新更新