Пример #1
0
// PodFitsResources calculates fit based on requested, rather than used resources
func (r *ResourceFit) PodFitsResources(pod api.Pod, existingPods []api.Pod, node string) (bool, error) {
	podRequest := getResourceRequest(&pod)
	if podRequest.milliCPU == 0 && podRequest.memory == 0 {
		// no resources requested always fits.
		return true, nil
	}
	info, err := r.info.GetNodeInfo(node)
	if err != nil {
		return false, err
	}
	milliCPURequested := 0
	memoryRequested := 0
	for ix := range existingPods {
		existingRequest := getResourceRequest(&existingPods[ix])
		milliCPURequested += existingRequest.milliCPU
		memoryRequested += existingRequest.memory
	}

	// TODO: convert to general purpose resource matching, when pods ask for resources
	totalMilliCPU := int(resources.GetFloatResource(info.NodeResources.Capacity, resources.CPU, 0) * 1000)
	totalMemory := resources.GetIntegerResource(info.NodeResources.Capacity, resources.Memory, 0)

	fitsCPU := totalMilliCPU == 0 || (totalMilliCPU-milliCPURequested) >= podRequest.milliCPU
	fitsMemory := totalMemory == 0 || (totalMemory-memoryRequested) >= podRequest.memory
	glog.V(3).Infof("Calculated fit: cpu: %s, memory %s", fitsCPU, fitsMemory)

	return fitsCPU && fitsMemory, nil
}
Пример #2
0
// PodFitsResources calculates fit based on requested, rather than used resources
func (r *ResourceFit) PodFitsResources(pod api.Pod, existingPods []api.Pod, node string) (bool, error) {
	podRequest := getResourceRequest(&pod)
	if podRequest.milliCPU == 0 && podRequest.memory == 0 {
		// no resources requested always fits.
		return true, nil
	}
	info, err := r.info.GetNodeInfo(node)
	if err != nil {
		return false, err
	}

	// check wether exsit free VM, only for bridge mode
	vmNum := len(info.Spec.VMs)
	if pod.Spec.NetworkMode == api.PodNetworkModeBridge && vmNum <= len(existingPods) {
		return false, nil
	}

	milliCPURequested := 0
	memoryRequested := 0
	coreRequested := 0
	diskRequested := 0
	for ix := range existingPods {
		existingRequest := getResourceRequest(&existingPods[ix])
		milliCPURequested += existingRequest.milliCPU
		memoryRequested += existingRequest.memory
		coreRequested += existingRequest.core
		diskRequested += existingRequest.disk
	}

	// TODO: convert to general purpose resource matching, when pods ask for resources
	totalMilliCPU := int(resources.GetFloatResource(info.Spec.Capacity, resources.CPU, 0) * 1000)
	totalMemory := resources.GetIntegerResource(info.Spec.Capacity, resources.Memory, 0)
	totalCore := resources.GetIntegerResource(info.Spec.Capacity, resources.Core, 0)
	totalDisk := resources.GetIntegerResource(info.Spec.Capacity, resources.Disk, 0)

	fitsCPU := totalMilliCPU == 0 || (totalMilliCPU-milliCPURequested) >= podRequest.milliCPU
	fitsMemory := totalMemory == 0 || (totalMemory-memoryRequested) >= podRequest.memory
	fitsCore := totalCore == 0 || (totalCore-coreRequested) >= podRequest.core
	fitsDisk := totalDisk == 0 || (totalDisk-diskRequested) >= podRequest.disk
	glog.V(3).Infof("Calculated fit: cpu: %s, memory %s, core: %s, disk: %s", fitsCPU, fitsMemory, fitsCore, fitsDisk)

	return fitsCPU && fitsMemory && fitsCore && fitsDisk, nil
}