當前位置: 首頁>>代碼示例>>Golang>>正文


Golang schedulercache.Resource類代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/plugin/pkg/scheduler/schedulercache.Resource的典型用法代碼示例。如果您正苦於以下問題:Golang Resource類的具體用法?Golang Resource怎麽用?Golang Resource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Resource類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetResourceRequest

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
}
開發者ID:upmc-enterprises,項目名稱:kubernetes,代碼行數:54,代碼來源:predicates.go

示例2: getResourceRequest

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
}
開發者ID:RyanBinfeng,項目名稱:kubernetes,代碼行數:20,代碼來源:predicates.go


注:本文中的k8s/io/kubernetes/plugin/pkg/scheduler/schedulercache.Resource類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。