【问题标题】:Helm variables used at custom places在自定义位置使用的 Helm 变量
【发布时间】:2021-09-14 11:19:59
【问题描述】:

我无法在 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 文件中的不同位置使用它。如果我使用 range 函数,那么它会创建两次部分(正如我提到的 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",
         }
      }

【问题讨论】:

    标签: kubernetes kubernetes-helm


    【解决方案1】:

    我不完全确定你打算在哪里使用这个 sn-p。我假设它在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 }}
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-03
      • 2020-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-11
      相关资源
      最近更新 更多