func GetResourceRequest(pod *api.Pod) *schedulercache.Resource {
	result := schedulercache.Resource{}
	for _, container := range pod.Spec.Containers {
		for rName, rQuantity := range container.Resources.Requests {
			switch rName {
			case api.ResourceMemory:
				result.Memory += rQuantity.Value()
			case api.ResourceCPU:
				result.MilliCPU += rQuantity.MilliValue()
			case api.ResourceNvidiaGPU:
				result.NvidiaGPU += rQuantity.Value()
			default:
				if api.IsOpaqueIntResourceName(rName) {
					// Lazily allocate this map only if required.
					if result.OpaqueIntResources == nil {
						result.OpaqueIntResources = map[api.ResourceName]int64{}
					}
					result.OpaqueIntResources[rName] += rQuantity.Value()
				}
			}
		}
	}
	// take max_resource(sum_pod, any_init_container)
	for _, container := range pod.Spec.InitContainers {
		for rName, rQuantity := range container.Resources.Requests {
			switch rName {
			case api.ResourceMemory:
				if mem := rQuantity.Value(); mem > result.Memory {
					result.Memory = mem
				}
			case api.ResourceCPU:
				if cpu := rQuantity.MilliValue(); cpu > result.MilliCPU {
					result.MilliCPU = cpu
				}
			case api.ResourceNvidiaGPU:
				if gpu := rQuantity.Value(); gpu > result.NvidiaGPU {
					result.NvidiaGPU = gpu
				}
			default:
				if api.IsOpaqueIntResourceName(rName) {
					// Lazily allocate this map only if required.
					if result.OpaqueIntResources == nil {
						result.OpaqueIntResources = map[api.ResourceName]int64{}
					}
					value := rQuantity.Value()
					if value > result.OpaqueIntResources[rName] {
						result.OpaqueIntResources[rName] = value
					}
				}
			}
		}
	}
	return &result
}
Exemple #2
0
func getResourceRequest(pod *api.Pod) *schedulercache.Resource {
	result := schedulercache.Resource{}
	for _, container := range pod.Spec.Containers {
		requests := container.Resources.Requests
		result.Memory += requests.Memory().Value()
		result.MilliCPU += requests.Cpu().MilliValue()
		result.NvidiaGPU += requests.NvidiaGPU().Value()
	}
	// take max_resource(sum_pod, any_init_container)
	for _, container := range pod.Spec.InitContainers {
		requests := container.Resources.Requests
		if mem := requests.Memory().Value(); mem > result.Memory {
			result.Memory = mem
		}
		if cpu := requests.Cpu().MilliValue(); cpu > result.MilliCPU {
			result.MilliCPU = cpu
		}
	}
	return &result
}