@@ -596,18 +596,27 @@ func runCfsQuotaGuPods(ctx context.Context, f *framework.Framework, disabledCPUQ
596
596
var err error
597
597
var ctnAttrs []ctnAttribute
598
598
var pod1 , pod2 , pod3 * v1.Pod
599
- var cleanupPods []* v1.Pod
600
- ginkgo .DeferCleanup (func () {
599
+ podsToClean := make (map [string ]* v1.Pod ) // pod.UID -> pod
600
+
601
+ deleteTestPod := func (pod * v1.Pod ) {
601
602
// waitForContainerRemoval takes "long" to complete; if we use the parent ctx we get a
602
603
// 'deadline expired' message and the cleanup aborts, which we don't want.
603
- ctx2 := context .TODO ()
604
+ // So let's use a separate and more generous timeout (determined by trial and error)
605
+ ctx2 , cancel := context .WithTimeout (context .Background (), 10 * time .Minute )
606
+ defer cancel ()
607
+ deletePodSyncAndWait (ctx2 , f , pod .Namespace , pod .Name )
608
+ delete (podsToClean , string (pod .UID ))
609
+ }
610
+
611
+ // cleanup leftovers on test failure. The happy path is covered by `deleteTestPod` calls
612
+ ginkgo .DeferCleanup (func () {
604
613
ginkgo .By ("by deleting the pods and waiting for container removal" )
605
- for _ , cleanupPod := range cleanupPods {
606
- framework . Logf ( "deleting pod: %s/%s" , cleanupPod . Namespace , cleanupPod . Name )
607
- deletePodSyncByName ( ctx2 , f , cleanupPod . Name )
608
- waitForContainerRemoval ( ctx2 , cleanupPod . Spec . Containers [ 0 ]. Name , cleanupPod . Name , cleanupPod . Namespace )
609
- framework . Logf ( "deleted pod: %s/%s" , cleanupPod . Namespace , cleanupPod . Name )
610
- }
614
+ // waitForContainerRemoval takes "long" to complete; if we use the parent ctx we get a
615
+ // 'deadline expired' message and the cleanup aborts, which we don't want.
616
+ // So let's use a separate and more generous timeout (determined by trial and error )
617
+ ctx2 , cancel := context . WithTimeout ( context . Background (), 10 * time . Minute )
618
+ defer cancel ( )
619
+ deletePodsAsync ( ctx2 , f , podsToClean )
611
620
})
612
621
613
622
cfsCheckCommand := []string {"sh" , "-c" , "cat /sys/fs/cgroup/cpu.max && sleep 1d" }
@@ -623,7 +632,7 @@ func runCfsQuotaGuPods(ctx context.Context, f *framework.Framework, disabledCPUQ
623
632
pod1 = makeCPUManagerPod ("gu-pod1" , ctnAttrs )
624
633
pod1 .Spec .Containers [0 ].Command = cfsCheckCommand
625
634
pod1 = e2epod .NewPodClient (f ).CreateSync (ctx , pod1 )
626
- cleanupPods = append ( cleanupPods , pod1 )
635
+ podsToClean [ string ( pod1 . UID )] = pod1
627
636
628
637
ginkgo .By ("checking if the expected cfs quota was assigned (GU pod, exclusive CPUs, unlimited)" )
629
638
@@ -635,6 +644,7 @@ func runCfsQuotaGuPods(ctx context.Context, f *framework.Framework, disabledCPUQ
635
644
err = e2epod .NewPodClient (f ).MatchContainerOutput (ctx , pod1 .Name , pod1 .Spec .Containers [0 ].Name , expCFSQuotaRegex )
636
645
framework .ExpectNoError (err , "expected log not found in container [%s] of pod [%s]" ,
637
646
pod1 .Spec .Containers [0 ].Name , pod1 .Name )
647
+ deleteTestPod (pod1 )
638
648
639
649
ctnAttrs = []ctnAttribute {
640
650
{
@@ -646,7 +656,7 @@ func runCfsQuotaGuPods(ctx context.Context, f *framework.Framework, disabledCPUQ
646
656
pod2 = makeCPUManagerPod ("gu-pod2" , ctnAttrs )
647
657
pod2 .Spec .Containers [0 ].Command = cfsCheckCommand
648
658
pod2 = e2epod .NewPodClient (f ).CreateSync (ctx , pod2 )
649
- cleanupPods = append ( cleanupPods , pod2 )
659
+ podsToClean [ string ( pod2 . UID )] = pod2
650
660
651
661
ginkgo .By ("checking if the expected cfs quota was assigned (GU pod, limited)" )
652
662
@@ -655,6 +665,7 @@ func runCfsQuotaGuPods(ctx context.Context, f *framework.Framework, disabledCPUQ
655
665
err = e2epod .NewPodClient (f ).MatchContainerOutput (ctx , pod2 .Name , pod2 .Spec .Containers [0 ].Name , expCFSQuotaRegex )
656
666
framework .ExpectNoError (err , "expected log not found in container [%s] of pod [%s]" ,
657
667
pod2 .Spec .Containers [0 ].Name , pod2 .Name )
668
+ deleteTestPod (pod2 )
658
669
659
670
ctnAttrs = []ctnAttribute {
660
671
{
@@ -666,7 +677,7 @@ func runCfsQuotaGuPods(ctx context.Context, f *framework.Framework, disabledCPUQ
666
677
pod3 = makeCPUManagerPod ("non-gu-pod3" , ctnAttrs )
667
678
pod3 .Spec .Containers [0 ].Command = cfsCheckCommand
668
679
pod3 = e2epod .NewPodClient (f ).CreateSync (ctx , pod3 )
669
- cleanupPods = append ( cleanupPods , pod3 )
680
+ podsToClean [ string ( pod3 . UID )] = pod3
670
681
671
682
ginkgo .By ("checking if the expected cfs quota was assigned (BU pod, limited)" )
672
683
@@ -675,6 +686,7 @@ func runCfsQuotaGuPods(ctx context.Context, f *framework.Framework, disabledCPUQ
675
686
err = e2epod .NewPodClient (f ).MatchContainerOutput (ctx , pod3 .Name , pod3 .Spec .Containers [0 ].Name , expCFSQuotaRegex )
676
687
framework .ExpectNoError (err , "expected log not found in container [%s] of pod [%s]" ,
677
688
pod3 .Spec .Containers [0 ].Name , pod3 .Name )
689
+ deleteTestPod (pod3 )
678
690
679
691
ctnAttrs = []ctnAttribute {
680
692
{
@@ -692,7 +704,7 @@ func runCfsQuotaGuPods(ctx context.Context, f *framework.Framework, disabledCPUQ
692
704
pod4 .Spec .Containers [0 ].Command = cfsCheckCommand
693
705
pod4 .Spec .Containers [1 ].Command = cfsCheckCommand
694
706
pod4 = e2epod .NewPodClient (f ).CreateSync (ctx , pod4 )
695
- cleanupPods = append ( cleanupPods , pod4 )
707
+ podsToClean [ string ( pod4 . UID )] = pod4
696
708
697
709
ginkgo .By ("checking if the expected cfs quota was assigned (GU pod, container 0 exclusive CPUs unlimited, container 1 limited)" )
698
710
@@ -709,6 +721,7 @@ func runCfsQuotaGuPods(ctx context.Context, f *framework.Framework, disabledCPUQ
709
721
err = e2epod .NewPodClient (f ).MatchContainerOutput (ctx , pod4 .Name , pod4 .Spec .Containers [1 ].Name , expCFSQuotaRegex )
710
722
framework .ExpectNoError (err , "expected log not found in container [%s] of pod [%s]" ,
711
723
pod4 .Spec .Containers [1 ].Name , pod4 .Name )
724
+ deleteTestPod (pod4 )
712
725
713
726
ctnAttrs = []ctnAttribute {
714
727
{
@@ -728,7 +741,8 @@ func runCfsQuotaGuPods(ctx context.Context, f *framework.Framework, disabledCPUQ
728
741
pod5 := makeCPUManagerPod ("gu-pod5" , ctnAttrs )
729
742
pod5 .Spec .Containers [0 ].Command = podCFSCheckCommand
730
743
pod5 = e2epod .NewPodClient (f ).CreateSync (ctx , pod5 )
731
- cleanupPods = append (cleanupPods , pod5 )
744
+ podsToClean [string (pod5 .UID )] = pod5
745
+
732
746
ginkgo .By ("checking if the expected cfs quota was assigned to pod (GU pod, unlimited)" )
733
747
734
748
expectedQuota = "150000"
@@ -741,6 +755,7 @@ func runCfsQuotaGuPods(ctx context.Context, f *framework.Framework, disabledCPUQ
741
755
742
756
err = e2epod .NewPodClient (f ).MatchContainerOutput (ctx , pod5 .Name , pod5 .Spec .Containers [0 ].Name , expCFSQuotaRegex )
743
757
framework .ExpectNoError (err , "expected log not found in container [%s] of pod [%s]" , pod5 .Spec .Containers [0 ].Name , pod5 .Name )
758
+ deleteTestPod (pod5 )
744
759
745
760
ctnAttrs = []ctnAttribute {
746
761
{
@@ -753,15 +768,15 @@ func runCfsQuotaGuPods(ctx context.Context, f *framework.Framework, disabledCPUQ
753
768
pod6 := makeCPUManagerPod ("gu-pod6" , ctnAttrs )
754
769
pod6 .Spec .Containers [0 ].Command = podCFSCheckCommand
755
770
pod6 = e2epod .NewPodClient (f ).CreateSync (ctx , pod6 )
756
- cleanupPods = append ( cleanupPods , pod6 )
771
+ podsToClean [ string ( pod6 . UID )] = pod6
757
772
758
773
ginkgo .By ("checking if the expected cfs quota was assigned to pod (GU pod, limited)" )
759
774
760
775
expectedQuota = "10000"
761
776
expCFSQuotaRegex = fmt .Sprintf ("^%s %s\n $" , expectedQuota , defaultPeriod )
762
777
err = e2epod .NewPodClient (f ).MatchContainerOutput (ctx , pod6 .Name , pod6 .Spec .Containers [0 ].Name , expCFSQuotaRegex )
763
778
framework .ExpectNoError (err , "expected log not found in container [%s] of pod [%s]" , pod6 .Spec .Containers [0 ].Name , pod6 .Name )
764
-
779
+ deleteTestPod ( pod6 )
765
780
}
766
781
767
782
func runMultipleGuPods (ctx context.Context , f * framework.Framework ) {
0 commit comments