As a followup question to my post Helm function to set value based on a variable?, and modifying the answer given in Dynamically accessing values depending on variable values in a Helm chart, I'm trying this
$ 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) }}
But I get
$ 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
Why is pluck
returning a float64
instead of an integer, which I expect since my environments
dictionary values are integers?
If I do this, that is, pipe pluck
with the int
converter, it works, but it doesn't explain why pluck
returns a float64
value.
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) }}
UPDATE: It turns out to be a known bug. See https://github.com/kubernetes-sigs/yaml/issues/45