示例#1
0
文件: algorithm.go 项目: 40a/bootkube
// limitPod limits the given pod based on the scheduler's default limits.
func (k *schedulerAlgorithm) limitPod(pod *api.Pod) error {
	cpuRequest, cpuLimit, _, err := resources.LimitPodCPU(pod, k.defaultCpus)
	if err != nil {
		return err
	}

	memRequest, memLimit, _, err := resources.LimitPodMem(pod, k.defaultMem)
	if err != nil {
		return err
	}

	log.V(3).Infof(
		"setting pod %s/%s resources: requested cpu %.2f mem %.2f MB, limited cpu %.2f mem %.2f MB",
		pod.Namespace, pod.Name, cpuRequest, memRequest, cpuLimit, memLimit,
	)

	return nil
}
示例#2
0
// StaticPodValidator discards a pod if we can't calculate resource limits for it.
func StaticPodValidator(
	defaultContainerCPULimit resources.CPUShares,
	defaultContainerMemLimit resources.MegaBytes,
	accumCPU, accumMem *float64,
) podutil.FilterFunc {
	return podutil.FilterFunc(func(pod *api.Pod) (bool, error) {
		_, cpu, _, err := resources.LimitPodCPU(pod, defaultContainerCPULimit)
		if err != nil {
			return false, err
		}

		_, mem, _, err := resources.LimitPodMem(pod, defaultContainerMemLimit)
		if err != nil {
			return false, err
		}

		log.V(2).Infof("reserving %.2f cpu shares and %.2f MB of memory to static pod %s/%s", cpu, mem, pod.Namespace, pod.Name)

		*accumCPU += float64(cpu)
		*accumMem += float64(mem)
		return true, nil
	})
}