在 helm 中合并两个值文件

kar*_*ick 1 yaml kubernetes-helm

我希望在 helm 中合并两个值文件。

秘密.yaml:

    serviceMonitor:
       endpoints:
         - module: oracledb
           port: http
           scheme: http
           url: "http://user:password@ip:port/xxx" 
Run Code Online (Sandbox Code Playgroud)

我有另一个 values.yaml 文件,它有多个端点。我想合并两个值文件。我尝试使用 append 函数来做到这一点:{{$endpoints := (append .Values.serviceMonitor.endpoints .Values.oracle_db.serviceMonitor.endpoints) }}当我进行试运行时,我看到它同时获取了两个值但不会合并。有人遇到过这个吗?

Laz*_*ass 5

在当前的 Helm 版本 (3) 中,不支持合并值。

这个特性在这个 Github 问题中讨论过:Helm should preform deep merge on multiple values files

来自那里的一个重要报价

如果实现,它应该是可选的,即合并模式应该指定为命令行标志。其他任何事情都将是一个突破性的变化,我认为在大多数情况下都是不可取的。问题是您将无法覆盖列表的默认值。

参见:https : //github.com/helm/helm/issues/3486#issuecomment-364534501


小智 4

您可以使用 python 脚本在传递值文件之前合并它们。下面是我正在使用的代码片段。

\n
import yaml\nfrom deepmerge import always_merger\n\nfileA = \xe2\x80\x9ctmp.yaml"\nfileB = \xe2\x80\x9cfeature.yaml"\n\nwith open(fileA,\'r+\') as f:\n   fileAdictionary= yaml.load(f)\n\nwith open(fileB,\'r+\') as f:\n   fileBdictionary = yaml.load(f)\n\nresult = always_merger.merge(fileAdictionary, fileBdictionary)\nwith open(\xe2\x80\x98newFile.yaml\xe2\x80\x99,\'w+\') as f:\n   yaml.dump(result,f)\n
Run Code Online (Sandbox Code Playgroud)\n