如何在 argo 工作流中的地图中传递多行 json 字符串
how to pass a multi line json string in map in argo workflows
我正在为地图变量创建一个带有循环 withParam
的 argo 工作流。在此地图中,我想使用多行 json 字符串。有什么使用方法吗?
这是我使用 policy
作为多行字符串的方法,但它不起作用
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: loops-param-arg-
spec:
entrypoint: loop-param-arg-example
arguments:
parameters:
- name: os-list
value: |
[
{ "image": "debian", "tag": "9.1", "policy": "{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BucketAdmin",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "*"
}
]
}" },
{ "image": "ubuntu", "tag": "17.10", "policy": "{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BucketAdmin",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "*"
}
]
}"}
]
templates:
- name: loop-param-arg-example
inputs:
parameters:
- name: os-list
steps:
- - name: test-linux
template: cat-os-release
arguments:
parameters:
- name: image
value: "{{item.image}}"
- name: tag
value: "{{item.tag}}"
withParam: "{{inputs.parameters.os-list}}"
- name: cat-os-release
inputs:
parameters:
- name: image
- name: tag
container:
image: "{{inputs.parameters.image}}:{{inputs.parameters.tag}} and policy is {{inputs.parameters.policy}}"
command: [cat]
args: [/etc/os-release]
argo 工作流中有什么方法可以实现这一点吗?如果没有,还有什么替代方法可以做到这一点?
存在三个问题:
- 政策无效JSON。星号必须用引号引起来,因为它们是字符串。
{
"Sid": "BucketAdmin",
"Effect": "Allow",
- "Principal": *,
+ "Principal": "*",
"Action": "s3:*",
- "Resource": *
+ "Resource": "*"
}
- (UPDATE:此更改实际上不是必需的 - Argo Workflows 正确处理
policy
JSON 对象。)策略应编码为字符串,以便它们可以作为参数轻松传递。例如:
"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"BucketAdmin\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":\"*\"}]}"
- 策略值需要作为参数显式传递给 cat-os-release 模板。
最终的工作流程应该是这样的:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: loops-param-arg-
spec:
entrypoint: loop-param-arg-example
arguments:
parameters:
- name: os-list
value: |
[
{
"image": "debian",
"tag": "9.1",
"policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"BucketAdmin\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":\"*\"}]}"
},
{
"image": "ubuntu",
"tag": "17.10",
"policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"BucketAdmin\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":\"*\"}]}"
}
]
templates:
- name: loop-param-arg-example
inputs:
parameters:
- name: os-list
steps:
- - name: test-linux
template: cat-os-release
arguments:
parameters:
- name: image
value: "{{item.image}}"
- name: tag
value: "{{item.tag}}"
- name: policy
value: "{{item.policy}}"
withParam: "{{inputs.parameters.os-list}}"
- name: cat-os-release
inputs:
parameters:
- name: image
- name: tag
- name: policy
container:
image: "{{inputs.parameters.image}}:{{inputs.parameters.tag}}"
command: [echo]
args: ["{{inputs.parameters.policy}}"]
Michael 提供的解决方案有效,下面的解决方案也适用于您,并且政策具有一定的可读性
kind: Workflow
metadata:
generateName: loops-param-arg-
spec:
entrypoint: loop-param-arg-example
arguments:
parameters:
- name: os-list
value: |
[
{ "image": "debian", "tag": "9.1", "policy": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BucketAdmin",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "*"
}
]
} },
{ "image": "ubuntu", "tag": "17.10", "policy": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BucketAdmin",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "*"
}
]
}
}
]
templates:
- name: loop-param-arg-example
inputs:
parameters:
- name: os-list
steps:
- - name: test-linux
template: cat-os-release
arguments:
parameters:
- name: image
value: "{{item.image}}"
- name: tag
value: "{{item.tag}}"
withParam: "{{inputs.parameters.os-list}}"
- name: cat-os-release
inputs:
parameters:
- name: image
- name: tag
container:
image: "{{inputs.parameters.image}}:{{inputs.parameters.tag}} and policy is {{inputs.parameters.policy}}"
command: [cat]
args: [/etc/os-release]
我正在为地图变量创建一个带有循环 withParam
的 argo 工作流。在此地图中,我想使用多行 json 字符串。有什么使用方法吗?
这是我使用 policy
作为多行字符串的方法,但它不起作用
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: loops-param-arg-
spec:
entrypoint: loop-param-arg-example
arguments:
parameters:
- name: os-list
value: |
[
{ "image": "debian", "tag": "9.1", "policy": "{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BucketAdmin",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "*"
}
]
}" },
{ "image": "ubuntu", "tag": "17.10", "policy": "{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BucketAdmin",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "*"
}
]
}"}
]
templates:
- name: loop-param-arg-example
inputs:
parameters:
- name: os-list
steps:
- - name: test-linux
template: cat-os-release
arguments:
parameters:
- name: image
value: "{{item.image}}"
- name: tag
value: "{{item.tag}}"
withParam: "{{inputs.parameters.os-list}}"
- name: cat-os-release
inputs:
parameters:
- name: image
- name: tag
container:
image: "{{inputs.parameters.image}}:{{inputs.parameters.tag}} and policy is {{inputs.parameters.policy}}"
command: [cat]
args: [/etc/os-release]
argo 工作流中有什么方法可以实现这一点吗?如果没有,还有什么替代方法可以做到这一点?
存在三个问题:
- 政策无效JSON。星号必须用引号引起来,因为它们是字符串。
{ "Sid": "BucketAdmin", "Effect": "Allow", - "Principal": *, + "Principal": "*", "Action": "s3:*", - "Resource": * + "Resource": "*" }
- (UPDATE:此更改实际上不是必需的 - Argo Workflows 正确处理
policy
JSON 对象。)策略应编码为字符串,以便它们可以作为参数轻松传递。例如:"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"BucketAdmin\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":\"*\"}]}"
- 策略值需要作为参数显式传递给 cat-os-release 模板。
最终的工作流程应该是这样的:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: loops-param-arg-
spec:
entrypoint: loop-param-arg-example
arguments:
parameters:
- name: os-list
value: |
[
{
"image": "debian",
"tag": "9.1",
"policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"BucketAdmin\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":\"*\"}]}"
},
{
"image": "ubuntu",
"tag": "17.10",
"policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"BucketAdmin\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":\"*\"}]}"
}
]
templates:
- name: loop-param-arg-example
inputs:
parameters:
- name: os-list
steps:
- - name: test-linux
template: cat-os-release
arguments:
parameters:
- name: image
value: "{{item.image}}"
- name: tag
value: "{{item.tag}}"
- name: policy
value: "{{item.policy}}"
withParam: "{{inputs.parameters.os-list}}"
- name: cat-os-release
inputs:
parameters:
- name: image
- name: tag
- name: policy
container:
image: "{{inputs.parameters.image}}:{{inputs.parameters.tag}}"
command: [echo]
args: ["{{inputs.parameters.policy}}"]
Michael 提供的解决方案有效,下面的解决方案也适用于您,并且政策具有一定的可读性
kind: Workflow
metadata:
generateName: loops-param-arg-
spec:
entrypoint: loop-param-arg-example
arguments:
parameters:
- name: os-list
value: |
[
{ "image": "debian", "tag": "9.1", "policy": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BucketAdmin",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "*"
}
]
} },
{ "image": "ubuntu", "tag": "17.10", "policy": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BucketAdmin",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "*"
}
]
}
}
]
templates:
- name: loop-param-arg-example
inputs:
parameters:
- name: os-list
steps:
- - name: test-linux
template: cat-os-release
arguments:
parameters:
- name: image
value: "{{item.image}}"
- name: tag
value: "{{item.tag}}"
withParam: "{{inputs.parameters.os-list}}"
- name: cat-os-release
inputs:
parameters:
- name: image
- name: tag
container:
image: "{{inputs.parameters.image}}:{{inputs.parameters.tag}} and policy is {{inputs.parameters.policy}}"
command: [cat]
args: [/etc/os-release]