Skip to content

Conversation

@v0y4g3r
Copy link

@v0y4g3r v0y4g3r commented Nov 19, 2025

Related issues:

Main changes

This PR introduces a new nodes-alloc view that provides detailed resource allocation information for Kubernetes nodes, including CPU and memory requests from all pods scheduled on each node. The view is optimized for capacity planning and resource utilization analysis.

Motivation

The standard nodes view shows node capacity and current usage, but doesn't display the total requested resources from pods. This makes it difficult to:

  • Understand how much of a node's capacity is actually requested by workloads
  • Identify nodes that are over-committed or under-utilized
  • Plan capacity based on resource requests rather than just current usage

The new nodes-alloc view addresses this by always calculating and displaying requested CPU and memory resources, providing a clearer picture of resource allocation across the cluster.

Changes

New Features

  1. New nodes-alloc view (:na or :nodes-alloc)

    • Dedicated view for resource allocation analysis
    • Always calculates requested CPU and memory from pods
    • Shows both absolute values and percentages
    • Streamlined column layout focused on resource metrics
  2. Resource Request Calculation

    • Calculates sum of CPU and memory requests from all non-terminated pods
    • Properly handles init containers (uses maximum init container resources)
    • Skips terminated pods (Succeeded/Failed states)
    • Falls back to limits when requests are not specified
  3. Performance Optimization

    • Requested resource calculation is deferred to the nodes-alloc view only
    • Regular nodes view no longer performs expensive pod resource calculations
    • Improves performance of the standard nodes view when pod counting is disabled

 feat(node): show requested CPU/MEM per node

 - Add CPU/R, %CPU/R, MEM/R, %MEM/R columns
 - Sum non-terminated pod requests; skip init-container overlap
 - Cache totals in NodeWithMetrics for both Get and List

Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
@v0y4g3r v0y4g3r changed the title feat: node view allocated res feat: add requested resource info to node view Nov 19, 2025
 render: show “n/a” for negative requested CPU/memory values

Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
@v0y4g3r v0y4g3r force-pushed the feat/node-view-allocated-res branch from da1e25a to 61b3e1c Compare November 19, 2025 08:46
@derailed
Copy link
Owner

@v0y4g3r Thank you for this update!
Tho I do see the value in computing these columns, I don't think we should volunteer this info in node view as this is an expensive computation and would render k9s worthless depending on node/pod cardinality at the cluster level.

Perhaps an alternate way to handle this, would be to offer and child view that would compute resource usage details per node, so cluster admins can use this to provision their cluster accordingly. Given this would be a separate command, we would not penalize everyone landing in node view and looking for other specific information especially on larger clusters.

What do you think?

@derailed derailed added the question Further information is requested label Nov 24, 2025
@v0y4g3r
Copy link
Author

v0y4g3r commented Nov 24, 2025

Perhaps an alternate way to handle this, would be to offer and child view that would compute resource usage details per node

I agree. Could you provide more context so I can proceed? For example, do we need to add a dedicated command (:node_resource), or by "child view" do you mean we can navigate to that list from an existing view? Is there any prior work I could use as a reference?

@derailed
Copy link
Owner

derailed commented Nov 25, 2025

@v0y4g3r Thank you Lei!

Sure. Here are my thoughts. I think we could go either way by either introducing a new k9s node view aka node-resources or node-allocs as you've suggested or add an a key action on node view and show allocations details for a selected node. I do think as an admin having a sortable view of node allocs would be awesome so one can figure out cluster provisioning margins/limits. Ultimately we could support both. But we can start with a global node-allocs command which I think would be a good start.

Code wise we have examples of either approaches i.e pod->container views or general views like workloads, dirs, etc.. with a custom dao.

 feat: add nodes-alloc view showing CPU/memory allocation per node

 Introduces a new k9s alias `nodes-alloc` (short: `na`) that lists every node together with the total CPU and memory *requested* by all non-terminated pods scheduled on it.
 Implementation adds NodeAlloc DAO, view, registry entries and wires it into the alias table; re-uses the existing Node renderer so columns match the standard node view but always include pod count, request
 CPU and requested memory.

Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
 perf: defer requested-resources calculation to NodeAlloc view only

 - Remove CPU/memory request summation from regular Node List/Get
 - Keep CalculateRequestedResources() solely in NodeAlloc DAO
 - Node view now always reports -1 for RequestedCPU/RequestedMemory
 - Eliminates redundant pod iteration on every node list/query

Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
 feat: add NodeAlloc renderer for nodes-alloc view

 - introduce dedicated NodeAlloc renderer dropping ROLE, TAINTS, VERSION, AGE
 - expose requested CPU/MEM columns and their percentages
 - register new renderer in Registry for client.NodeAllocGVR

Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
 feat: add NodeAlloc resource view with pod count and resource requests

 - Introduce NodeAlloc GVR and supporting DAO, render, view layers
 - Count scheduled pods and aggregate CPU/memory requests per node
 - Surface requested vs allocatable percentages in the UI
 - Include comprehensive unit tests for core logic

Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
 ui: drop requested CPU & memory columns from node view

Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
@v0y4g3r v0y4g3r force-pushed the feat/node-view-allocated-res branch from a2c9885 to 80d1709 Compare December 1, 2025 06:56
@v0y4g3r
Copy link
Author

v0y4g3r commented Dec 1, 2025

@derailed Happy Thanksgiving! I made some changes to this PR in this holiday as we discussed above, please take another look

@v0y4g3r v0y4g3r changed the title feat: add requested resource info to node view feat: add node-alloc view Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Node Allocated resources

2 participants