首页 文章

图表模板中的嵌套循环

提问于
浏览
1

我在为Helm Chart渲染模板时遇到问题,Helm Chart需要具有易于扩展的节点和副本数量 . 我收到以下错误消息 . 奇怪的是,如果我删除内部循环不嵌套循环,我不会得到以下错误消息 . 我完全不知道了,但这似乎有效 . 我不知所措 .

错误:

$ helm install . --dry-run --debug
Error: render error in "app-on-k8s/templates/configmap_configd.yaml": template: app-on-k8s/templates/configmap_configd.yaml:18:77: executing "app-on-k8s/templates/configmap_configd.yaml" at <.Values.nodeCount>: can't evaluate field Values in type int

这是我的values.yaml文件中的相关部分:

# number of nodes / shards
nodeCount: 5
replicaCount: 3

以及我的模板文件中的相关部分:

<default>
        {{range $i, $e := until (atoi (printf "%d" (int64 .Values.nodeCount))) }}
                <node>
                {{range $j, $k := until (atoi (printf "%d" (int64 .Values.replicaCount))) }}   #line 18
                    <replica>
                        <host>{{ $.Release.Name }}-{{$j}}</host>
                        <port>{{ $.Values.service.rpc_port }}</port>
                    </replica>
                {{end}}    
                </node>
        {{end}}
    </default>

1 回答

  • 4

    问题是,当您在第二个循环中使用 .Values.replicaCount 时, . 范围已更改,现在指向 .Values.nodeCount . 所以 .Values.replicaCount 现在指向 .Values.nodeCount.Values.replicaCount . 因为,在values.yaml文件中没有这样的字段,您收到此错误 .

    在第二个循环中使用 $.Values.replicaCount 而不是 .Values.replicaCount .

    参考:helm.sh

相关问题