Skip to content

fix(config): preserve integer types through YAML struct-path unmarshal#256

Closed
geoberle wants to merge 1 commit into
mainfrom
numbers
Closed

fix(config): preserve integer types through YAML struct-path unmarshal#256
geoberle wants to merge 1 commit into
mainfrom
numbers

Conversation

@geoberle

Copy link
Copy Markdown
Collaborator

sigs.k8s.io/yaml converts all numbers to float64 when unmarshaling through the struct path (YAML → JSON → json.Unmarshal). For values >= 1e6, fmt.Sprint renders float64 in scientific notation (2e+06),
which breaks bicep template parsing, and required some hacky workarounds, e.g.

param amwMaxActiveTimeSeries = {{ if eq (printf "%T" .monitoring.maxActiveTimeSeries) "float64" }}{{ printf "%.0f" .monitoring.maxActiveTimeSeries }}{{ else }}{{ .monitoring.maxActiveTimeSeries }}{{ end }}

Add UnmarshalJSON on types.Configuration using json.Decoder with UseNumber() to preserve integers as int64 and fractional values as float64.

Why now: the conditional shown in the example does not translate well into EV2 artifacts, hence we want to make sure that things like these are disallowed in bicepparam files but first need to fix them properly
alse see: #255

https://redhat.atlassian.net/browse/ARO-27909

Copilot AI review requested due to automatic review settings June 22, 2026 15:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a YAML→JSON→Go unmarshaling issue where numeric values can be coerced into float64, causing large integers (≥ 1e6) to render in scientific notation and break downstream bicep/bicepparam parsing. It introduces a custom JSON unmarshaler for types.Configuration to preserve integer types and adds unit tests to lock in the behavior.

Changes:

  • Add Configuration.UnmarshalJSON using json.Decoder.UseNumber() and recursively normalize json.Number into int64 or float64.
  • Add tests covering integers, floats, nesting, and arrays to ensure numeric type preservation and expected fmt.Sprint rendering.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
config/types/configuration.go Adds custom JSON unmarshaling and recursive normalization to preserve integer numeric types.
config/types/configuration_test.go Adds unit tests validating integer preservation and string rendering behavior across nested/array cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread config/types/configuration.go
sigs.k8s.io/yaml converts all numbers to float64 when unmarshaling
through the struct path (YAML → JSON → json.Unmarshal). For values
>= 1e6, fmt.Sprint renders float64 in scientific notation (2e+06),
which breaks bicep template parsing.

Add UnmarshalJSON on types.Configuration using json.Decoder with
UseNumber() to preserve integers as int64 and fractional values as
float64.

Ref: ARO-27909
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 this pull request may close these issues.

2 participants