If container doesn't have resources set, in pod view show limits as n/a
parent
c3c77b6e50
commit
0c425f2edf
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
|
|
@ -262,3 +263,11 @@ func ToPercentage(v1, v2 int64) int {
|
|||
}
|
||||
return int(math.Floor((float64(v1) / float64(v2)) * 100))
|
||||
}
|
||||
|
||||
// ToPercentageStr computes percentage, but if v2 is 0, it will return NAValue instead of 0
|
||||
func ToPercentageStr(v1, v2 int64) string {
|
||||
if v2 == 0 {
|
||||
return NA
|
||||
}
|
||||
return strconv.Itoa(ToPercentage(v1, v2))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,10 +160,10 @@ func (*Pod) gatherPodMX(pod *v1.Pod, mx *mv1beta1.PodMetrics) (c, p metric) {
|
|||
rc, rm := requestedRes(pod.Spec.Containers)
|
||||
lc, lm := resourceLimits(pod.Spec.Containers)
|
||||
p = metric{
|
||||
cpu: IntToStr(client.ToPercentage(cpu.MilliValue(), rc.MilliValue())),
|
||||
mem: IntToStr(client.ToPercentage(client.ToMB(mem.Value()), client.ToMB(rm.Value()))),
|
||||
cpuLim: IntToStr(client.ToPercentage(cpu.MilliValue(), lc.MilliValue())),
|
||||
memLim: IntToStr(client.ToPercentage(client.ToMB(mem.Value()), client.ToMB(lm.Value()))),
|
||||
cpu: client.ToPercentageStr(cpu.MilliValue(), rc.MilliValue()),
|
||||
mem: client.ToPercentageStr(client.ToMB(mem.Value()), client.ToMB(rm.Value())),
|
||||
cpuLim: client.ToPercentageStr(cpu.MilliValue(), lc.MilliValue()),
|
||||
memLim: client.ToPercentageStr(client.ToMB(mem.Value()), client.ToMB(lm.Value())),
|
||||
}
|
||||
|
||||
return
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ func TestPodRender(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
|
||||
assert.Equal(t, "default/nginx", r.ID)
|
||||
e := render.Fields{"default", "nginx", "1/1", "0", "Running", "10", "10", "10", "14", "0", "5", "172.17.0.6", "minikube", "BE"}
|
||||
e := render.Fields{"default", "nginx", "1/1", "0", "Running", "10", "10", "10", "14", render.NAValue, "5", "172.17.0.6", "minikube", "BE"}
|
||||
assert.Equal(t, e, r.Fields[:14])
|
||||
}
|
||||
|
||||
|
|
@ -190,7 +190,7 @@ func TestPodInitRender(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
|
||||
assert.Equal(t, "default/nginx", r.ID)
|
||||
e := render.Fields{"default", "nginx", "1/1", "0", "Init:0/1", "10", "10", "10", "14", "0", "5", "172.17.0.6", "minikube", "BE"}
|
||||
e := render.Fields{"default", "nginx", "1/1", "0", "Init:0/1", "10", "10", "10", "14", render.NAValue, "5", "172.17.0.6", "minikube", "BE"}
|
||||
assert.Equal(t, e, r.Fields[:14])
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue