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

Add paved.GetFloat() function #778

Conversation

rickard-von-essen
Copy link

This adds paved.GetFloat() function similar to paved.GetString() and paved.GetInteger() but returning a float64.

I have:

Need help with this checklist? See the cheat sheet.

This adds `paved.GetFloat()` function similar to `paved.GetString()` and
`paved.GetInteger()` but returning a `float64`.

Signed-off-by: Rickard von Essen <[email protected]>
@rickard-von-essen rickard-von-essen requested a review from a team as a code owner September 26, 2024 08:46
@negz
Copy link
Member

negz commented Oct 11, 2024

Thanks! Can you provide some context around what you need this for?

I vaguely recall that we actually used to have something like this but intentionally dropped it, because you're not supposed to use floats in Kubernetes APIs. From https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#primitive-types:

Avoid floating-point values as much as possible, and never use them in spec. Floating-point values cannot be reliably round-tripped (encoded and re-decoded) without changing, and have varying precision and representations across languages and architectures.

@rickard-von-essen
Copy link
Author

Sorry I should have provided some context.

I needed this in this PR provider-upjet-gcp#623 to read the port (as in IPv4 port).

I first assumed it was a integer since inherently a port is an int and the Terraform schema mark it as schema.TypeInt. But after some debugging I realize it was passed as a json number which translates into a float.

@negz
Copy link
Member

negz commented Oct 16, 2024

@rickard-von-essen I'm pretty confident this is a bug in upjet - these fields should not be floats in the Go structs. That violates the Kubernetes API conventions I linked above. It also doesn't make sense in most of the cases - ports, replica counts, etc presumably can never actually be a floating point number.

So, I suggest we fix the bug (which I assume is in upjet) rather than adding a GetFloat utility here.

@rickard-von-essen
Copy link
Author

@negz Thanks for your insight on this. I'll close this and see if I have some time to chase down the issue in upjet.

@rickard-von-essen rickard-von-essen deleted the feature/paved-getfloat branch October 20, 2024 19:02
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