2

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?

Chris F
  • 14,337
  • 30
  • 94
  • 192

1 Answers1

2

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

Chris F
  • 14,337
  • 30
  • 94
  • 192
  • You are missing a close parentheses. Are you showing all the code that produces the result? – erk Feb 15 '21 at 01:05
  • @erk I copy/pasted code that actually ran for me. i don't see the missing `()`. I see 2 opening `(` and 2 closing `)`? The inner `()` for the `pluck` command itself, and the outer `()` to pipe the whole `(pluck)` command with `int`? So it's `{{ index .Values.replicaCount ((pluck ...) | int) }}`? – Chris F Feb 15 '21 at 15:15