func leastNUMAContainerScopeScore()

in pkg/noderesourcetopology/least_numa.go [37:76]


func leastNUMAContainerScopeScore(lh logr.Logger, pod *v1.Pod, zones topologyv1alpha2.ZoneList) (int64, *framework.Status) {
	nodes := createNUMANodeList(lh, zones)
	qos := v1qos.GetPodQOS(pod)

	maxNUMANodesCount := 0
	allContainersMinAvgDistance := true
	// the order how TopologyManager asks for hint is important so doing it in the same order
	// https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/cm/topologymanager/scope_container.go#L52
	for _, container := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
		// if a container requests only non NUMA just continue
		if onlyNonNUMAResources(nodes, container.Resources.Requests) {
			continue
		}
		numaNodes, isMinAvgDistance := numaNodesRequired(lh, qos, nodes, container.Resources.Requests)
		// container's resources can't fit onto node, return MinNodeScore for whole pod
		if numaNodes == nil {
			// score plugin should be running after resource filter plugin so we should always find sufficient amount of NUMA nodes
			lh.Info("cannot calculate how many NUMA nodes are required", "container", container.Name)
			return framework.MinNodeScore, nil
		}

		if !isMinAvgDistance {
			allContainersMinAvgDistance = false
		}

		if numaNodes.Count() > maxNUMANodesCount {
			maxNUMANodesCount = numaNodes.Count()
		}

		// subtract the resources requested by the container from the given NUMA.
		// this is necessary, so we won't allocate the same resources for the upcoming containers
		subtractFromNUMAs(container.Resources.Requests, nodes, numaNodes.GetBits()...)
	}

	if maxNUMANodesCount == 0 {
		return framework.MaxNodeScore, nil
	}

	return normalizeScore(maxNUMANodesCount, allContainersMinAvgDistance), nil
}