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

<p>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? </p>

<p><a href="https://github.com/kubernetes/kubernetes/blob/master/pkg/scheduler/nodeinfo/node_info.go" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/blob/master/pkg/scheduler/nodeinfo/node_info.go</a></p>

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

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

    return
}
</code></pre>

HamiBU
<p>In short, kubelet limit container resource usage by cgroup. You can search this by keyword <code>CgroupConfig</code>.</p>

<blockquote>
  <p>How kubernetes decides to allocate resources based on resource limits?</p>
</blockquote>

<p>Detail at <a href="https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/cm/helpers_linux.go#L109" rel="nofollow noreferrer">ResourceConfigForPod</a>.</p>
