@@ -30,7 +30,6 @@ import (
3030 utilerrors "k8s.io/apimachinery/pkg/util/errors"
3131 helpers "k8s.io/component-helpers/resource"
3232 "k8s.io/kubectl/pkg/util/podutils"
33- kubecm "k8s.io/kubernetes/pkg/kubelet/cm"
3433 kubeqos "k8s.io/kubernetes/pkg/kubelet/qos"
3534 "k8s.io/kubernetes/test/e2e/framework"
3635 imageutils "k8s.io/kubernetes/test/utils/image"
@@ -305,10 +304,11 @@ func VerifyPodContainersCgroupValues(ctx context.Context, f *framework.Framework
305304 value := IsPodOnCgroupv2Node (f , pod )
306305 podOnCgroupv2Node = & value
307306 }
307+ podOnCgroupV2 := * podOnCgroupv2Node
308308 cgroupMemLimit := Cgroupv2MemLimit
309309 cgroupCPULimit := Cgroupv2CPULimit
310310 cgroupCPURequest := Cgroupv2CPURequest
311- if ! * podOnCgroupv2Node {
311+ if ! podOnCgroupV2 {
312312 cgroupMemLimit = CgroupMemLimit
313313 cgroupCPULimit = CgroupCPUQuota
314314 cgroupCPURequest = CgroupCPUShares
@@ -322,32 +322,23 @@ func VerifyPodContainersCgroupValues(ctx context.Context, f *framework.Framework
322322 tc := makeResizableContainer (ci )
323323 if tc .Resources .Limits != nil || tc .Resources .Requests != nil {
324324 var expectedCPUShares int64
325- var expectedMemLimitString string
326325 expectedMemLimitInBytes := tc .Resources .Limits .Memory ().Value ()
327326 cpuRequest := tc .Resources .Requests .Cpu ()
328327 cpuLimit := tc .Resources .Limits .Cpu ()
329- if cpuRequest .IsZero () && ! cpuLimit .IsZero () {
330- expectedCPUShares = int64 (kubecm .MilliCPUToShares (cpuLimit .MilliValue ()))
331- } else {
332- expectedCPUShares = int64 (kubecm .MilliCPUToShares (cpuRequest .MilliValue ()))
333- }
334-
328+ expectedCPUShares := getExpectedCPUShares (tc .Resources , podOnCgroupV2 )
335329 expectedCPULimits := GetCPULimitCgroupExpectations (cpuLimit )
336330 expectedMemLimitString = strconv .FormatInt (expectedMemLimitInBytes , 10 )
337- if * podOnCgroupv2Node {
331+ if podOnCgroupV2 {
338332 if expectedMemLimitString == "0" {
339333 expectedMemLimitString = "max"
340334 }
341- // convert cgroup v1 cpu.shares value to cgroup v2 cpu.weight value
342- // https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/2254-cgroup-v2#phase-1-convert-from-cgroups-v1-settings-to-v2
343- expectedCPUShares = int64 (1 + ((expectedCPUShares - 2 )* 9999 )/ 262142 )
344335 }
345336
346337 if expectedMemLimitString != "0" {
347338 errs = append (errs , VerifyCgroupValue (f , pod , ci .Name , cgroupMemLimit , expectedMemLimitString ))
348339 }
349340 errs = append (errs , VerifyCgroupValue (f , pod , ci .Name , cgroupCPULimit , expectedCPULimits ... ))
350- errs = append (errs , VerifyCgroupValue (f , pod , ci .Name , cgroupCPURequest , strconv . FormatInt ( expectedCPUShares , 10 ) ))
341+ errs = append (errs , VerifyCgroupValue (f , pod , ci .Name , cgroupCPURequest , expectedCPUShares ... ))
351342 // TODO(vinaykul,InPlacePodVerticalScaling): Verify oom_score_adj when runc adds support for updating it
352343 // See https://github.com/opencontainers/runc/pull/4669
353344 }
0 commit comments