func singleNUMAContainerLevelHandler()

in pkg/noderesourcetopology/filter.go [44:85]


func singleNUMAContainerLevelHandler(lh logr.Logger, pod *v1.Pod, zones topologyv1alpha2.ZoneList, nodeInfo *framework.NodeInfo) *framework.Status {
	lh.V(5).Info("container level single NUMA node handler")

	// prepare NUMANodes list from zoneMap
	nodes := createNUMANodeList(lh, zones)
	qos := v1qos.GetPodQOS(pod)

	// Node() != nil already verified in Filter(), which is the only public entry point
	logNumaNodes(lh, "container handler NUMA resources", nodeInfo.Node().Name, nodes)

	// the init containers are running SERIALLY and BEFORE the normal containers.
	// https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#understanding-init-containers
	// therefore, we don't need to accumulate their resources together
	for _, initContainer := range pod.Spec.InitContainers {
		lh.V(6).Info("init container desired resources", stringify.ResourceListToLoggable(initContainer.Resources.Requests)...)

		_, match := resourcesAvailableInAnyNUMANodes(lh, nodes, initContainer.Resources.Requests, qos, nodeInfo)
		if !match {
			// we can't align init container, so definitely we can't align a pod
			lh.V(2).Info("cannot align container", "name", initContainer.Name, "kind", "init")
			return framework.NewStatus(framework.Unschedulable, "cannot align init container")
		}
	}

	for _, container := range pod.Spec.Containers {
		// TODO: add containerName
		lh.V(6).Info("app container resources", stringify.ResourceListToLoggable(container.Resources.Requests)...)

		numaID, match := resourcesAvailableInAnyNUMANodes(lh, nodes, container.Resources.Requests, qos, nodeInfo)
		if !match {
			// we can't align container, so definitely we can't align a pod
			lh.V(2).Info("cannot align container", "name", container.Name, "kind", "app")
			return framework.NewStatus(framework.Unschedulable, "cannot align container")
		}

		// 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
		subtractFromNUMA(lh, nodes, numaID, container)
	}
	lh.V(2).Info("can align all containers")
	return nil
}