Helm Index 不使用默认值

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

下面是我正在使用的代码。我想使用productName从productNameReplicas获取值

  replicas: {{ index .Values.productNameReplicas .Values.productName | default 1 }}

这是我的价值观文件

productNameReplicas:
  carAi: 3
  langAI: 3

问题是,如果productName不在productNameReplicas中,它不仅仅使用默认值并给我错误:

 error calling index: index of untyped nil

有什么想法可以让这样的事情发挥作用吗?

kubernetes-helm
1个回答
0
投票

你会得到

error calling index: index of untyped nil

当值中不存在productNameReplicas时。

如果 ProductNameReplicas 存在于 Values 中,但 ProductName 不存在,那么您会得到:

error calling index: value is nil; should be of type string

为了解决这个问题,我将为productName 添加一个默认值。将我的values.yaml 设置为:

productName: ""

productNameReplicas:
  carAi: 3
  langAI: 3
© www.soinside.com 2019 - 2024. All rights reserved.