robscott / kube-capacity

A simple CLI that provides an overview of the resource requests, limits, and utilization in a Kubernetes cluster
Apache License 2.0
2.09k stars 114 forks source link

[Bug] 0% usage will cause wrong output #73

Closed JobberRT closed 1 year ago

JobberRT commented 1 year ago

Here kc set the resources unit: https://github.com/robscott/kube-capacity/blob/9557a2857fa949de037858bb19b8f37580f16470/pkg/capacity/resources.go#L103-L112

And if the cpu or memory unit is a blank string(0% usage for example), this code will do the wrong judgement(all the judgement about Format, here just a example): https://github.com/robscott/kube-capacity/blob/9557a2857fa949de037858bb19b8f37580f16470/pkg/capacity/resources.go#L366-L372

Because the value of cpu or memory is a blank string, so it's type won't be resource.DecimalSI, and it will always do the else code block. And of couse its calculate progress will be wrong too since the else code block will call formatTomegiBytes and the unit is not correct: https://github.com/robscott/kube-capacity/blob/9557a2857fa949de037858bb19b8f37580f16470/pkg/capacity/resources.go#L387-L393

The Wrong output will be like(those red ones): image

I will try to fix it and provide a PR, but my skills are not good, will do my best

robscott commented 1 year ago

Thanks for reporting this! I've been pretty underwater recently but if anyone has time to fix this I'll try to review a PR ASAP.

KR411-prog commented 1 year ago

Please let me know if I can work on this.

robscott commented 1 year ago

Hey @KR411-prog, thanks for volunteering! Appreciate any help with this.

KR411-prog commented 1 year ago

When I checked the main branch, I dont see this if else condition anymore. I see switch case statement with also default condition check. https://github.com/robscott/kube-capacity/blob/807764563371f82047bed8f55f5a037aae3e1298/pkg/capacity/resources.go#L395-L409

I also dont find wrong unit in cpu for 0% usage now.

image

Please let me know if this issue reported is still valid.

JobberRT commented 1 year ago

@KR411-prog @robscott Sorry guys, I was late. Did this issue no longer exist? I've not using KC for a long time.

KR411-prog commented 1 year ago

@JobberRT I think the issue is no longer valid as the main branch does not seem to have the code anymore.

robscott commented 1 year ago

Thanks @JobberRT and @KR411-prog, will close this out.