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

gotohelm: fix map indexing and zeroOf #359

Merged
merged 2 commits into from
Dec 16, 2024
Merged

Conversation

chrisseto
Copy link
Contributor

66671ba gotohelm: correct map indexing for non-nil zero values

Prior to this commit all map indexing operations in helm world would return
nil thanks to index's behavior under the hood. This worked for 70% of all
cases as the zero value of most map elements was zero. However, non-nil zero
values would be handled incorrectly:

map[string]string{}["missing"] // returns nil in helm

This commit updates the transpiler to appropriately detect such cases and
injects the zero value of the map's element type.

e6cc8bc gotohelm: improve special case detection in zeroOf

Prior to this commit gotohelm would incorrectly attempt to compute the zero
value of types that implemented json.{Unm,M}arshaller. In most cases, this
would lead to a transpiler crash all together. In some corner cases, it was
possible to silently generate incorrect values.

This commit improves zeroOf to detect and reject implementers of
json.{Unm,M}arshaller with a helpful error message and adds a special case
for Kubernetes' resource.Quantity type.

Prior to this commit all map indexing operations in helm world would return
`nil` thanks to `index`'s behavior under the hood. This worked for 70% of all
cases as the zero value of most map elements was zero. However, non-nil zero
values would be handled incorrectly:

```go
map[string]string{}["missing"] // returns nil in helm
```

This commit updates the transpiler to appropriately detect such cases and
injects the zero value of the map's element type.
Prior to this commit gotohelm would incorrectly attempt to compute the zero
value of types that implemented `json.{Unm,M}arshaller`. In most cases, this
would lead to a transpiler crash all together. In some corner cases, it was
possible to silently generate incorrect values.

This commit improves `zeroOf` to detect and reject implementers of
`json.{Unm,M}arshaller` with a helpful error message and adds a special case
for Kubernetes' `resource.Quantity` type.
@chrisseto chrisseto changed the title Chris/p/gotohelm zero of gotohelm: fix map indexing and zeroOf Dec 16, 2024
@chrisseto
Copy link
Contributor Author

I'm going to merge this without k8s-operator passing because we keep hitting unrelated flakes :(

@chrisseto chrisseto merged commit bb41e7c into main Dec 16, 2024
4 of 5 checks passed
@chrisseto chrisseto deleted the chris/p/gotohelm-zero-of branch December 16, 2024 19:16
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