我们正在使用 Airflow 社区舵图,我正在尝试根据团队列表动态创建池,以便我可以在不同的设置中重复使用该团队列表。
请注意,这些设置位于同一个values.yaml 文件中,但也许有一种更合适的方法来实现这一点,但我不知道。
values.yaml:
teams:
- name: team1
pool_slots: 4
- name: team2
pool_slots: 5
airflow:
...
pools:
# This part I want to create dynamically based on the list above
- name: pool-team1
slots: 4
- name: pool-team2
slots: 5
...
我尝试了以下选项并运行了
helm template .. --values values.yaml
命令,这给出了以下错误:
Option 1
错误:“范围无法迭代 {{- range $teams := .Values.teams }}”
teams:
- name: team1
pool_slots: 4
- name: team2
pool_slots: 5
airflow:
...
pools:
{{- range $team := .Values.teams}}
- name: pool-{{ $team.name }}
slots: {{ $team.pool_slots}}
{{- end }}
...
Option 2
错误:“范围无法迭代 {{- range .Values.teams}}”
teams:
- name: team1
pool_slots: 4
- name: team2
pool_slots: 5
airflow:
...
pools:
{{- range .Values.teams}}
- name: pool-{{ $teams.name }}
slots: {{ $teams.pool_slots}}
{{- end }}
...
Option 3
错误:“将 YAML 转换为 JSON 时出错:yaml:第 17 行:找不到预期的 ':'”
teams:
- name: team1
pool_slots: 4
- name: team2
pool_slots: 5
{{- $ := . -}}
{{- range $team := .Values.teams}}
airflow:
...
pools:
- name: pool-{{ $team.name }}
slots: {{ $team.pool_slots}}
...
{{- end }}