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

Support floats? #245

Closed
skonto opened this issue Jul 9, 2019 · 22 comments · Fixed by #618
Closed

Support floats? #245

skonto opened this issue Jul 9, 2019 · 22 comments · Fixed by #618
Assignees
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. priority/backlog Higher priority than priority/awaiting-more-evidence.

Comments

@skonto
Copy link

skonto commented Jul 9, 2019

In the official docs I still see float support: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/, am I wrong?
I am currently hitting this error:

// no floats (technically we shouldn't allow int64 or plain int either, but :shrug:).

Error I get is: unsupported type "float32". I expected my field to be parsed and crd to have a field of type number in the yaml format.

@skonto
Copy link
Author

skonto commented Jul 9, 2019

/cc @DirectXMan12 , number based fields should be all string? generate-groups.sh allows floats.

@DirectXMan12
Copy link
Contributor

so, it's technically supported, but floats are highly discouraged (and disallowed in official kubernetes APIs) because they won't round-trip properly, can't actually represent certain numbers exactly, etc (all the normal reasons floats are usually not what you want in a program). We recommend using resource.Quantity or int32 for your numeric types, in accordance with the Kubernetes API conventions.

Closing this for now, but if you have a compelling argument, I'm happy to reconsider.

@tothandras
Copy link

tothandras commented Aug 7, 2019

I think it would be better to support it and have a warning about this in the documentation. There are scenarios where precision is not important and any workaround might be worse.

@DirectXMan12
Copy link
Contributor

DirectXMan12 commented Aug 14, 2019

it's not just precision -- it's mainly that it doesn't round-trip. Can you provide a concrete example here of a scenario where you want to use float?

@tothandras
Copy link

@DirectXMan12 We have an operator managing canary releases (using Istio). The user should be able to provide arbitrary prometheus queries with thresholds (usually a floating number) alongside the built-in metrics (request success rate and request duration).

@DirectXMan12 DirectXMan12 reopened this Aug 15, 2019
@DirectXMan12
Copy link
Contributor

I think that's probably a better case for quantity than for a normal float, but I see your point.

@DirectXMan12
Copy link
Contributor

we could also have an "allowDangerousTypes" option too.

@tothandras
Copy link

@DirectXMan12 Thank you for considering it! From a UX perspective, by default I would log out a warning with a link to the relevant part of the documentation or a short description, but not fail to build. The allowDangerousTypes option could be used to turn off this warning.

@DirectXMan12
Copy link
Contributor

/kind feature
/priority backlog
/help

@k8s-ci-robot
Copy link
Contributor

@DirectXMan12:
This request has been marked as needing help from a contributor.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help command.

In response to this:

/kind feature
/priority backlog
/help

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. priority/backlog Higher priority than priority/awaiting-more-evidence. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Aug 19, 2019
@gaocegege
Copy link

gaocegege commented Oct 22, 2019

I am glad to share why we need float in CRD spec.

We are implementing an AutoML (a.k.a Hyperparameter tuning) system using kubebuilder. CRD is here https://github.com/kubeflow/katib/tree/master/pkg/apis/controller.

You can see https://github.com/kubeflow/katib/blob/master/pkg/apis/controller/common/v1alpha3/common_types.go#L42 where we use float

We allow users to define the goal of the tuning experiment (e.g. When the accuracy reached the goal, we stop the experiment). And the goal is mainly a float number (e.g. 0.99 for accuracy, or 100.5 for loss and so on).

Thus it will be better if we support floats. But it seems that we can have some hack around resource.Quantity

@DirectXMan12
Copy link
Contributor

@gaocegege it's not clear to me why that needs float in the IEEE sense. We could improve the syntax for resource.Quantity a bit, but I think resource.Quantity should suffice for your use case.

@gaocegege
Copy link

Yeah, It also works.

@loewenstein
Copy link

@DirectXMan12 Would you consider reopening this? We would be willing to contribute float support.

We plan to include another CRD (like a template) in ours and that unfortunately uses a float64.

@RobbinBaauw
Copy link

RobbinBaauw commented May 14, 2020

float64 is also used in Kubernetes APIs:
https://github.com/kubernetes/kubernetes/blob/7580666e0c58b0a34a87fb19beeb682a88e50fac/pkg/kubelet/apis/stats/v1alpha1/types.go#L342-L344

Right now, it is unfortunately impossible to use stats.PodStats in your CRD (both because of this error and because VolumeStats has an embedded FsStats without JSON tags).

rainest added a commit to Kong/go-kong that referenced this issue Feb 6, 2021
Convert the Upstream health threshold and Target createdat values from
float64 to string.

Use of float64 doesn't allow controller-gen to automate manifests from
these types, and using string instead is the typical approach in other
projects:
kubernetes-sigs/controller-tools#245
rainest added a commit to Kong/go-kong that referenced this issue Feb 6, 2021
Convert the Upstream health threshold and Target createdat values from
float64 to string.

Use of float64 doesn't allow controller-gen to automate manifests from
these types, and using string instead is the typical approach in other
projects:
kubernetes-sigs/controller-tools#245
rainest added a commit to Kong/go-kong that referenced this issue Feb 8, 2021
Convert the Upstream health threshold and Target createdat values from
float64 to json.Number

Use of float64 prevents controller-gen from automatically generating
maifests from these types:
kubernetes-sigs/controller-tools#245
@alvaroaleman
Copy link
Member

/reopen

@k8s-ci-robot
Copy link
Contributor

@alvaroaleman: Reopened this issue.

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@matthchr
Copy link
Contributor

@alvaroaleman - FYI there's already some support for floats which I added in #449 behind a flag.

@alvaroaleman
Copy link
Member

@alvaroaleman - FYI there's already some support for floats which I added in #449 behind a flag.

Oh I wasn't aware of that, thanks for mentioning it! Maybe we could improve the handling to instead of falling through into unsupported type mention why this is problematic and that it can be overridden through this flag?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. priority/backlog Higher priority than priority/awaiting-more-evidence.
Projects
None yet
Development

Successfully merging a pull request may close this issue.