@@ -289,6 +289,51 @@ func assertSubscription(t *testing.T, namespace, subName string) error {
289289 return err
290290}
291291
292+ // deleteExistingSubscription deletes if the subscription of the given name exists and returns an error if not.
293+ func deleteExistingSubscription (t * testing.T , namespace , subName string ) error {
294+ t .Helper ()
295+ existingSubscription := & operatorsv1alpha1.Subscription {}
296+ newSubscription := & operatorsv1alpha1.Subscription {}
297+ nsName := types.NamespacedName {Namespace : namespace , Name : subName }
298+
299+ err := wait .PollUntilContextTimeout (context .Background (), 1 * time .Second , 30 * time .Second , false , func (context context.Context ) (bool , error ) {
300+ if err := kclient .Get (context , nsName , existingSubscription ); err != nil {
301+ t .Logf ("failed to get Subscription %s: %v" , nsName .Name , err )
302+ return false , nil
303+ }
304+ return true , nil
305+ })
306+ if err != nil {
307+ return fmt .Errorf ("timed out getting subscription %s: %w" , nsName .Name , err )
308+ }
309+ // deleting Subscription.
310+ err = kclient .Delete (context .Background (), existingSubscription )
311+ if err != nil {
312+ return err
313+ }
314+ err = wait .PollUntilContextTimeout (context .Background (), 1 * time .Second , 1 * time .Minute , false , func (ctx context.Context ) (bool , error ) {
315+ if err := kclient .Get (ctx , nsName , newSubscription ); err != nil {
316+ if kerrors .IsNotFound (err ) {
317+ return true , nil
318+ }
319+ t .Logf ("failed to get deleted subscription %s: %v" , nsName .Name , err )
320+ return false , nil
321+ }
322+ // if new Subscription got recreated while the poll ensures the Subscription is deleted.
323+ if newSubscription != nil && newSubscription .UID != existingSubscription .UID {
324+ return true , nil
325+ }
326+ t .Logf ("Subscription %s still exists" , nsName .Name )
327+ return false , nil
328+ })
329+ if err != nil {
330+ return fmt .Errorf ("timed out waiting for Subscription %s to be deleted: %v" , nsName .Name , err )
331+ }
332+ t .Logf ("deleted Subscription %s" , nsName .Name )
333+ return nil
334+
335+ }
336+
292337// assertOSSMOperator checks if the OSSM Istio operator gets successfully installed
293338// and returns an error if not.
294339func assertOSSMOperator (t * testing.T ) error {
@@ -625,6 +670,51 @@ func assertSMCP(t *testing.T) error {
625670 return err
626671}
627672
673+ // deleteExistingSMCP deletes if the SMCP exists and returns an error if not.
674+ func deleteExistingSMCP (t * testing.T ) error {
675+ t .Helper ()
676+ existingSMCP := & maistrav2.ServiceMeshControlPlane {}
677+ newSMCP := & maistrav2.ServiceMeshControlPlane {}
678+ nsName := types.NamespacedName {Namespace : operatorcontroller .DefaultOperandNamespace , Name : openshiftSMCPName }
679+
680+ err := wait .PollUntilContextTimeout (context .Background (), 1 * time .Second , 30 * time .Second , false , func (context context.Context ) (bool , error ) {
681+ if err := kclient .Get (context , nsName , existingSMCP ); err != nil {
682+ t .Logf ("failed to get smcp %s: %v" , nsName .Name , err )
683+ return false , nil
684+ }
685+ return true , nil
686+ })
687+ if err != nil {
688+ return fmt .Errorf ("timed out getting smcp %s: %w" , nsName .Name , err )
689+ }
690+ // deleting SMCP.
691+ err = kclient .Delete (context .Background (), existingSMCP )
692+ if err != nil {
693+ t .Errorf ("failed to delete smcp %s: %v" , nsName .Name , err )
694+ return err
695+ }
696+ err = wait .PollUntilContextTimeout (context .Background (), 1 * time .Second , 1 * time .Minute , false , func (ctx context.Context ) (bool , error ) {
697+ if err := kclient .Get (ctx , nsName , newSMCP ); err != nil {
698+ if kerrors .IsNotFound (err ) {
699+ return true , nil
700+ }
701+ t .Logf ("failed to get deleted SMCP %s: %v" , nsName .Name , err )
702+ return false , nil
703+ }
704+ // if new SMCP got recreated while the poll ensures the SMCP is deleted.
705+ if newSMCP != nil && newSMCP .UID != existingSMCP .UID {
706+ return true , nil
707+ }
708+ t .Logf ("smcp %s still exists" , nsName .Name )
709+ return false , nil
710+ })
711+ if err != nil {
712+ return fmt .Errorf ("timed out waiting for SMCP %s to be deleted: %v" , nsName .Name , err )
713+ }
714+ t .Logf ("deleted smcp %s" , nsName .Name )
715+ return nil
716+ }
717+
628718// assertDNSRecord checks to make sure a DNSRecord exists in a ready state,
629719// and returns an error if not.
630720func assertDNSRecord (t * testing.T , recordName types.NamespacedName ) error {
0 commit comments