在自定义位置使用的 Helm 变量

Helm variables used at custom places

我无法在 Helm 的嵌套变量中引用变量。另外,我无法将其作为嵌套参考来执行。我想使用 client_name 变量的值检索客户端名称下的所有客户端变量。我该怎么做?

Values.yaml

clients:
  client1:
    incomigBucket: databucket
    outgoingBucket: tempbucket
    webURL: http://example.com
  client2: 
     incomingBucket: databucket
    outgoingBucket: tempbucket
    webURL: http://example.com

我想将客户端变量值存储在一个变量中,并想在我的 Json 文件中的不同位置使用它。如果我使用范围函数,那么它会创建两次部分(正如我提到的 2 个客户),Helm 中是否有任何我可以使用的东西可以动态存储这些变量并在 json 文件中的自定义位置使用它?

示例文件部分:

 "FileConfig": {
         "Client1": {
           "incomingLocationPath": "s3://{{ .Values.clients.client1.incomingBucket }}/dir1/dir2",
           "outgoingLocationPath": "s3://{{ .Values.clients.client1.outgoingBucket }}/dir1/dir2",
         },
         "Client2": {
           "incomingLocationPath": "s3://{{ .Values.clients.client2.incomingBucket }}/dir1/dir2",
           "outgoingLocationPath": "s3://{{ .Values.clients.client2.outgoingBucket }}/dir1/dir2",
         }
      }

我不完全确定您打算在哪里使用此代码段。我假设它在 configMap 内。至少,我不知道有任何资源有 FileConfig 部分。我也不知道为什么它应该是 JSON。

基本模式可能如下所示。

fileConfig:
  {{- range $client, $config := .Values.clients }}
  {{ $client }}:
    incomingLocationPath: "s3://{{ $config.incomingBucket }}/dir1/dir2"
    outgoingLocationPath: "s3://{{ $config.outgoingBucket }}/dir1/dir2"
  {{- end }}

在类似于 configMap 的东西中创建 JSON 它可能看起来像这样。

kind: ConfigMap
apiVersion: v1
metadata:
  name: file-config-json
data:
  config.json: |
    "fileConfig": {
      {{- range $client, $config := .Values.clients }}
      "{{ $client }}": {
        "incomingLocationPath": "s3://{{ $config.incomingBucket }}/dir1/dir2",
        "outgoingLocationPath": "s3://{{ $config.outgoingBucket }}/dir1/dir2"
      }
      {{- end }}
    }