@@ -1304,28 +1304,21 @@ var _ = Describe("webhook tests for operations on ARM managed resources", Ordere
13041304 By ("deleting the managed namespace" )
13051305 ns := managedNamespace ()
13061306 Expect (hubClient .Delete (ctx , & ns )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}), "Failed to delete the managed namespace" )
1307- Eventually (
1308- func () error {
1309- if err := hubClient .Get (ctx , types.NamespacedName {Name : ns .Name }, & corev1.Namespace {}); ! k8sErrors .IsNotFound (err ) {
1310- return fmt .Errorf ("The managed namespace still exists or an unexpected error occurred: %w" , err )
1311- }
1312- return nil
1313- }, workloadEventuallyDuration , eventuallyInterval ).Should (Succeed (), "Failed to remove the managed namespace %s" , ns .Name )
1307+ Eventually (func () error {
1308+ if err := hubClient .Get (ctx , types.NamespacedName {Name : ns .Name }, & corev1.Namespace {}); ! k8sErrors .IsNotFound (err ) {
1309+ return fmt .Errorf ("The managed namespace still exists or an unexpected error occurred: %w" , err )
1310+ }
1311+ return nil
1312+ }, workloadEventuallyDuration , eventuallyInterval ).Should (Succeed (), "Failed to remove the managed namespace %s" , ns .Name )
13141313 })
13151314
13161315 It ("should deny create a managed resource namespace" , func () {
1317- Eventually (func (g Gomega ) error {
1318- createNs := managedNamespace ()
1319- createNs .Name = "this-will-be-denied"
1320- err := impersonateHubClient .Create (ctx , & createNs )
1321- if k8sErrors .IsConflict (err ) {
1322- return err
1323- }
1324- var statusErr * k8sErrors.StatusError
1325- g .Expect (errors .As (err , & statusErr )).To (BeTrue (), fmt .Sprintf ("Create managed namespace call produced error %s. Error type wanted is %s." , reflect .TypeOf (err ), reflect .TypeOf (& k8sErrors.StatusError {})))
1326- Expect (statusErr .ErrStatus .Message ).Should (MatchRegexp (".*the operation on the managed resource type .* is not allowed" ))
1327- return nil
1328- }, testutils .PollTimeout , testutils .PollInterval ).Should (Succeed ())
1316+ createNs := managedNamespace ()
1317+ createNs .Name = "this-will-be-denied"
1318+ err := impersonateHubClient .Create (ctx , & createNs )
1319+ var statusErr * k8sErrors.StatusError
1320+ Expect (errors .As (err , & statusErr )).To (BeTrue (), fmt .Sprintf ("Create managed namespace call produced error %s. Error type wanted is %s." , reflect .TypeOf (err ), reflect .TypeOf (& k8sErrors.StatusError {})))
1321+ Expect (statusErr .ErrStatus .Message ).Should (MatchRegexp (".*the operation on the managed resource type .* is not allowed" ))
13291322 })
13301323
13311324 It ("should deny update a managed resource namespace" , func () {
@@ -1344,29 +1337,24 @@ var _ = Describe("webhook tests for operations on ARM managed resources", Ordere
13441337 })
13451338
13461339 It ("should deny delete a managed resource namespace" , func () {
1347- Eventually (func (g Gomega ) error {
1348- created := managedNamespace ()
1349- err := impersonateHubClient .Delete (ctx , & created )
1350- if k8sErrors .IsConflict (err ) {
1351- return err
1352- }
1353- var statusErr * k8sErrors.StatusError
1354- g .Expect (errors .As (err , & statusErr )).To (BeTrue (), fmt .Sprintf ("Delete managed namespace call produced error %s. Error type wanted is %s." , reflect .TypeOf (err ), reflect .TypeOf (& k8sErrors.StatusError {})))
1355- Expect (statusErr .ErrStatus .Message ).Should (MatchRegexp (".*the operation on the managed resource type .* is not allowed" ))
1356- return nil
1357- }, testutils .PollTimeout , testutils .PollInterval ).Should (Succeed ())
1340+ created := managedNamespace ()
1341+ err := impersonateHubClient .Delete (ctx , & created )
1342+ var statusErr * k8sErrors.StatusError
1343+ Expect (errors .As (err , & statusErr )).To (BeTrue (), fmt .Sprintf ("Delete managed namespace call produced error %s. Error type wanted is %s." , reflect .TypeOf (err ), reflect .TypeOf (& k8sErrors.StatusError {})))
1344+ Expect (statusErr .ErrStatus .Message ).Should (MatchRegexp (".*the operation on the managed resource type .* is not allowed" ))
13581345 })
13591346
13601347 It ("should allow create/update/delete an unmanaged resource namespace" , func () {
1348+ unmanaged := managedNamespace ()
1349+ unmanaged .Name = "this-should-be-allowed"
1350+ delete (unmanaged .Labels , managedresource .ManagedByArmKey )
1351+ Expect (impersonateHubClient .Create (ctx , & unmanaged )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}), "Failed to create the unmanaged namespace" )
13611352 Eventually (func (g Gomega ) error {
1362- unmanaged := managedNamespace ()
1363- unmanaged .Name = "this-should-be-allowed"
1364- delete (unmanaged .Labels , managedresource .ManagedByArmKey )
1365- g .Expect (impersonateHubClient .Create (ctx , & unmanaged )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}), "Failed to create the unmanaged namespace" )
1353+ // Get the object again.
13661354 unmanaged .Labels ["foo" ] = "NotManaged"
13671355 g .Expect (impersonateHubClient .Update (ctx , & unmanaged )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}), "Failed to update the unmanaged namespace" )
1368- g .Expect (impersonateHubClient .Delete (ctx , & unmanaged )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}), "Failed to delete the unmanaged namespace" )
13691356 return nil
13701357 }, testutils .PollTimeout , testutils .PollInterval ).Should (Succeed ())
1358+ Expect (impersonateHubClient .Delete (ctx , & unmanaged )).Should (SatisfyAny (Succeed (), utils.NotFoundMatcher {}), "Failed to delete the unmanaged namespace" )
13711359 })
13721360})
0 commit comments