kube-capacity icon indicating copy to clipboard operation
kube-capacity copied to clipboard

fix limit and request availability with -a with json and yaml

Open elyesbenamor opened this issue 10 months ago • 2 comments

Closes #92

Add Available Resources to JSON/YAML Output

Description

Currently, when using the -a flag with JSON/YAML output formats, the available resources are not displayed in a clear format. This PR adds new fields requestsAvailable and limitsAvailable to show available resources explicitly while maintaining backward compatibility.

Changes

  • Added new fields requestsAvailable and limitsAvailable to listResourceOutput struct
  • Updated buildListResourceOutput to calculate and populate available resources
  • These fields are only included in the output when using the -a flag

Examples

Without -a flag (unchanged):

{
  "nodes": [
    {
      "name": "minikube",
      "cpu": {
        "requests": "1350m",
        "requestsPercent": "11%",
        "limits": "700m",
        "limitsPercent": "5%"
      },
      "memory": {
        "requests": "522Mi",
        "requestsPercent": "6%",
        "limits": "362Mi",
        "limitsPercent": "4%"
      }
    }
  ]
}
### With `-a` flag (unchanged):
{
  "nodes": [
    {
      "name": "minikube",
      "cpu": {
        "requests": "1350m",
        "requestsPercent": "11%",
        "requestsAvailable": "10650m",
        "limits": "700m",
        "limitsPercent": "5%",
        "limitsAvailable": "11300m"
      },
      "memory": {
        "requests": "522Mi",
        "requestsPercent": "6%",
        "requestsAvailable": "7315Mi",
        "limits": "362Mi",
        "limitsPercent": "4%",
        "limitsAvailable": "7475Mi"
      }
    }
  ]
}

elyesbenamor avatar Jan 07 '25 15:01 elyesbenamor

@robscott Here is a detailed MR that can be reviewed please

elyesbenamor avatar Jan 12 '25 18:01 elyesbenamor

Hey @elyesbenamor, thanks for the contribution! Any chance you can rebase this PR?

robscott avatar Mar 24 '25 03:03 robscott