如何为 yaml 块创建 helm 模板?

问题描述 投票:0回答:1

我正在尝试创建一个 Helm Chart,它将在 K8s 集群上部署 SecretProviderClass。我在尝试模板化以下部分时面临的问题:

objects:  |
  array:
    - |
      objectName: secret1
      objectType: secret
    - |
      objectName: secret2
      objectType: secret

我的价值文件:

vault:
  secrets:
.   array:
      - |
        objectName: secret1
        objectType: secret
      - |
        objectName: secret2
        objectType: secret

在我的头盔模板中:

objects:  |
  array:
    {{ .Values.vault.secrets.array | toJson | nindent 6 }}
Error: at <.Values.vault.secrets.array>: nil pointer evaluating interface {}.array

我该如何解决这个问题?有人可以帮忙吗?

kubernetes-helm
1个回答
0
投票

我尝试重新创建您的场景,在复制/粘贴过程中我注意到您的值由于“.”而无效。在vault.secrets.array之前

vault:
  secrets:
# Notice the invalid "." which prevents .array from beeing accessed
==> . <==   array:
      - |
        objectName: secret1
        objectType: secret
      - |
        objectName: secret2
        objectType: secret

当我删除“.”时从您的值文件示例中获取并使用您提供的代码片段渲染 helm 模板,它可以工作。

values.yaml:

---
vault:
  secrets:
    array:
      - |
        objectName: secret1
        objectType: secret
      - |
        objectName: secret2
        objectType: secret

模板:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: cm
data:
  objects: |
    array:
      {{ .Values.vault.secrets.array | toJson | nindent 6 }}

helm 模板结果:

helm template <chartName>/
---
# Source: <chartName>/templates/cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: myapp
data:
  objects: |
    array:
      
      ["objectName: secret1\nobjectType: secret\n","objectName: secret2\nobjectType: secret\n"]
© www.soinside.com 2019 - 2024. All rights reserved.