如何在Helm中向Argo CD Application字典内的列表追加另一个列表?
实现Argo CD Application中helm.valueFiles列表的追加
要将外部values.yaml中的helm.valueFiles列表追加到Argo CD Application资源的helm.valueFiles列表中,不能直接用merge函数(因为merge对列表是替换而非追加),需要使用Helm的append函数来拼接两个列表。
解决方案步骤
假设你通过Helm Chart管理Argo CD Application资源:
修改Application模板文件
在定义spec.source.helm.valueFiles的位置,用append函数合并基础列表和待追加列表:apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: guestbook namespace: argocd finalizers: - resources-finalizer.argocd.argoproj.io labels: name: guestbook spec: project: default source: repoURL: https://github.com/argoproj/argocd-example-apps.git targetRevision: HEAD path: guestbook chart: chart-name helm: passCredentials: false parameters: - name: "nginx-ingress.controller.service.annotations.external-dns\.alpha\.kubernetes\.io/hostname" value: mydomain.example.com - name: "ingress.annotations.kubernetes\.io/tls-acme" value: "true" forceString: true fileParameters: - name: config path: files/config.json releaseName: guestbook valueFiles: {{ append .Values.spec.source.helm.valueFiles .Values.helm.valueFiles | toYaml | nindent 10 }}对应的values.yaml配置
保持你原有的values.yaml结构:helm: valueFiles: - myvalues1.yaml - myvalues2.yaml spec: source: helm: valueFiles: - values-prod.yaml
原理说明
- Helm的
append函数会将第二个列表的元素追加到第一个列表末尾,生成合并后的新列表。 toYaml将合并后的列表转为YAML格式,nindent 10保证缩进与Application资源的层级结构匹配(可根据实际模板调整缩进数值)。
内容的提问来源于stack exchange,提问作者Shuzheng
相关产品推荐
相关产品推荐

