mirror of https://github.com/k3s-io/k3s
Merge pull request #27365 from derekwaynecarr/describe_allocatable
Automatic merge from submit-queue kubectl describe node is allocatable aware `kubectl describe node` will render node.status.allocatable if present. in addition, it will report allocated resources relative to node.status.allocatable if present instead of capacity. old code was confusing if you setup system-reserved and kube-reserved as allocated resource percentages were relative to node capacity and not schedulable amount of resources. this is a small but valuable usability improvement, so i think it would be good to make 1.3 milestone. /cc @kubernetes/sig-node @kubernetes/rh-cluster-infra @kubernetes/kubectl @davidopppull/6/head
commit
b613908cf2
|
@ -1669,12 +1669,27 @@ func describeNode(node *api.Node, nodeNonTerminatedPodsList *api.PodList, events
|
|||
for _, address := range node.Status.Addresses {
|
||||
addresses = append(addresses, address.Address)
|
||||
}
|
||||
|
||||
printResourceList := func(resourceList api.ResourceList) {
|
||||
resources := make([]api.ResourceName, 0, len(resourceList))
|
||||
for resource := range resourceList {
|
||||
resources = append(resources, resource)
|
||||
}
|
||||
sort.Sort(SortableResourceNames(resources))
|
||||
for _, resource := range resources {
|
||||
value := resourceList[resource]
|
||||
fmt.Fprintf(out, " %s:\t%s\n", resource, value.String())
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(out, "Addresses:\t%s\n", strings.Join(addresses, ","))
|
||||
if len(node.Status.Capacity) > 0 {
|
||||
fmt.Fprintf(out, "Capacity:\n")
|
||||
for resource, value := range node.Status.Capacity {
|
||||
fmt.Fprintf(out, " %s:\t%s\n", resource, value.String())
|
||||
}
|
||||
printResourceList(node.Status.Capacity)
|
||||
}
|
||||
if len(node.Status.Allocatable) > 0 {
|
||||
fmt.Fprintf(out, "Allocatable:\n")
|
||||
printResourceList(node.Status.Allocatable)
|
||||
}
|
||||
|
||||
fmt.Fprintf(out, "System Info:\n")
|
||||
|
@ -1811,16 +1826,21 @@ func describeNodeResource(nodeNonTerminatedPodsList *api.PodList, node *api.Node
|
|||
fmt.Fprintf(out, "Non-terminated Pods:\t(%d in total)\n", len(nodeNonTerminatedPodsList.Items))
|
||||
fmt.Fprint(out, " Namespace\tName\t\tCPU Requests\tCPU Limits\tMemory Requests\tMemory Limits\n")
|
||||
fmt.Fprint(out, " ---------\t----\t\t------------\t----------\t---------------\t-------------\n")
|
||||
allocatable := node.Status.Capacity
|
||||
if len(node.Status.Allocatable) > 0 {
|
||||
allocatable = node.Status.Allocatable
|
||||
}
|
||||
|
||||
for _, pod := range nodeNonTerminatedPodsList.Items {
|
||||
req, limit, err := api.PodRequestsAndLimits(&pod)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cpuReq, cpuLimit, memoryReq, memoryLimit := req[api.ResourceCPU], limit[api.ResourceCPU], req[api.ResourceMemory], limit[api.ResourceMemory]
|
||||
fractionCpuReq := float64(cpuReq.MilliValue()) / float64(node.Status.Capacity.Cpu().MilliValue()) * 100
|
||||
fractionCpuLimit := float64(cpuLimit.MilliValue()) / float64(node.Status.Capacity.Cpu().MilliValue()) * 100
|
||||
fractionMemoryReq := float64(memoryReq.MilliValue()) / float64(node.Status.Capacity.Memory().MilliValue()) * 100
|
||||
fractionMemoryLimit := float64(memoryLimit.MilliValue()) / float64(node.Status.Capacity.Memory().MilliValue()) * 100
|
||||
fractionCpuReq := float64(cpuReq.MilliValue()) / float64(allocatable.Cpu().MilliValue()) * 100
|
||||
fractionCpuLimit := float64(cpuLimit.MilliValue()) / float64(allocatable.Cpu().MilliValue()) * 100
|
||||
fractionMemoryReq := float64(memoryReq.Value()) / float64(allocatable.Memory().Value()) * 100
|
||||
fractionMemoryLimit := float64(memoryLimit.Value()) / float64(allocatable.Memory().Value()) * 100
|
||||
fmt.Fprintf(out, " %s\t%s\t\t%s (%d%%)\t%s (%d%%)\t%s (%d%%)\t%s (%d%%)\n", pod.Namespace, pod.Name,
|
||||
cpuReq.String(), int64(fractionCpuReq), cpuLimit.String(), int64(fractionCpuLimit),
|
||||
memoryReq.String(), int64(fractionMemoryReq), memoryLimit.String(), int64(fractionMemoryLimit))
|
||||
|
@ -1833,10 +1853,10 @@ func describeNodeResource(nodeNonTerminatedPodsList *api.PodList, node *api.Node
|
|||
return err
|
||||
}
|
||||
cpuReqs, cpuLimits, memoryReqs, memoryLimits := reqs[api.ResourceCPU], limits[api.ResourceCPU], reqs[api.ResourceMemory], limits[api.ResourceMemory]
|
||||
fractionCpuReqs := float64(cpuReqs.MilliValue()) / float64(node.Status.Capacity.Cpu().MilliValue()) * 100
|
||||
fractionCpuLimits := float64(cpuLimits.MilliValue()) / float64(node.Status.Capacity.Cpu().MilliValue()) * 100
|
||||
fractionMemoryReqs := float64(memoryReqs.MilliValue()) / float64(node.Status.Capacity.Memory().MilliValue()) * 100
|
||||
fractionMemoryLimits := float64(memoryLimits.MilliValue()) / float64(node.Status.Capacity.Memory().MilliValue()) * 100
|
||||
fractionCpuReqs := float64(cpuReqs.MilliValue()) / float64(allocatable.Cpu().MilliValue()) * 100
|
||||
fractionCpuLimits := float64(cpuLimits.MilliValue()) / float64(allocatable.Cpu().MilliValue()) * 100
|
||||
fractionMemoryReqs := float64(memoryReqs.Value()) / float64(allocatable.Memory().Value()) * 100
|
||||
fractionMemoryLimits := float64(memoryLimits.Value()) / float64(allocatable.Memory().Value()) * 100
|
||||
fmt.Fprintf(out, " %s (%d%%)\t%s (%d%%)\t%s (%d%%)\t%s (%d%%)\n",
|
||||
cpuReqs.String(), int64(fractionCpuReqs), cpuLimits.String(), int64(fractionCpuLimits),
|
||||
memoryReqs.String(), int64(fractionMemoryReqs), memoryLimits.String(), int64(fractionMemoryLimits))
|
||||
|
|
Loading…
Reference in New Issue