davidB / kubectl-view-allocations

kubectl plugin to list allocations (cpu, memory, gpu,... X utilization, requested, limit, allocatable,...)

Home Page:https://crates.io/crates/kubectl-view-allocations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Comparison between requests and limits seems wrong

ktarplee opened this issue · comments

I have been digging into the code and it seems that this is ignoring the scale field (namely base and pow).

This is used (if I understand rust properly) by the calc_free function when it compares requests to limits. If these have different bases then the result will be wrong. For example in this code I think "10 Gi" would be less than "100 Mi".

I think we need to use the commented out code or switch to bignumber like the comments suggest.

I guess No, you can add a test to check.

On previous impl, Qty.value used Qty.scale as unit, so it used the commented code f64::from(...) for the comparison, but I got some issues and complexity in the code. So switch to Qty.valuealways in the lowest unit (milli). and as i64 to have no rounding issue, real zero, real comparison and the range is enough for our use case.

Thanks for the review

I see what you mean. That makes sense. I didn't realize value was the entire value (in millis).