Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kindIs returns false when documentation says it should return true #1532

Open
NeodymiumFerBore opened this issue Dec 3, 2023 · 2 comments · May be fixed by #1653
Open

kindIs returns false when documentation says it should return true #1532

NeodymiumFerBore opened this issue Dec 3, 2023 · 2 comments · May be fixed by #1653

Comments

@NeodymiumFerBore
Copy link

Opening this issue following the reply on helm/helm#12084 (helm/helm#12084 (comment))

Description

{{ if kindIs "int" 123 }} returns false when documentation says it should return true.

This appears to be a documentation issue. The kind of a yaml/json parsed number is float64 with the library that's used. Please file an issue in helm-www.

Behavior details can be found in mentioned issue.

@TerryHowe TerryHowe linked a pull request Nov 14, 2024 that will close this issue
@mattfarina
Copy link
Contributor

This is more complicated than it seems.

The following will return true in a template.

kindIs "int" 123

See https://go.dev/play/p/kUCfwEQzeoh for an example that shows exactly this.

The problem in the original issue is that 123 in the values.yaml file is parsed by the k8s yaml parser. The spec has data types for both integers and floating point numbers. But, the Kubernetes YAML parser turns any number into a float64. The following is a comment from that package:

// - This decodes any number (although it is an integer) into a float64 if the type of obj is unknown, e.g. *map[string]interface{}, *interface{}, or *[]interface{}. This means integers above +/- 2^53 will lose precision when round-tripping. Make a JSONOpt that calls d.UseNumber() to avoid this.

If you use an integer right in the template it will return true. If you use a number passed from the values.yaml file it will need to be a float64.

@TerryHowe
Copy link
Contributor

Related helm/helm#4982

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants