@@ -197,9 +197,16 @@ var _ = common.SIGDescribe("Netpol API", func() {
197197 ginkgo .By ("deleting" )
198198 err = npClient .Delete (ctx , createdNetPol .Name , metav1.DeleteOptions {})
199199 framework .ExpectNoError (err )
200- _ , err = npClient .Get (ctx , createdNetPol .Name , metav1.GetOptions {})
201- if ! apierrors .IsNotFound (err ) {
202- framework .Failf ("expected 404, got %#v" , err )
200+ err = wait .PollUntilContextTimeout (ctx , 2 * time .Second , 1 * time .Minute , false , func (ctx context.Context ) (done bool , err error ) {
201+ _ , err = npClient .Get (ctx , createdNetPol .Name , metav1.GetOptions {})
202+ if ! apierrors .IsNotFound (err ) {
203+ framework .Logf ("expected 404, got %#v" , err )
204+ return false , nil
205+ }
206+ return true , nil
207+ })
208+ if err != nil {
209+ framework .Failf ("unexpected error deleting existing network policy: %v" , err )
203210 }
204211 nps , err = npClient .List (ctx , metav1.ListOptions {LabelSelector : "special-label=" + f .UniqueName })
205212 framework .ExpectNoError (err )
@@ -208,9 +215,20 @@ var _ = common.SIGDescribe("Netpol API", func() {
208215 ginkgo .By ("deleting a collection" )
209216 err = npClient .DeleteCollection (ctx , metav1.DeleteOptions {}, metav1.ListOptions {LabelSelector : "special-label=" + f .UniqueName })
210217 framework .ExpectNoError (err )
211- nps , err = npClient .List (ctx , metav1.ListOptions {LabelSelector : "special-label=" + f .UniqueName })
212- framework .ExpectNoError (err )
213- gomega .Expect (nps .Items ).To (gomega .BeEmpty (), "filtered list should have 0 items" )
218+ err = wait .PollUntilContextTimeout (ctx , 2 * time .Second , 1 * time .Minute , false , func (ctx context.Context ) (done bool , err error ) {
219+ nps , err = npClient .List (ctx , metav1.ListOptions {LabelSelector : "special-label=" + f .UniqueName })
220+ if err != nil {
221+ return false , err
222+ }
223+ if len (nps .Items ) > 0 {
224+ framework .Logf ("still %d network policies present, retrying ..." , len (nps .Items ))
225+ return false , nil
226+ }
227+ return true , nil
228+ })
229+ if err != nil {
230+ framework .Failf ("unexpected error deleting existing network policies: %v" , err )
231+ }
214232 })
215233
216234 /*
@@ -267,8 +285,19 @@ var _ = common.SIGDescribe("Netpol API", func() {
267285 ginkgo .By ("deleting all test collection" )
268286 err = npClient .DeleteCollection (ctx , metav1.DeleteOptions {}, metav1.ListOptions {LabelSelector : "special-label=" + f .UniqueName })
269287 framework .ExpectNoError (err )
270- nps , err := npClient .List (ctx , metav1.ListOptions {LabelSelector : "special-label=" + f .UniqueName })
271- framework .ExpectNoError (err )
272- gomega .Expect (nps .Items ).To (gomega .BeEmpty (), "filtered list should be 0 items" )
288+ err = wait .PollUntilContextTimeout (ctx , 2 * time .Second , 1 * time .Minute , false , func (ctx context.Context ) (done bool , err error ) {
289+ nps , err := npClient .List (ctx , metav1.ListOptions {LabelSelector : "special-label=" + f .UniqueName })
290+ if err != nil {
291+ return false , err
292+ }
293+ if len (nps .Items ) > 0 {
294+ framework .Logf ("still %d network policies present, retrying ..." , len (nps .Items ))
295+ return false , nil
296+ }
297+ return true , nil
298+ })
299+ if err != nil {
300+ framework .Failf ("unexpected error deleting existing network policies: %v" , err )
301+ }
273302 })
274303})
0 commit comments