无法从掌舵子图中找到全球价值

时间:2020-07-06 20:36:16

标签: templates kubernetes-helm

这是我第一次使用嵌套的Helm图表,并且试图从根values.yaml文件访问全局值。 According to the documentation我应该可以在secret.yaml文件中使用以下语法,但是如果运行helm template api --debug,则会出现以下错误:

错误:模板:api / templates / secret.yaml:7:21:在<.Values.global.sa_json>处执行“ api / templates / secret.yaml”:无指针评估接口{} .sa_json helm.go:84:[调试]模板:api / templates / secret.yaml:7:21:在<.Values.global.sa_json>处执行“ api / templates / secret.yaml”:无指针评估接口{}。 sa_json

/primaryChart/charts/api/templates/secret.yaml

apiVersion: v1
kind: Secret
metadata:
  name: {{ .Chart.Name }}-service-account-secret
type: Opaque
data:
  sa_json: {{ .Values.global.sa_json }}

primaryChart / values.yaml

global:
  sa_json: _b64_sa_credentials

文件夹结构如下:

/primaryChart 
|- values.yaml 
|-- /charts
    |-- /api
       |-- /templates
           |- secret.yaml

1 个答案:

答案 0 :(得分:1)

具有以下目录布局,.Values.global.sa_json仅在您从主图表调用helm template api .时可用

/mnt/c/home/primaryChart> tree
.
├── Chart.yaml  <-- your main chart
├── charts
│   └── api
│       ├── Chart.yaml  <-- your subchart
│       ├── charts
│       ├── templates
│       │   └── secrets.yaml
│       └── values.yaml
├── templates
└── values.yaml   <--- this is where your global.sa_json is defined

您的values file应该被称为values.yaml,而不是value.yaml,或者使用带有-f标志helm template api . -f value.yaml

的任何其他文件

/mnt/c/home/primaryChart> helm template api .
---
# Source: primaryChart/charts/api/templates/secrets.yaml
apiVersion: v1
kind: Secret
metadata:
  name: api-service-account-secret
type: Opaque
data:
  sa_json: _b64_sa_credentials
相关问题