Skip to content

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

Closed

Description

@arm4b

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 StackStorm/stackstorm-k8s#89
Closes StackStorm/stackstorm-k8s#91

Activity

  1. bacongobbler commented on Oct 19, 2019

    @bacongobbler
    Member

    CC'ing @icanhazbroccoli as it looks like #6010 caused a regression. Perhaps we need to update int and other functions to accept json.Number?

  2. added this to the 2.15.1 milestone on Oct 19, 2019
  3. added
    bug
    v2.x
    on Oct 19, 2019
  4. osdrv commented on Oct 19, 2019

    @osdrv
    Contributor

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

  5. bacongobbler commented on Oct 19, 2019

    @bacongobbler
    Member

    Yes please.

  6. Stono commented on Oct 20, 2019

    @Stono

    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 }}
    
  7. 17 remaining items

  8. rgl commented on Dec 1, 2019

    @rgl

    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
    
  9. osdrv commented on Dec 1, 2019

    @osdrv
    Contributor

    @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).

  10. rgl commented on Dec 1, 2019

    @rgl

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

  11. osdrv commented on Dec 1, 2019

    @osdrv
    Contributor

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

  12. rgl commented on Dec 7, 2019

    @rgl

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugv2.x

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions