Untitled

 avatar
unknown
plain_text
2 months ago
1.1 kB
6
Indexable
kubectl get pods -n <namespace> -o json | jq '
  reduce .items[] as $pod (
    {cpuRequest: 0, memRequest: 0, cpuLimit: 0, memLimit: 0, excluded: []};
    if (
      ($pod.spec.containers[]?.resources.requests.cpu // "") == "" or
      ($pod.spec.containers[]?.resources.requests.memory // "") == "" or
      ($pod.spec.containers[]?.resources.limits.cpu // "") == "" or
      ($pod.spec.containers[]?.resources.limits.memory // "") == ""
    ) then
      .excluded += [$pod.metadata.name]
    else
      .cpuRequest += ($pod.spec.containers[]?.resources.requests.cpu // "0m" | sub("m"; "") | tonumber * if test("m") then 1 else 1000 end) |
      .memRequest += ($pod.spec.containers[]?.resources.requests.memory // "0Mi" | sub("Mi"; "") | tonumber * if test("Gi") then 1024 else 1 end) |
      .cpuLimit += ($pod.spec.containers[]?.resources.limits.cpu // "0m" | sub("m"; "") | tonumber * if test("m") then 1 else 1000 end) |
      .memLimit += ($pod.spec.containers[]?.resources.limits.memory // "0Mi" | sub("Mi"; "") | tonumber * if test("Gi") then 1024 else 1 end)
    end
  )
'
Editor is loading...
Leave a Comment