我的 Argo 工作流程有一个模板,可生成以下配置图:
{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": { "name": "configmap" },
"data":
{
"ELASTIC_SEARCH_URL": "https://staging-aaa.domain.com",
"EXTENSION_PATH": "/dist",
"GRAPHQL_GATEWAY_URL": "https://graphql-gateway.stg.domain.com/graphql",
"bucket_url": "stg-bucket/fie/to/path",
},
}
我在我的其他模板之一中使用此值,如下所示:
...
envFrom:
- configMapRef:
name: "{{inputs.parameters.configmap}}"
我还想通过在该输出中获取
bucket_url
来获得“二合一”,因此我创建了此模板来测试我是否能够打印我想要的内容(我不能在原始输出,所以我在 withParam
周围添加了 []
):{{steps.create-configmap.outputs.parameters.configmap}}
此模板的输出正是配置映射本身:
- - name: print-with-loop
template: print-with-loop-tmpl
arguments:
parameters:
- name: data
value: "{{item}}"
withParam: "[{{steps.create-configmap.outputs.parameters.configmap}}]"
我还可以在该配置映射中打印
{apiVersion:v1,data:{ELASTIC_SEARCH_URL:https://staging-aaa.domain.com,EXTENSION_PATH:/dist,GRAPHQL_GATEWAY_URL:https://graphql.stg.domain.com/graphql,bucket_url:stg-bucket/fie/to/path},kind:ConfigMap,metadata:{name:env-configmap}}
:
item.data
但是我无法访问
{ELASTIC_SEARCH_URL:https://staging-aaa.domain.com,EXTENSION_PATH:/dist,GRAPHQL_GATEWAY_URL:https://graphql.stg.domain.com/graphql,bucket_name:stg-bucket,ext_path:extension/stable/dist-raw.tar.gz,bucket_url:stg-bucket/extension/stable/dist-raw.tar.gz}
内的任何数据。如果我使用
item.data
或 item.data.bucket_url
,它不起作用,并且我会从 Argo 收到错误。我尝试使用 sprig 操作输出,但我无法找到解决方案。基本上我正在尝试获取 item.data['bucket_url']
以便在此工作流程中的另一个模板中使用。
bucket_url
也许使用
with open("/tmp/configmap.json", "w") as file:
json.dump(configmap, file)
会对我有所帮助?我没有看到它,但我提供此信息以防万一。
dumps
:
withParam
由于我正在打印生成 ConfigMap 的脚本中所做的
- - name: print-with-loop
template: print-with-loop-tmpl
arguments:
parameters:
- name: data
value: "{{item.bucket_url}}"
withParam: "{{steps.create-configmap.outputs.result}}"
,因此我可以轻松访问
json.dump
。上面模板的输出正是我所需要的。