Skip to content

Wrong interpretation of Zero in templates files when having a default value #3164

@anas-aso

Description

@anas-aso

Setup

Here is my helm chart (just the relevant part to this issue)
values.yaml:

name: failed
MyValue: 0

templates/config.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Values.name }}
data:
  file.conf: |+
    {{ .Values.MyValue | default 10 }}

Expected behaviour

Running helm upgrade --install ... I expect to have a ConfigMap that contains the value "0".

Actual behaviour

The created ConfigMap contains "10" (the default).

$ kubectl describe cm failed
Name:         failed
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
file.conf:
----
10

Events:  <none>

More fun:

This behaviour is not visible when :

  • there is no default. Changing this line {{ .Values.MyValue | default 10 }} to this {{ .Values.MyValue }}
  • the value is different than Zero (0). Changing this line MyValue: 0 to this MyValue: 7
  • the value is zero by quoted "0" (string not int). Changing this line MyValue: 0 to this MyValue: "0"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions