首页 > 解决方案 > 在我的 Helm 模板中,为什么 pluck 评估为 float64?

问题描述

作为我帖子Helm 函数的后续问题,基于变量设置值?,并根据 Helm 图表中的变量值修改动态访问值中给出的答案,我正在尝试这个

$ helm version --short
v3.5.2+g167aac7

values.yaml
-----------
env: sandbox
environments:
  sandbox: 0
  staging: 1
  production: 2
replicaCount:
  - 1
  - 2
  - 4

templates/deployments.yaml
--------------------------
apiVersion: apps/v1
kind: Deployment
metadata:
...
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ index .Values.replicaCount (pluck .Values.env .Values.environments | first | default .Values.environments.sandbox) }}

但我明白了

$ helm template . --dry-run
Error: template: guestbook/templates/deployment.yaml:10:15: executing "guestbook/templates/deployment.yaml" at <index .Values.replicaCount (pluck .Values.env .Values.environments | first | default .Values.environments.sandbox)>: error calling index: cannot index slice/array with type float64

为什么pluck返回 afloat64而不是整数,因为我的environments字典值是整数,所以我期望它?

标签: kuberneteskubernetes-helm

解决方案


如果我这样做,即pluck使用int转换器进行管道传输,它可以工作,但它没有解释为什么pluck返回一个float64值。

templates/deployments.yaml
--------------------------
apiVersion: apps/v1
kind: Deployment
metadata:
...
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ index .Values.replicaCount ((pluck .Values.env .Values.environments | first | default .Values.environments.sandbox) | int) }}

更新:事实证明这是一个已知的错误。见https://github.com/kubernetes-sigs/yaml/issues/45


推荐阅读