@@ -207,23 +207,6 @@ func getExpectedCPULimitFromCPUQuota(cpuQuota int64, podOnCgroupV2 bool) string
207207 return expectedCPULimitString
208208}
209209
210- func getExpectedCPUShares (rr * v1.ResourceRequirements , podOnCgroupv2 bool ) int64 {
211- cpuRequest := rr .Requests .Cpu ()
212- cpuLimit := rr .Limits .Cpu ()
213- var shares int64
214- if cpuRequest .IsZero () && ! cpuLimit .IsZero () {
215- shares = int64 (kubecm .MilliCPUToShares (cpuLimit .MilliValue ()))
216- } else {
217- shares = int64 (kubecm .MilliCPUToShares (cpuRequest .MilliValue ()))
218- }
219- if podOnCgroupv2 {
220- // TODO: This fomula should be a shared function.
221- return 1 + ((shares - 2 )* 9999 )/ 262142
222- } else {
223- return shares
224- }
225- }
226-
227210func getExpectedMemLimitString (rr * v1.ResourceRequirements , podOnCgroupv2 bool ) string {
228211 expectedMemLimitInBytes := rr .Limits .Memory ().Value ()
229212 expectedMemLimitString := strconv .FormatInt (expectedMemLimitInBytes , 10 )
@@ -236,7 +219,7 @@ func getExpectedMemLimitString(rr *v1.ResourceRequirements, podOnCgroupv2 bool)
236219func verifyContainerCPUWeight (f * framework.Framework , pod * v1.Pod , containerName string , expectedResources * v1.ResourceRequirements , podOnCgroupv2 bool ) error {
237220 cpuWeightCgPath := getCgroupCPURequestPath (cgroupFsPath , podOnCgroupv2 )
238221 expectedCPUShares := getExpectedCPUShares (expectedResources , podOnCgroupv2 )
239- if err := VerifyCgroupValue (f , pod , containerName , cpuWeightCgPath , strconv . FormatInt ( expectedCPUShares , 10 ) ); err != nil {
222+ if err := VerifyCgroupValue (f , pod , containerName , cpuWeightCgPath , expectedCPUShares ... ); err != nil {
240223 return fmt .Errorf ("failed to verify cpu request cgroup value: %w" , err )
241224 }
242225 return nil
@@ -286,7 +269,7 @@ func verifyPodCPUWeight(f *framework.Framework, pod *v1.Pod, expectedResources *
286269 cpuWeightCgPath = fmt .Sprintf ("%s/%s" , podCgPath , cgroupCPUSharesFile )
287270 }
288271 expectedCPUShares := getExpectedCPUShares (expectedResources , podOnCgroupv2 )
289- if err := VerifyCgroupValue (f , pod , pod .Spec .Containers [0 ].Name , cpuWeightCgPath , strconv . FormatInt ( expectedCPUShares , 10 ) ); err != nil {
272+ if err := VerifyCgroupValue (f , pod , pod .Spec .Containers [0 ].Name , cpuWeightCgPath , expectedCPUShares ... ); err != nil {
290273 return fmt .Errorf ("pod cgroup cpu weight verification failed: %w" , err )
291274 }
292275 return nil
0 commit comments