@@ -201,11 +201,11 @@ func (r *WatcherReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
201201 // create service DB - end
202202
203203 //
204- // create RabbitMQ transportURL CR and get the actual URL from the associated secret that is created
204+ // create RPC RabbitMQ transportURL CR and get the actual URL from the associated secret that is created
205205 // not-ready condition is managed here instead of in ensureMQ to distinguish between Error (when receiving)
206206 // an error, or Running when transportURL is empty.
207207 //
208- transportURL , op , err := r .ensureMQ (ctx , instance , helper , serviceLabels )
208+ transportURL , op , err := r .ensureMQ (ctx , instance , helper , instance . Name + "-watcher-transport" , * instance . Spec . RabbitMqClusterName , serviceLabels )
209209 if err != nil {
210210 instance .Status .Conditions .Set (condition .FalseCondition (
211211 watcherv1beta1 .WatcherRabbitMQTransportURLReadyCondition ,
@@ -226,9 +226,64 @@ func (r *WatcherReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
226226 return ctrl.Result {RequeueAfter : time .Duration (10 ) * time .Second }, nil
227227 }
228228
229+ instance .Status .Conditions .MarkTrue (watcherv1beta1 .WatcherRabbitMQTransportURLReadyCondition , watcherv1beta1 .WatcherRabbitMQTransportURLReadyMessage )
230+
229231 _ = op
230232 // end of TransportURL creation
231233
234+ // create Notification RabbitMQ transportURL CR and get the actual URL from the associated secret that is created
235+ notificationURLSecret := & corev1.Secret {}
236+
237+ if instance .Spec .NotificationsBusInstance != nil && * instance .Spec .NotificationsBusInstance != "" {
238+ instance .Status .Conditions .Set (condition .FalseCondition (
239+ watcherv1beta1 .WatcherNotificationTransportURLReadyCondition ,
240+ condition .RequestedReason ,
241+ condition .SeverityInfo ,
242+ watcherv1beta1 .WatcherNotificationTransportURLReadyRunningMessage ,
243+ ))
244+ notificationURL , op , err := r .ensureMQ (ctx , instance , helper , instance .Name + "-watcher-notification" , * instance .Spec .NotificationsBusInstance , serviceLabels )
245+ if err != nil {
246+ instance .Status .Conditions .Set (condition .FalseCondition (
247+ watcherv1beta1 .WatcherNotificationTransportURLReadyCondition ,
248+ condition .ErrorReason ,
249+ condition .SeverityWarning ,
250+ watcherv1beta1 .WatcherNotificationTransportURLReadyErrorMessage ,
251+ err .Error ()))
252+ return ctrl.Result {}, err
253+ }
254+
255+ if notificationURL == nil {
256+ Log .Info (fmt .Sprintf ("Waiting for TransportURL for %s to be created" , instance .Name ))
257+ instance .Status .Conditions .Set (condition .FalseCondition (
258+ watcherv1beta1 .WatcherNotificationTransportURLReadyCondition ,
259+ condition .RequestedReason ,
260+ condition .SeverityInfo ,
261+ watcherv1beta1 .WatcherNotificationTransportURLReadyRunningMessage ,
262+ ))
263+ return ctrl.Result {RequeueAfter : time .Duration (10 ) * time .Second }, nil
264+ }
265+ instance .Status .Conditions .MarkTrue (watcherv1beta1 .WatcherNotificationTransportURLReadyCondition , watcherv1beta1 .WatcherNotificationTransportURLReadyMessage )
266+
267+ // NotificationURL Secret
268+ hashNotificationURL , _ , notificationSecret , err := ensureSecret (
269+ ctx ,
270+ types.NamespacedName {Namespace : instance .Namespace , Name : notificationURL .Status .SecretName },
271+ []string {
272+ TransportURLSelector ,
273+ },
274+ helper .GetClient (),
275+ & instance .Status .Conditions ,
276+ r .RequeueTimeout ,
277+ )
278+ if err != nil || hashNotificationURL == "" {
279+ // Empty hash means that there is some problem retrieving the key from the secret
280+ return ctrl.Result {}, errors .New ("error retrieving required data from notificationURL secret" )
281+ }
282+ notificationURLSecret = & notificationSecret
283+ _ = op
284+ }
285+
286+ // end of Notification TransportURL creation
232287 // Check we have the required inputs
233288 // Top level secret
234289 hash , _ , inputSecret , err := ensureSecret (
@@ -300,7 +355,7 @@ func (r *WatcherReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
300355
301356 // End of Prometheus config secret
302357
303- subLevelSecretName , err := r .createSubLevelSecret (ctx , helper , instance , transporturlSecret , inputSecret , db )
358+ subLevelSecretName , err := r .createSubLevelSecret (ctx , helper , instance , transporturlSecret , notificationURLSecret , inputSecret , db )
304359 if err != nil {
305360 return ctrl.Result {}, nil
306361 }
@@ -605,21 +660,23 @@ func (r *WatcherReconciler) ensureMQ(
605660 ctx context.Context ,
606661 instance * watcherv1beta1.Watcher ,
607662 h * helper.Helper ,
663+ transportURLName string ,
664+ messageBusInstance string ,
608665 serviceLabels map [string ]string ,
609666) (* rabbitmqv1.TransportURL , controllerutil.OperationResult , error ) {
610667 Log := r .GetLogger (ctx )
611- Log .Info (fmt .Sprintf ("Reconciling the RabbitMQ TransportURL for '%s'" , instance .Name ))
668+ Log .Info (fmt .Sprintf ("Reconciling the RabbitMQ TransportURL '%s' for '%s'" , transportURLName , instance .Name ))
612669
613670 transportURL := & rabbitmqv1.TransportURL {
614671 ObjectMeta : metav1.ObjectMeta {
615- Name : fmt . Sprintf ( "%s-watcher-transport" , instance . Name ) ,
672+ Name : transportURLName ,
616673 Namespace : instance .Namespace ,
617674 Labels : serviceLabels ,
618675 },
619676 }
620677
621678 op , err := controllerutil .CreateOrUpdate (ctx , r .Client , transportURL , func () error {
622- transportURL .Spec .RabbitmqClusterName = * instance . Spec . RabbitMqClusterName
679+ transportURL .Spec .RabbitmqClusterName = messageBusInstance
623680
624681 err := controllerutil .SetControllerReference (instance , transportURL , r .Scheme )
625682 return err
@@ -656,7 +713,6 @@ func (r *WatcherReconciler) ensureMQ(
656713 "the TransportURL secret %s does not have 'transport_url' field" , transportURL .Status .SecretName )
657714 }
658715
659- instance .Status .Conditions .MarkTrue (watcherv1beta1 .WatcherRabbitMQTransportURLReadyCondition , watcherv1beta1 .WatcherRabbitMQTransportURLReadyMessage )
660716 return transportURL , op , nil
661717}
662718
@@ -810,13 +866,15 @@ func (r *WatcherReconciler) createSubLevelSecret(
810866 helper * helper.Helper ,
811867 instance * watcherv1beta1.Watcher ,
812868 transportURLSecret corev1.Secret ,
869+ notificationURLSecret * corev1.Secret ,
813870 inputSecret corev1.Secret ,
814871 db * mariadbv1.Database ,
815872) (string , error ) {
816873 Log := r .GetLogger (ctx )
817874 Log .Info (fmt .Sprintf ("Creating SubCr Level Secret for '%s'" , instance .Name ))
818875 databaseAccount := db .GetAccount ()
819876 databaseSecret := db .GetSecret ()
877+
820878 data := map [string ]string {
821879 * instance .Spec .PasswordSelectors .Service : string (inputSecret .Data [* instance .Spec .PasswordSelectors .Service ]),
822880 TransportURLSelector : string (transportURLSecret .Data [TransportURLSelector ]),
@@ -825,6 +883,7 @@ func (r *WatcherReconciler) createSubLevelSecret(
825883 DatabasePassword : string (databaseSecret .Data [mariadbv1 .DatabasePasswordSelector ]),
826884 DatabaseHostname : db .GetDatabaseHostname (),
827885 watcher .GlobalCustomConfigFileName : instance .Spec .CustomServiceConfig ,
886+ NotificationURLSelector : string (notificationURLSecret .Data [TransportURLSelector ]),
828887 }
829888 secretName := instance .Name
830889
0 commit comments