Skip to content

Commit 61b3e1c

Browse files
committed
feat/node-view-allocated-res:
render: show “n/a” for negative requested CPU/memory values Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
1 parent 3bebdef commit 61b3e1c

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

internal/dao/node.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ func (n *Node) CalculateRequestedResources(oo []runtime.Object, nodeName string)
269269
continue
270270
}
271271

272-
// Convert to Pod to check phase and calculate resources
273272
var pod v1.Pod
274273
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &pod); err != nil {
275274
continue
@@ -280,9 +279,6 @@ func (n *Node) CalculateRequestedResources(oo []runtime.Object, nodeName string)
280279
continue
281280
}
282281

283-
// Calculate requests from containers
284-
// Init containers run sequentially, so we take the max of their requests
285-
// Regular containers run in parallel, so we sum their requests
286282
var initCPU, initMem *resource.Quantity
287283
for i := range pod.Spec.InitContainers {
288284
co := pod.Spec.InitContainers[i]
@@ -306,19 +302,16 @@ func (n *Node) CalculateRequestedResources(oo []runtime.Object, nodeName string)
306302
}
307303
}
308304

309-
// Calculate pod-level requested resources
310305
podCPUQ := resource.NewQuantity(0, resource.DecimalSI)
311306
podMemQ := resource.NewQuantity(0, resource.BinarySI)
312307

313-
// Add max init container resources
314308
if initCPU != nil {
315309
podCPUQ.Add(*initCPU)
316310
}
317311
if initMem != nil {
318312
podMemQ.Add(*initMem)
319313
}
320314

321-
// Sum regular container requests
322315
for i := range pod.Spec.Containers {
323316
co := pod.Spec.Containers[i]
324317
req := co.Resources.Requests
@@ -346,7 +339,6 @@ func (n *Node) CalculateRequestedResources(oo []runtime.Object, nodeName string)
346339
"memory-requested-bytes", podMemQ.Value(),
347340
)
348341

349-
// Add to cumulative totals
350342
cpuQ.Add(*podCPUQ)
351343
memQ.Add(*podMemQ)
352344
}

internal/render/node_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import (
1616

1717
func TestNodeRender(t *testing.T) {
1818
pom := render.NodeWithMetrics{
19-
Raw: load(t, "no"),
20-
MX: makeNodeMX("n1", "10m", "20Mi"),
19+
Raw: load(t, "no"),
20+
MX: makeNodeMX("n1", "10m", "20Mi"),
21+
RequestedCPU: -1,
22+
RequestedMemory: -1,
2123
}
2224

2325
var no render.Node
@@ -26,8 +28,8 @@ func TestNodeRender(t *testing.T) {
2628
require.NoError(t, err)
2729

2830
assert.Equal(t, "minikube", r.ID)
29-
e := model1.Fields{"minikube", "Ready", "master", "amd64", "0", "v1.15.2", "Buildroot 2018.05.3", "4.15.0", "192.168.64.107", "<none>", "0", "10", "4000", "0", "20", "7874", "0", "n/a", "n/a"}
30-
assert.Equal(t, e, r.Fields[:19])
31+
e := model1.Fields{"minikube", "Ready", "master", "amd64", "0", "v1.15.2", "Buildroot 2018.05.3", "4.15.0", "192.168.64.107", "<none>", "0", "10", "4000", "n/a", "0", "n/a", "20", "7874", "n/a", "0", "n/a"}
32+
assert.Equal(t, e, r.Fields[:21])
3133
}
3234

3335
func BenchmarkNodeRender(b *testing.B) {

0 commit comments

Comments
 (0)