@@ -29,12 +29,14 @@ import (
29
29
storage "k8s.io/api/storage/v1"
30
30
"k8s.io/apimachinery/pkg/api/resource"
31
31
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32
+ "k8s.io/apimachinery/pkg/util/wait"
32
33
"k8s.io/apimachinery/pkg/watch"
33
34
utilfeature "k8s.io/apiserver/pkg/util/feature"
34
35
"k8s.io/client-go/informers"
35
36
clientset "k8s.io/client-go/kubernetes"
36
37
restclient "k8s.io/client-go/rest"
37
38
ref "k8s.io/client-go/tools/reference"
39
+ "k8s.io/client-go/util/retry"
38
40
featuregatetesting "k8s.io/component-base/featuregate/testing"
39
41
kubeapiservertesting "k8s.io/kubernetes/cmd/kube-apiserver/app/testing"
40
42
"k8s.io/kubernetes/pkg/api/legacyscheme"
@@ -1058,34 +1060,6 @@ func TestPersistentVolumeProvisionMultiPVCs(t *testing.T) {
1058
1060
defer testClient .CoreV1 ().PersistentVolumes ().DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {})
1059
1061
defer testClient .StorageV1 ().StorageClasses ().DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {})
1060
1062
1061
- // Watch all events in the namespace, and save them to artifacts for debugging.
1062
- // TODO: This is a temporary solution to debug flaky tests `panic: test timed out after 10m0s`.
1063
- // We should remove this once https://github.com/kubernetes/kubernetes/issues/124136 is fixed.
1064
- go func () {
1065
- w , err := testClient .EventsV1 ().Events (ns .Name ).Watch (tCtx , metav1.ListOptions {})
1066
- if err != nil {
1067
- return
1068
- }
1069
- for {
1070
- select {
1071
- case event , ok := <- w .ResultChan ():
1072
- if ! ok {
1073
- klog .Info ("Event watch channel closed" )
1074
- w , err = testClient .EventsV1 ().Events (ns .Name ).Watch (tCtx , metav1.ListOptions {})
1075
- if err != nil {
1076
- klog .ErrorS (err , "Failed to restart event watch" )
1077
- return
1078
- }
1079
- continue
1080
- }
1081
- reportToArtifacts (t .Name ()+ "-events.text" , event .Object )
1082
- case <- tCtx .Done ():
1083
- w .Stop ()
1084
- return
1085
- }
1086
- }
1087
- }()
1088
-
1089
1063
storageClass := storage.StorageClass {
1090
1064
TypeMeta : metav1.TypeMeta {
1091
1065
Kind : "StorageClass" ,
@@ -1117,9 +1091,24 @@ func TestPersistentVolumeProvisionMultiPVCs(t *testing.T) {
1117
1091
}()
1118
1092
1119
1093
// Wait until the controller provisions and binds all of them
1120
- for i := 0 ; i < objCount ; i ++ {
1121
- waitForAnyPersistentVolumeClaimPhaseAndReportIt (t , watchPVC , v1 .ClaimBound )
1122
- klog .V (1 ).Infof ("%d claims bound" , i + 1 )
1094
+ err := wait .ExponentialBackoffWithContext (tCtx , retry .DefaultBackoff , func (ctx context.Context ) (bool , error ) {
1095
+ for i := 0 ; i < objCount ; i ++ {
1096
+ waitErr := waitForAnyPersistentVolumeClaimPhase (watchPVC , v1 .ClaimBound )
1097
+ if waitErr != nil {
1098
+ newWatchPVC , err := testClient .CoreV1 ().PersistentVolumeClaims (namespaceName ).Watch (ctx , metav1.ListOptions {})
1099
+ if err != nil {
1100
+ return false , err
1101
+ }
1102
+ watchPVC .Stop ()
1103
+ watchPVC = newWatchPVC
1104
+ return false , waitErr
1105
+ }
1106
+ klog .V (1 ).Infof ("%d claims bound" , i + 1 )
1107
+ }
1108
+ return true , nil
1109
+ })
1110
+ if err != nil {
1111
+ t .Fatalf ("Failed to wait for all claims to be bound: %v" , err )
1123
1112
}
1124
1113
klog .V (2 ).Infof ("TestPersistentVolumeProvisionMultiPVCs: claims are bound" )
1125
1114
@@ -1488,31 +1477,19 @@ func waitForAnyPersistentVolumePhase(w watch.Interface, phase v1.PersistentVolum
1488
1477
}
1489
1478
}
1490
1479
1491
- func waitForAnyPersistentVolumeClaimPhase (w watch.Interface , phase v1.PersistentVolumeClaimPhase ) {
1480
+ func waitForAnyPersistentVolumeClaimPhase (w watch.Interface , phase v1.PersistentVolumeClaimPhase ) error {
1492
1481
for {
1493
- event := <- w .ResultChan ()
1494
- claim , ok := event .Object .(* v1.PersistentVolumeClaim )
1482
+ event , ok := <- w .ResultChan ()
1495
1483
if ! ok {
1496
- continue
1484
+ return fmt . Errorf ( "watch closed" )
1497
1485
}
1498
- if claim .Status .Phase == phase {
1499
- klog .V (2 ).Infof ("claim %q is %s" , claim .Name , phase )
1500
- break
1501
- }
1502
- }
1503
- }
1504
-
1505
- func waitForAnyPersistentVolumeClaimPhaseAndReportIt (t * testing.T , w watch.Interface , phase v1.PersistentVolumeClaimPhase ) {
1506
- for {
1507
- event := <- w .ResultChan ()
1508
- reportToArtifacts (t .Name ()+ "-watched-pvcs.text" , event )
1509
1486
claim , ok := event .Object .(* v1.PersistentVolumeClaim )
1510
1487
if ! ok {
1511
1488
continue
1512
1489
}
1513
1490
if claim .Status .Phase == phase {
1514
1491
klog .V (2 ).Infof ("claim %q is %s" , claim .Name , phase )
1515
- break
1492
+ return nil
1516
1493
}
1517
1494
}
1518
1495
}
0 commit comments