<p>I'm trying to find out how kubernetes calculates the allocation of resources? Actually, I cannot find it in the source code.
In kubernetes official documentation, allocatable has been calculated as [Allocatable] = [Node Capacity] - [Kube-Reserved] - [System-Reserved] - [Hard-Eviction-Threshold]. Could you please help me to find the related source codes in kubernetes which is in github? </p>

<p>Actually, I would like to change the allocation policy in kubernetes and I need to find the related codes.</p>

<p>Cheers</p>

HamiBU
<p>There are a couple of options:</p>

<ul>
<li><p><strong>The scheduler uses the value of node.Status.Allocatable instead of node.Status.Capacity to decide if a node will become a candidate for pod scheduling.</strong>  So one thing is to do custom stuff , is to bypass the schedular and specify your own schedular.</p></li>
<li><p>The second option is to change the values and options used by kubelet. <a href="https://docs.okd.io/latest/admin_guide/allocating_node_resources.html" rel="nofollow noreferrer">details</a></p></li>
</ul>

<blockquote>
  <p>You can set these in the kubeletArguments section of the node
  configuration map by using a set of
  = pairs (e.g.,
  cpu=200m,memory=512Mi). Add the section if it does not already exist</p>
</blockquote>

<ul>
<li>Maybe the last option you are looking for is to change the code , the way things are calculated.</li>
</ul>

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

<p>start from here:</p>

<pre><code>// AllocatableResource returns allocatable resources on a given node.
func (n *NodeInfo) AllocatableResource() Resource {
    if n == nil {
        return emptyResource
    }
    return *n.allocatableResource
}
</code></pre>

<p>here is a portion of schedular that uses that info:</p>

<pre><code>if allocatable.Memory &lt; podRequest.Memory+nodeInfo.RequestedResource().Memory {
        predicateFails = append(predicateFails, NewInsufficientResourceError(v1.ResourceMemory, podRequest.Memory, nodeInfo.RequestedResource().Memory, allocatable.Memory))
    }
</code></pre>

<p><a href="https://github.com/kubernetes/kubernetes/blob/788f24583e95ac47938a41daaf1f1efc58153738/pkg/scheduler/algorithm/predicates/predicates.go" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/blob/788f24583e95ac47938a41daaf1f1efc58153738/pkg/scheduler/algorithm/predicates/predicates.go</a></p>
