我知道,字典是按顺序处理的。但是,为了某种进程目的,我需要以某种顺序运行特定的进程。(由于本机k8s不按顺序支持cron作业,所以我是在单荚的入口点这样做的)。下面是我的values.yaml
batches:
evaluate_events:
ev-cron-3:
populate_data:
event-name: "Populate Data process"
business-process: "Generic"
rule-type: "Identification"
auth_export:
event-name: "Auth Export Ruleset"
business-process: "Generic"
rule-type: "Constraint Satisfaction"
new_document_attached:
event-name: "New Document Attached"
business-process: "Generic"
rule-type: "Constraint Satisfaction"我的代码inv k8s yaml:
{{- range $event, $data := $.Values.batches }}
{{- range $key, $cron := $data }
{{- range $jobname, $inputs := $cron }}
- '{{ $event }} {{- range $args, $val := $inputs }} --{{ $args }} "{{ $val }}" {{- end }}'
{{- end }}
{{- end }}
{{- end }}预期输出:与values.yaml相同的顺序
- 'evaluate_events --business-process "Generic" --event-name "Populate Data process" --rule-type "Identification"'
- 'evaluate_events --business-process "Generic" --event-name "Auth Export Ruleset" --rule-type "Constraint Satisfaction"'
- 'evaluate_events --business-process "Generic" --event-name "New Document Attached" --rule-type "Constraint Satisfaction"'实际输出:不按values.yaml的顺序排列
- 'evaluate_events --business-process "Generic" --event-name "Auth Export Ruleset" --rule-type "Constraint Satisfaction"'
- 'evaluate_events --business-process "Generic" --event-name "New Document Attached" --rule-type "Constraint Satisfaction"'
- 'evaluate_events --business-process "Generic" --event-name "Populate Data process" --rule-type "Identification"'需要吗,如果有人处理这种情况的话?如何才能做到这一点呢?
发布于 2022-01-22 00:12:02
在values.yaml中使用YAML映射对象。它由一对键和值组成,但不一定按任何顺序排列。您可能需要一个YAML列表,而不是:
- arg: event-name
value: Populate Data process
- arg: business-process
value: Generic
- arg: rule-type
value: Identification然后可以使用range迭代列表(而不是映射)。
- '{{ $event }}
{{- range $inputs }} --{{ .arg }} "{{ .value }}"{{- end -}}
'Kubernetes中的几个地方都有包含name字段的列表,这正是出于这个原因,您也可以考虑在您的值结构中更高地使用这种方法。如果您控制应用程序本身,您可能还会发现将这些设置作为环境变量而不是命令行参数传递比较容易,因为如您所示,构造命令字符串在语法上可能有点棘手。
https://stackoverflow.com/questions/70805550
复制相似问题