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


Golang ResourceList.NvidiaGPU方法代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/api.ResourceList.NvidiaGPU方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResourceList.NvidiaGPU方法的具體用法?Golang ResourceList.NvidiaGPU怎麽用?Golang ResourceList.NvidiaGPU使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在k8s/io/kubernetes/pkg/api.ResourceList的用法示例。


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

示例1: CheckPodsExceedingFreeResources

func CheckPodsExceedingFreeResources(pods []*api.Pod, allocatable api.ResourceList) (fitting []*api.Pod, notFittingCPU, notFittingMemory, notFittingNvidiaGPU []*api.Pod) {
	totalMilliCPU := allocatable.Cpu().MilliValue()
	totalMemory := allocatable.Memory().Value()
	totalNvidiaGPU := allocatable.NvidiaGPU().Value()
	milliCPURequested := int64(0)
	memoryRequested := int64(0)
	nvidiaGPURequested := int64(0)
	for _, pod := range pods {
		podRequest := getResourceRequest(pod)
		fitsCPU := (totalMilliCPU - milliCPURequested) >= podRequest.milliCPU
		fitsMemory := (totalMemory - memoryRequested) >= podRequest.memory
		fitsNVidiaGPU := (totalNvidiaGPU - nvidiaGPURequested) >= podRequest.nvidiaGPU
		if !fitsCPU {
			// the pod doesn't fit due to CPU request
			notFittingCPU = append(notFittingCPU, pod)
			continue
		}
		if !fitsMemory {
			// the pod doesn't fit due to Memory request
			notFittingMemory = append(notFittingMemory, pod)
			continue
		}
		if !fitsNVidiaGPU {
			// the pod doesn't fit due to NvidiaGPU request
			notFittingNvidiaGPU = append(notFittingNvidiaGPU, pod)
			continue
		}
		// the pod fits
		milliCPURequested += podRequest.milliCPU
		memoryRequested += podRequest.memory
		nvidiaGPURequested += podRequest.nvidiaGPU
		fitting = append(fitting, pod)
	}
	return
}
開發者ID:shmurata,項目名稱:kubernetes,代碼行數:35,代碼來源:predicates.go


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