From bc7d254317cf64b64d29c05862c88d0da6c84474 Mon Sep 17 00:00:00 2001 From: Adelina Tuvenie Date: Tue, 3 Dec 2019 15:14:29 +0200 Subject: [PATCH] Fix Cpu Requests priority Windows. For Windows, CPU Requests ( Shares, Count and Maximum ) are mutually exclusive, however Kubernetes sends them all anyway in the pod spec. When using dockershim this is not an issue, as Docker checks for this specific situation here: https://github.com/moby/moby/blob/1bd184a4c291e4f60629e2cc279216f8f40495f3/daemon/daemon_windows.go#L87-L106 However, when using CRI-Containerd this pods fail to spawn with an error from hcsshim. This PR intends to filter these values before they are sent to the CRI and not rely on the runtime for it. Related to: https://github.com/kubernetes/kubernetes/issues/84804 --- .../kuberuntime_container_windows.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container_windows.go b/pkg/kubelet/kuberuntime/kuberuntime_container_windows.go index 6f858b7482e..5501592b8ef 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_container_windows.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_container_windows.go @@ -28,6 +28,8 @@ import ( kubefeatures "k8s.io/kubernetes/pkg/features" kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis" "k8s.io/kubernetes/pkg/securitycontext" + + "k8s.io/klog" ) // applyPlatformSpecificContainerConfig applies platform specific configurations to runtimeapi.ContainerConfig. @@ -82,6 +84,28 @@ func (m *kubeGenericRuntimeManager) generateWindowsContainerConfig(container *v1 } wc.Resources.CpuShares = cpuShares + if !isolatedByHyperv { + // The processor resource controls are mutually exclusive on + // Windows Server Containers, the order of precedence is + // CPUCount first, then CPUShares, and CPUMaximum last. + if wc.Resources.CpuCount > 0 { + if wc.Resources.CpuShares > 0 { + wc.Resources.CpuShares = 0 + klog.Warningf("Mutually exclusive options: CPUCount priority > CPUShares priority on Windows Server Containers. CPUShares should be ignored") + } + if wc.Resources.CpuMaximum > 0 { + wc.Resources.CpuMaximum = 0 + klog.Warningf("Mutually exclusive options: CPUCount priority > CPUMaximum priority on Windows Server Containers. CPUMaximum should be ignored") + } + } else if wc.Resources.CpuShares > 0 { + if wc.Resources.CpuMaximum > 0 { + wc.Resources.CpuMaximum = 0 + klog.Warningf("Mutually exclusive options: CPUShares priority > CPUMaximum priority on Windows Server Containers. CPUMaximum should be ignored") + } + + } + } + memoryLimit := container.Resources.Limits.Memory().Value() if memoryLimit != 0 { wc.Resources.MemoryLimitInBytes = memoryLimit