File tree 1 file changed +35
-0
lines changed 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,9 @@ import (
16
16
"github.com/stretchr/testify/suite"
17
17
"golang.org/x/oauth2"
18
18
v1 "k8s.io/api/core/v1"
19
+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
19
20
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21
+ "k8s.io/apimachinery/pkg/util/wait"
20
22
"k8s.io/client-go/kubernetes"
21
23
"k8s.io/client-go/tools/clientcmd"
22
24
)
@@ -181,6 +183,39 @@ func (s *IntegrationTestSuite) TearDownTest() {
181
183
errors ++
182
184
}
183
185
186
+ // Wait up to two minutes for the namespace to be deleted
187
+ timeout := 120 * time .Second
188
+
189
+ ctx , cancel := context .WithTimeout (context .Background (), timeout )
190
+ defer cancel ()
191
+
192
+ err = wait .PollUntilContextCancel (ctx , 1 * time .Second , true ,
193
+ func (ctx context.Context ) (bool , error ) {
194
+ _ , err := s .k8s .CoreV1 ().Namespaces ().Get (
195
+ ctx ,
196
+ s .ns ,
197
+ metav1.GetOptions {},
198
+ )
199
+
200
+ // Not found, we are done
201
+ if k8serrors .IsNotFound (err ) {
202
+ return true , nil
203
+ }
204
+
205
+ // Another error, fail
206
+ if err != nil {
207
+ return false , err
208
+ }
209
+
210
+ // Found, try again
211
+ return false , nil
212
+ })
213
+
214
+ if err != nil {
215
+ s .T ().Logf ("took too long to delete namespace %s: %s" , s .ns , err )
216
+ errors ++
217
+ }
218
+
184
219
if errors > 0 {
185
220
panic (fmt .Sprintf ("failed cleanup test: %d errors" , errors ))
186
221
}
You can’t perform that action at this time.
0 commit comments