@@ -19,6 +19,7 @@ package e2e
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "time"
22
23
23
24
"github.com/pkg/errors"
24
25
@@ -326,23 +327,7 @@ func waitForMatchingFederatedObject(tl common.TestLogger, typeConfig typeconfig.
326
327
}
327
328
328
329
func createIntersectionEnvironment (tl common.TestLogger , client genericclient.Client , kubefedNamespace string , clusterName string ) {
329
- fedCluster := & unstructured.Unstructured {}
330
- fedCluster .SetGroupVersionKind (schema.GroupVersionKind {
331
- Kind : "KubeFedCluster" ,
332
- Group : fedv1b1 .SchemeGroupVersion .Group ,
333
- Version : fedv1b1 .SchemeGroupVersion .Version ,
334
- })
335
-
336
- err := client .Get (context .Background (), fedCluster , kubefedNamespace , clusterName )
337
- if err != nil {
338
- tl .Fatalf ("Cannot get KubeFedCluster %q from namespace %q: %v" , clusterName , kubefedNamespace , err )
339
- }
340
-
341
- addLabel (fedCluster , "foo" , "bar" )
342
- err = client .Update (context .TODO (), fedCluster )
343
- if err != nil {
344
- tl .Fatalf ("Error updating label %q to KubeFedCluster %q: %v" , "foo:bar" , clusterName , err )
345
- }
330
+ updateClusterLabel (tl , client , kubefedNamespace , clusterName , true )
346
331
}
347
332
348
333
func destroyIntersectionEnvironment (tl common.TestLogger , client genericclient.Client , testNamespace * unstructured.Unstructured , kubefedNamespace string , clusterName string ) {
@@ -352,22 +337,40 @@ func destroyIntersectionEnvironment(tl common.TestLogger, client genericclient.C
352
337
tl .Fatalf ("Error deleting FederatedNamespace %q: %v" , testNamespaceKey , err )
353
338
}
354
339
340
+ updateClusterLabel (tl , client , kubefedNamespace , clusterName , false )
341
+ }
342
+
343
+ func updateClusterLabel (tl common.TestLogger , client genericclient.Client , kubefedNamespace string , clusterName string , addTestLabel bool ) {
355
344
fedCluster := & unstructured.Unstructured {}
356
345
fedCluster .SetGroupVersionKind (schema.GroupVersionKind {
357
346
Kind : "KubeFedCluster" ,
358
347
Group : fedv1b1 .SchemeGroupVersion .Group ,
359
348
Version : fedv1b1 .SchemeGroupVersion .Version ,
360
349
})
350
+ // We retry couple of times on conflict
351
+ err := wait .PollImmediate (1 * time .Second , 10 * time .Second , func () (bool , error ) {
352
+ err := client .Get (context .Background (), fedCluster , kubefedNamespace , clusterName )
353
+ if err != nil {
354
+ tl .Fatalf ("Cannot get KubeFedCluster %q from namespace %q: %v" , clusterName , kubefedNamespace , err )
355
+ }
361
356
362
- err = client .Get (context .Background (), fedCluster , kubefedNamespace , clusterName )
363
- if err != nil {
364
- tl .Fatalf ("Cannot get KubeFedCluster %q from namespace %q: %v" , clusterName , kubefedNamespace , err )
365
- }
366
-
367
- removeLabel (fedCluster , "foo" , "bar" )
368
- err = client .Update (context .TODO (), fedCluster )
357
+ if addTestLabel {
358
+ addLabel (fedCluster , "foo" , "bar" )
359
+ } else {
360
+ removeLabel (fedCluster , "foo" , "bar" )
361
+ }
362
+ err = client .Update (context .TODO (), fedCluster )
363
+ if err == nil {
364
+ return true , nil
365
+ }
366
+ if apierrors .IsConflict (err ) {
367
+ tl .Logf ("Got conflit updating label %q (add=%t) to KubeFedCluster %q" , "foo:bar. Will Retry." , addTestLabel , clusterName )
368
+ return false , nil
369
+ }
370
+ return false , errors .Wrapf (err , "failed to update resource" )
371
+ })
369
372
if err != nil {
370
- tl .Fatalf ("Error deleting label %q of KubeFedCluster %q: %v" , "foo:bar" , clusterName , err )
373
+ tl .Fatalf ("Error updating label %q (add=%b) to KubeFedCluster %q: %v" , "foo:bar" , addTestLabel , clusterName , err )
371
374
}
372
375
}
373
376
0 commit comments