What is the purpose of this function in Kubernetes?

6/21/2019

I would like to, what is the purpose of the following function? Is it for resource allocation?

Also, I want to know, in which part of codes, the kubernetes decides to allocate resources based on resource limits? I cannot find those codes. Could you please help me?

https://github.com/kubernetes/kubernetes/blob/master/pkg/scheduler/nodeinfo/node_info.go

func calculateResource(pod *v1.Pod) (res Resource, non0CPU int64, non0Mem int64) {
    resPtr := &res
    for _, c := range pod.Spec.Containers {
        resPtr.Add(c.Resources.Requests)

        non0CPUReq, non0MemReq := priorityutil.GetNonzeroRequests(&c.Resources.Requests)
        non0CPU += non0CPUReq
        non0Mem += non0MemReq
        // No non-zero resources for GPUs or opaque resources.
    }

    return
}
-- HamiBU
kubernetes

1 Answer

6/22/2019

In short, kubelet limit container resource usage by cgroup. You can search this by keyword CgroupConfig.

How kubernetes decides to allocate resources based on resource limits?

Detail at ResourceConfigForPod.

-- menya
Source: StackOverflow