You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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资源:

  1. 修改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 }}
    
  2. 对应的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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 01:36:00