From f2d591fae62822a8e96b0e015e6e42224286b5d5 Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Fri, 29 Jul 2022 23:11:25 +0200 Subject: [PATCH] change CPUCFSQuotaPeriod default value to 100us to match Linux default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cpu.cfs_period_us is 100μs by default despite having an "ms" unit for some unfortunate reason. Documentation: https://www.kernel.org/doc/html/latest/scheduler/sched-bwc.html#management The desired effect of that change is to match k8s default `CPUCFSQuotaPeriod` value (100ms before that change) with one used in k8s without the `CustomCPUCFSQuotaPeriod` flag enabled and Linux CFS (100us, 1000x smaller than 100ms). --- pkg/generated/openapi/zz_generated.openapi.go | 2 +- .../scheme/testdata/KubeletConfiguration/after/v1beta1.yaml | 2 +- .../KubeletConfiguration/roundtrip/default/v1beta1.yaml | 2 +- pkg/kubelet/apis/config/types.go | 2 +- pkg/kubelet/apis/config/v1beta1/defaults.go | 2 +- pkg/kubelet/apis/config/v1beta1/defaults_test.go | 4 ++-- pkg/kubelet/apis/config/validation/validation.go | 2 +- pkg/kubelet/kuberuntime/kuberuntime_manager.go | 4 ++-- staging/src/k8s.io/kubelet/config/v1beta1/types.go | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index da23aa5b6cd..078099339b5 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -54495,7 +54495,7 @@ func schema_k8sio_kubelet_config_v1beta1_KubeletConfiguration(ref common.Referen }, "cpuCFSQuotaPeriod": { SchemaProps: spec.SchemaProps{ - Description: "cpuCFSQuotaPeriod is the CPU CFS quota period value, `cpu.cfs_period_us`. The value must be between 1 us and 1 second, inclusive. Requires the CustomCPUCFSQuotaPeriod feature gate to be enabled. Default: \"100ms\"", + Description: "cpuCFSQuotaPeriod is the CPU CFS quota period value, `cpu.cfs_period_us`. The value must be between 1 us and 1 second, inclusive. Requires the CustomCPUCFSQuotaPeriod feature gate to be enabled. Default: \"100µs\"", Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Duration"), }, }, diff --git a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml index a1a6cd6367e..8d14fb2939f 100644 --- a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml +++ b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/after/v1beta1.yaml @@ -19,7 +19,7 @@ containerLogMaxFiles: 5 containerLogMaxSize: 10Mi contentType: application/vnd.kubernetes.protobuf cpuCFSQuota: true -cpuCFSQuotaPeriod: 100ms +cpuCFSQuotaPeriod: 100µs cpuManagerPolicy: none cpuManagerReconcilePeriod: 10s enableControllerAttachDetach: true diff --git a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml index a1a6cd6367e..8d14fb2939f 100644 --- a/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml +++ b/pkg/kubelet/apis/config/scheme/testdata/KubeletConfiguration/roundtrip/default/v1beta1.yaml @@ -19,7 +19,7 @@ containerLogMaxFiles: 5 containerLogMaxSize: 10Mi contentType: application/vnd.kubernetes.protobuf cpuCFSQuota: true -cpuCFSQuotaPeriod: 100ms +cpuCFSQuotaPeriod: 100µs cpuManagerPolicy: none cpuManagerReconcilePeriod: 10s enableControllerAttachDetach: true diff --git a/pkg/kubelet/apis/config/types.go b/pkg/kubelet/apis/config/types.go index 0ec23416fab..e0aff1e83ba 100644 --- a/pkg/kubelet/apis/config/types.go +++ b/pkg/kubelet/apis/config/types.go @@ -273,7 +273,7 @@ type KubeletConfiguration struct { // cpuCFSQuota enables CPU CFS quota enforcement for containers that // specify CPU limits CPUCFSQuota bool - // CPUCFSQuotaPeriod sets the CPU CFS quota period value, cpu.cfs_period_us, defaults to 100ms + // CPUCFSQuotaPeriod sets the CPU CFS quota period value, cpu.cfs_period_us, defaults to 100µs CPUCFSQuotaPeriod metav1.Duration // maxOpenFiles is Number of files that can be opened by Kubelet process. MaxOpenFiles int64 diff --git a/pkg/kubelet/apis/config/v1beta1/defaults.go b/pkg/kubelet/apis/config/v1beta1/defaults.go index 82315403081..331eb7edb92 100644 --- a/pkg/kubelet/apis/config/v1beta1/defaults.go +++ b/pkg/kubelet/apis/config/v1beta1/defaults.go @@ -188,7 +188,7 @@ func SetDefaults_KubeletConfiguration(obj *kubeletconfigv1beta1.KubeletConfigura obj.CPUCFSQuota = utilpointer.BoolPtr(true) } if obj.CPUCFSQuotaPeriod == nil { - obj.CPUCFSQuotaPeriod = &metav1.Duration{Duration: 100 * time.Millisecond} + obj.CPUCFSQuotaPeriod = &metav1.Duration{Duration: 100 * time.Microsecond} } if obj.NodeStatusMaxImages == nil { obj.NodeStatusMaxImages = utilpointer.Int32Ptr(50) diff --git a/pkg/kubelet/apis/config/v1beta1/defaults_test.go b/pkg/kubelet/apis/config/v1beta1/defaults_test.go index e16b3698624..f51b710eb2f 100644 --- a/pkg/kubelet/apis/config/v1beta1/defaults_test.go +++ b/pkg/kubelet/apis/config/v1beta1/defaults_test.go @@ -92,7 +92,7 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) { PodPidsLimit: utilpointer.Int64(-1), ResolverConfig: utilpointer.String(kubetypes.ResolvConfDefault), CPUCFSQuota: utilpointer.BoolPtr(true), - CPUCFSQuotaPeriod: &metav1.Duration{Duration: 100 * time.Millisecond}, + CPUCFSQuotaPeriod: &metav1.Duration{Duration: 100 * time.Microsecond}, NodeStatusMaxImages: utilpointer.Int32Ptr(50), MaxOpenFiles: 1000000, ContentType: "application/vnd.kubernetes.protobuf", @@ -691,7 +691,7 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) { PodPidsLimit: utilpointer.Int64(-1), ResolverConfig: utilpointer.String(kubetypes.ResolvConfDefault), CPUCFSQuota: utilpointer.BoolPtr(true), - CPUCFSQuotaPeriod: &metav1.Duration{Duration: 100 * time.Millisecond}, + CPUCFSQuotaPeriod: &metav1.Duration{Duration: 100 * time.Microsecond}, NodeStatusMaxImages: utilpointer.Int32Ptr(50), MaxOpenFiles: 1000000, ContentType: "application/vnd.kubernetes.protobuf", diff --git a/pkg/kubelet/apis/config/validation/validation.go b/pkg/kubelet/apis/config/validation/validation.go index afd43d70b8e..cc200d410f0 100644 --- a/pkg/kubelet/apis/config/validation/validation.go +++ b/pkg/kubelet/apis/config/validation/validation.go @@ -36,7 +36,7 @@ import ( ) var ( - defaultCFSQuota = metav1.Duration{Duration: 100 * time.Millisecond} + defaultCFSQuota = metav1.Duration{Duration: 100 * time.Microsecond} ) // ValidateKubeletConfiguration validates `kc` and returns an error if it is invalid diff --git a/pkg/kubelet/kuberuntime/kuberuntime_manager.go b/pkg/kubelet/kuberuntime/kuberuntime_manager.go index 89eaf8b4fcd..09d811d1d74 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_manager.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_manager.go @@ -115,7 +115,7 @@ type kubeGenericRuntimeManager struct { // If true, enforce container cpu limits with CFS quota support cpuCFSQuota bool - // CPUCFSQuotaPeriod sets the CPU CFS quota period value, cpu.cfs_period_us, defaults to 100ms + // CPUCFSQuotaPeriod sets the CPU CFS quota period value, cpu.cfs_period_us, defaults to 100µs cpuCFSQuotaPeriod metav1.Duration // wrapped image puller. @@ -152,7 +152,7 @@ type kubeGenericRuntimeManager struct { // MemorySwapBehavior defines how swap is used memorySwapBehavior string - //Function to get node allocatable resources + // Function to get node allocatable resources getNodeAllocatable func() v1.ResourceList // Memory throttling factor for MemoryQoS diff --git a/staging/src/k8s.io/kubelet/config/v1beta1/types.go b/staging/src/k8s.io/kubelet/config/v1beta1/types.go index aa67206ee40..ecc088aa80b 100644 --- a/staging/src/k8s.io/kubelet/config/v1beta1/types.go +++ b/staging/src/k8s.io/kubelet/config/v1beta1/types.go @@ -442,7 +442,7 @@ type KubeletConfiguration struct { // cpuCFSQuotaPeriod is the CPU CFS quota period value, `cpu.cfs_period_us`. // The value must be between 1 us and 1 second, inclusive. // Requires the CustomCPUCFSQuotaPeriod feature gate to be enabled. - // Default: "100ms" + // Default: "100µs" // +optional CPUCFSQuotaPeriod *metav1.Duration `json:"cpuCFSQuotaPeriod,omitempty"` // nodeStatusMaxImages caps the number of images reported in Node.status.images.