@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- package pod
17
+ package podresize
18
18
19
19
import (
20
20
"context"
@@ -33,6 +33,7 @@ import (
33
33
kubecm "k8s.io/kubernetes/pkg/kubelet/cm"
34
34
kubeqos "k8s.io/kubernetes/pkg/kubelet/qos"
35
35
"k8s.io/kubernetes/test/e2e/framework"
36
+ e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
36
37
imageutils "k8s.io/kubernetes/test/utils/image"
37
38
38
39
"github.com/onsi/ginkgo/v2"
@@ -302,7 +303,7 @@ func verifyPodContainersStatusResources(gotCtrStatuses []v1.ContainerStatus, wan
302
303
func VerifyPodContainersCgroupValues (ctx context.Context , f * framework.Framework , pod * v1.Pod , tcInfo []ResizableContainerInfo ) error {
303
304
ginkgo .GinkgoHelper ()
304
305
if podOnCgroupv2Node == nil {
305
- value := IsPodOnCgroupv2Node (f , pod )
306
+ value := e2epod . IsPodOnCgroupv2Node (f , pod )
306
307
podOnCgroupv2Node = & value
307
308
}
308
309
cgroupMemLimit := Cgroupv2MemLimit
@@ -344,10 +345,10 @@ func VerifyPodContainersCgroupValues(ctx context.Context, f *framework.Framework
344
345
}
345
346
346
347
if expectedMemLimitString != "0" {
347
- errs = append (errs , VerifyCgroupValue (f , pod , ci .Name , cgroupMemLimit , expectedMemLimitString ))
348
+ errs = append (errs , e2epod . VerifyCgroupValue (f , pod , ci .Name , cgroupMemLimit , expectedMemLimitString ))
348
349
}
349
- errs = append (errs , VerifyCgroupValue (f , pod , ci .Name , cgroupCPULimit , expectedCPULimits ... ))
350
- errs = append (errs , VerifyCgroupValue (f , pod , ci .Name , cgroupCPURequest , strconv .FormatInt (expectedCPUShares , 10 )))
350
+ errs = append (errs , e2epod . VerifyCgroupValue (f , pod , ci .Name , cgroupCPULimit , expectedCPULimits ... ))
351
+ errs = append (errs , e2epod . VerifyCgroupValue (f , pod , ci .Name , cgroupCPURequest , strconv .FormatInt (expectedCPUShares , 10 )))
351
352
// TODO(vinaykul,InPlacePodVerticalScaling): Verify oom_score_adj when runc adds support for updating it
352
353
// See https://github.com/opencontainers/runc/pull/4669
353
354
}
@@ -393,7 +394,7 @@ func verifyContainerRestarts(f *framework.Framework, pod *v1.Pod, gotStatuses []
393
394
}
394
395
395
396
func verifyOomScoreAdj (f * framework.Framework , pod * v1.Pod , containerName string ) error {
396
- container := FindContainerInPod (pod , containerName )
397
+ container := e2epod . FindContainerInPod (pod , containerName )
397
398
if container == nil {
398
399
return fmt .Errorf ("failed to find container %s in pod %s" , containerName , pod .Name )
399
400
}
@@ -407,10 +408,10 @@ func verifyOomScoreAdj(f *framework.Framework, pod *v1.Pod, containerName string
407
408
oomScoreAdj := kubeqos .GetContainerOOMScoreAdjust (pod , container , int64 (nodeMemoryCapacity .Value ()))
408
409
expectedOomScoreAdj := strconv .FormatInt (int64 (oomScoreAdj ), 10 )
409
410
410
- return VerifyOomScoreAdjValue (f , pod , container .Name , expectedOomScoreAdj )
411
+ return e2epod . VerifyOomScoreAdjValue (f , pod , container .Name , expectedOomScoreAdj )
411
412
}
412
413
413
- func WaitForPodResizeActuation (ctx context.Context , f * framework.Framework , podClient * PodClient , pod * v1.Pod , expectedContainers []ResizableContainerInfo ) * v1.Pod {
414
+ func WaitForPodResizeActuation (ctx context.Context , f * framework.Framework , podClient * e2epod. PodClient , pod * v1.Pod , expectedContainers []ResizableContainerInfo ) * v1.Pod {
414
415
ginkgo .GinkgoHelper ()
415
416
// Wait for resize to complete.
416
417
@@ -535,3 +536,35 @@ func formatErrors(err error) error {
535
536
}
536
537
return fmt .Errorf ("[\n %s\n ]" , strings .Join (errStrings , ",\n " ))
537
538
}
539
+
540
+ // TODO: Remove the rounded cpu limit values when https://github.com/opencontainers/runc/issues/4622
541
+ // is fixed.
542
+ func GetCPULimitCgroupExpectations (cpuLimit * resource.Quantity ) []string {
543
+ var expectedCPULimits []string
544
+ milliCPULimit := cpuLimit .MilliValue ()
545
+
546
+ cpuQuota := kubecm .MilliCPUToQuota (milliCPULimit , kubecm .QuotaPeriod )
547
+ if cpuLimit .IsZero () {
548
+ cpuQuota = - 1
549
+ }
550
+ expectedCPULimits = append (expectedCPULimits , getExpectedCPULimitFromCPUQuota (cpuQuota ))
551
+
552
+ if milliCPULimit % 10 != 0 && cpuQuota != - 1 {
553
+ roundedCPULimit := (milliCPULimit / 10 + 1 ) * 10
554
+ cpuQuotaRounded := kubecm .MilliCPUToQuota (roundedCPULimit , kubecm .QuotaPeriod )
555
+ expectedCPULimits = append (expectedCPULimits , getExpectedCPULimitFromCPUQuota (cpuQuotaRounded ))
556
+ }
557
+
558
+ return expectedCPULimits
559
+ }
560
+
561
+ func getExpectedCPULimitFromCPUQuota (cpuQuota int64 ) string {
562
+ expectedCPULimitString := strconv .FormatInt (cpuQuota , 10 )
563
+ if * podOnCgroupv2Node {
564
+ if expectedCPULimitString == "-1" {
565
+ expectedCPULimitString = "max"
566
+ }
567
+ expectedCPULimitString = fmt .Sprintf ("%s %s" , expectedCPULimitString , CPUPeriod )
568
+ }
569
+ return expectedCPULimitString
570
+ }
0 commit comments