Skip to content

[Bug]: gt fails when comparing int and float values in Helm templates #84

Description

@ahron-cohen

Description

Versions:

  • Controller Version: v0.1.3
  • Chart Version: 0.1.3

When using the gt function in a Helm template to compare a value (e.g., .Values.controller.replicas) with a float literal like 1.0, the template fails if the value is an int.

Example:

values.yaml

controller:
....replicas: 2

template

{{- if gt .Values.controller.replicas 1.0 -}}
...
{{- end -}}

Files affected:

This issue occurs in the following templates:

  • charts/local-pvc-releaser/templates/rbac/leader_election_role_binding.yaml
  • charts/local-pvc-releaser/templates/rbac/leader_election_role.yaml
  • charts/local-pvc-releaser/templates/manager/deployment.yaml

Error:

error calling gt: incompatible types for comparison

This is surprising because in most languages, comparing int to float works transparently (e.g., 2 > 1.0 is valid).

Expected behavior:

gt should handle numeric comparisons between int and float where possible, or at least provide a clearer error message or helper functions for type conversion.

Actual behavior:

The template engine throws a runtime error when comparing int with float64.

Suggested fix:

{{- if gt (int .Values.controller.replicas) 1 -}}

Helm version:

version.BuildInfo{Version:"v3.18.0", GitCommit:"cc58e3f5a3aa615c6a86275e6f4444b5fdd3cc4e", GitTreeState:"clean", GoVersion:"go1.24.3"}

Regression Note:

In earlier versions of Helm (with older Go versions), this comparison did not fail at runtime, and mixed-type comparisons (int with float) were handled more permissively.
After Helm upgraded its Go version (e.g., Go 1.20+), the stricter type safety in Go templates has made this behavior a breaking change in practice, even though it is not documented as such.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions