@@ -19,6 +19,7 @@ package e2e
1919import (
2020 "context"
2121 "fmt"
22+ "time"
2223
2324 "github.com/pkg/errors"
2425
@@ -326,23 +327,7 @@ func waitForMatchingFederatedObject(tl common.TestLogger, typeConfig typeconfig.
326327}
327328
328329func 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 )
346331}
347332
348333func 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
352337 tl .Fatalf ("Error deleting FederatedNamespace %q: %v" , testNamespaceKey , err )
353338 }
354339
340+ updateClusterLabel (tl , client , kubefedNamespace , clusterName , false )
341+ }
342+
343+ func updateClusterLabel (tl common.TestLogger , client genericclient.Client , kubefedNamespace string , clusterName string , addTestLabel bool ) {
355344 fedCluster := & unstructured.Unstructured {}
356345 fedCluster .SetGroupVersionKind (schema.GroupVersionKind {
357346 Kind : "KubeFedCluster" ,
358347 Group : fedv1b1 .SchemeGroupVersion .Group ,
359348 Version : fedv1b1 .SchemeGroupVersion .Version ,
360349 })
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+ }
361356
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+ })
369372 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=%t) to KubeFedCluster %q: %v" , "foo:bar" , addTestLabel , clusterName , err )
371374 }
372375}
373376
0 commit comments