func CheckPodsExceedingFreeResources(pods []*api.Pod, capacity api.ResourceList) (fitting []*api.Pod, notFittingCPU, notFittingMemory []*api.Pod) { totalMilliCPU := capacity.Cpu().MilliValue() totalMemory := capacity.Memory().Value() milliCPURequested := int64(0) memoryRequested := int64(0) for _, pod := range pods { podRequest := getResourceRequest(pod) fitsCPU := totalMilliCPU == 0 || (totalMilliCPU-milliCPURequested) >= podRequest.milliCPU fitsMemory := totalMemory == 0 || (totalMemory-memoryRequested) >= podRequest.memory 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 } // the pod fits milliCPURequested += podRequest.milliCPU memoryRequested += podRequest.memory fitting = append(fitting, pod) } return }
// TODO: Consider setting default as a fixed fraction of machine capacity (take "capacity api.ResourceList" // as an additional argument here) rather than using constants func getNonzeroRequests(requests *api.ResourceList) (int64, int64) { var out_millicpu, out_memory int64 // Override if un-set, but not if explicitly set to zero if (*requests.Cpu() == resource.Quantity{}) { out_millicpu = defaultMilliCpuRequest } else { out_millicpu = requests.Cpu().MilliValue() } // Override if un-set, but not if explicitly set to zero if (*requests.Memory() == resource.Quantity{}) { out_memory = defaultMemoryRequest } else { out_memory = requests.Memory().Value() } return out_millicpu, out_memory }
func (cm *containerManagerImpl) setupNode() error { if err := validateSystemRequirements(cm.mountUtil); err != nil { return err } // TODO: plumb kernel tunable options into container manager, right now, we modify by default if err := setupKernelTunables(KernelTunableModify); err != nil { return err } systemContainers := []*systemContainer{} if cm.dockerDaemonContainerName != "" { cont := newSystemContainer(cm.dockerDaemonContainerName) info, err := cm.cadvisorInterface.MachineInfo() var capacity = api.ResourceList{} if err != nil { } else { capacity = CapacityFromMachineInfo(info) } memoryLimit := (int64(capacity.Memory().Value() * DockerMemoryLimitThresholdPercent / 100)) if memoryLimit < MinDockerMemoryLimit { glog.Warningf("Memory limit %d for container %s is too small, reset it to %d", memoryLimit, cm.dockerDaemonContainerName, MinDockerMemoryLimit) memoryLimit = MinDockerMemoryLimit } glog.V(2).Infof("Configure resource-only container %s with memory limit: %d", cm.dockerDaemonContainerName, memoryLimit) dockerContainer := &fs.Manager{ Cgroups: &configs.Cgroup{ Name: cm.dockerDaemonContainerName, Memory: memoryLimit, MemorySwap: -1, AllowAllDevices: true, }, } cont.ensureStateFunc = func(manager *fs.Manager) error { return ensureDockerInContainer(cm.cadvisorInterface, -900, dockerContainer) } systemContainers = append(systemContainers, cont) } if cm.systemContainerName != "" { if cm.systemContainerName == "/" { return fmt.Errorf("system container cannot be root (\"/\")") } rootContainer := &fs.Manager{ Cgroups: &configs.Cgroup{ Name: "/", }, } manager := createManager(cm.systemContainerName) err := ensureSystemContainer(rootContainer, manager) if err != nil { return err } systemContainers = append(systemContainers, newSystemContainer(cm.systemContainerName)) } if cm.kubeletContainerName != "" { systemContainers = append(systemContainers, newSystemContainer(cm.kubeletContainerName)) } cm.systemContainers = systemContainers return nil }