@@ -401,9 +401,10 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul
401401 var notificationMQStatus nova.MessageBusStatus
402402 var notificationMQError error
403403
404+ notificationTransportURLName := instance .Name + "-notification-transport"
404405 if notificationBusName != "" {
405406 notificationTransportURL , notificationMQStatus , notificationMQError = r .ensureMQ (
406- ctx , h , instance , instance . Name + "-notification-transport" , notificationBusName )
407+ ctx , h , instance , notificationTransportURLName , notificationBusName )
407408
408409 switch notificationMQStatus {
409410 case nova .MQFailed :
@@ -430,6 +431,24 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul
430431 }
431432 } else {
432433 instance .Status .Conditions .Remove (novav1 .NovaNotificationMQReadyCondition )
434+
435+ // Ensure to delete the previous notifications transport url
436+ transportURLList := & rabbitmqv1.TransportURLList {}
437+ listOpts := []client.ListOption {
438+ client .InNamespace (instance .Namespace ),
439+ }
440+ if err := r .Client .List (ctx , transportURLList , listOpts ... ); err != nil {
441+ return ctrl.Result {}, err
442+ }
443+
444+ for _ , url := range transportURLList .Items {
445+ if strings .Contains (url .Name , notificationTransportURLName ) {
446+ err = r .ensureMQDeleted (ctx , instance , url .Name )
447+ if err != nil {
448+ return ctrl.Result {}, err
449+ }
450+ }
451+ }
433452 }
434453
435454 cellMQs := map [string ]* nova.MessageBus {}
@@ -827,13 +846,7 @@ func (r *NovaReconciler) ensureCellDeleted(
827846 }
828847
829848 // Delete transportURL cr
830- transportURL := & rabbitmqv1.TransportURL {
831- ObjectMeta : metav1.ObjectMeta {
832- Name : instance .Name + "-" + cellName + "-transport" ,
833- Namespace : instance .Namespace ,
834- },
835- }
836- err = r .Client .Delete (ctx , transportURL )
849+ err = r .ensureMQDeleted (ctx , instance , instance .Name + "-" + cellName + "-transport" )
837850 if err != nil && ! k8s_errors .IsNotFound (err ) {
838851 return nova .CellDeleteFailed , err
839852 }
@@ -1756,6 +1769,30 @@ func (r *NovaReconciler) ensureMQ(
17561769 return string (url ), nova .MQCompleted , nil
17571770}
17581771
1772+ func (r * NovaReconciler ) ensureMQDeleted (
1773+ ctx context.Context ,
1774+ instance * novav1.Nova ,
1775+ transportURLName string ,
1776+ ) error {
1777+ Log := r .GetLogger (ctx )
1778+ transportURL := & rabbitmqv1.TransportURL {
1779+ ObjectMeta : metav1.ObjectMeta {
1780+ Name : transportURLName ,
1781+ Namespace : instance .Namespace ,
1782+ },
1783+ }
1784+
1785+ err := r .Client .Delete (ctx , transportURL )
1786+ if err != nil {
1787+ Log .Info (fmt .Sprintf ("Could not delete TransportURL %s err: %s" , transportURLName , err ))
1788+ return err
1789+ }
1790+
1791+ Log .Info ("Deleted transportURL" , ":" , transportURLName )
1792+
1793+ return nil
1794+ }
1795+
17591796func getNovaMetadataName (instance client.Object ) types.NamespacedName {
17601797 return types.NamespacedName {Namespace : instance .GetNamespace (), Name : instance .GetName () + "-metadata" }
17611798}
0 commit comments