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

Fix rounding issue when parsing CPU k8s resources #145

Merged
merged 1 commit into from
Nov 8, 2022

Conversation

amisevsk
Copy link
Contributor

@amisevsk amisevsk commented Nov 8, 2022

What does this PR do?

Fix issue where adding Kubernetes resource units results in invalid values:

k8sUnits.sumUnits("4000m", "30m", "cpu")

returns 4030.0000000000005m

What issues does this PR fix?

Part of eclipse-che/che#21811

How to test this PR?

k8sUnits.sumUnits("4000m", "30m", "cpu") should return 4030m

Take floor before returning a CPU resource in millis to avoid invalid values
resulting from floating point precision

(4.0+0.03)*1000 !== 4030

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
@azatsarynnyy azatsarynnyy merged commit 10ddd51 into main Nov 8, 2022
@azatsarynnyy azatsarynnyy deleted the fix-float-int-conversion branch November 8, 2022 16:42
@che-bot che-bot added this to the 7.57 milestone Nov 8, 2022
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.

3 participants