helm / helm

The Kubernetes Package Manager
https://helm.sh
Apache License 2.0
26.93k stars 7.1k forks source link

Regression for numeric Value type in Helm v2.15 breaking templates #6708

Closed arm4b closed 4 years ago

arm4b commented 5 years ago

The regression found in CI/CD nightly builds when relying on latest Helm which is now v2.15 (since Friday? :trollface:)

In new Helm v2.15 there seems to be some changes in values types.

Helm Values:

replicas: 3

Helm Template:

$replicas := int (.Values.replicas)

Will produce:

0 in v2.15 3 in v2.14


After closer look, .Values.replicas is now of type json.Number in v2.15, previously was float64 in v2.14. This means some previously worked cast/conversions in many user's templates and charts would fail. For reference: https://github.com/helm/charts/search?q=int+.Values.&unscoped_q=int+.Values https://github.com/helm/charts/search?q=until&unscoped_q=until

Workaround

Workaround for Helm v2.15 templates is to cast to string first before converting to int:

- $replicas := int (.Values.replicas)
+ $replicas := int (toString (.Values.replicas))

Output of helm version:

v2.15.0

Cloud Provider/Platform (AKS, GKE, Minikube etc.):

minikube

Fixes https://github.com/StackStorm/stackstorm-ha/issues/89 Closes https://github.com/StackStorm/stackstorm-ha/pull/91

bacongobbler commented 5 years ago

CC'ing @icanhazbroccoli as it looks like https://github.com/helm/helm/pull/6010 caused a regression. Perhaps we need to update int and other functions to accept json.Number?

osdrv commented 5 years ago

@bacongobbler indeed, it's a miss from my side. Mind if I start working on a fix?

bacongobbler commented 5 years ago

Yes please.

Stono commented 5 years ago

Was just going to report this too!

❯ helm template . --execute templates/test.yaml --set=replicas=1
---
# Source: platform-helm-at-service/templates/test.yaml

original: 1
int: 0
intOnNumber: 1
original: {{ .Values.replicas }}
int: {{ int .Values.replicas }}
intOnNumber: {{ int 1 }}
bacongobbler commented 4 years ago

fixed in #6749.

arm4b commented 4 years ago

:tada: Thanks for a quick fix!

Hopefully we'll see v2.15.1 release soonish.

hickeyma commented 4 years ago

v2.15.1 released.

rgl commented 4 years ago

Oh this problem also exists in helm 3:

Error: template: rancher/templates/deployment.yaml:76:7: executing "rancher/templates/deployment.yaml" at <gt .Values.auditLog.level 0.0>: error calling gt: incompatible types for comparison

Happens when installing with:

rancher_helm_chart_version="2.3.3"
rancher_server_domain="server.rancher.test"
kubectl create namespace cattle-system
helm install \
    rancher \
    rancher/rancher \
    --namespace cattle-system \
    --version $rancher_helm_chart_version \
    --set "hostname=$rancher_server_domain" \
    --set ingress.tls.source=secret \
    --set privateCA=true \
    --set auditLog.level=3 \
    --set replicas=1
osdrv commented 4 years ago

@rgl this is a slightly different problem, which goes as deep as golang text/template internals. In a nutshell: comparison functions expect operands to come in compatible formats. Once it gets a int-like and float-like argument tuple, it panics. Maybe this ref would be helpful: https://golang.org/src/text/template/funcs.go#L513.

I would suggest using an explicit type casting here (using int and float helpers).

rgl commented 4 years ago

@icanhazbroccoli how do I do an explicit type casting from the helm cli?

osdrv commented 4 years ago

@rgl either --set auditLog.level=3.0 or it's the templates that have to be modified :-(

rgl commented 4 years ago

Doing --set auditLog.level=3.0 brakes the rancher installation somehow. Will push for the templates to be changed instead. Thanks for the pointer!