diff --git a/controllers/natsaccount_controller.go b/controllers/natsaccount_controller.go index c28e10c..5142f94 100644 --- a/controllers/natsaccount_controller.go +++ b/controllers/natsaccount_controller.go @@ -138,7 +138,7 @@ func (r *NatsAccountReconciler) reconcileAccount(ctx context.Context, req ctrl.R issuer := &natsv1alpha1.NatsOperator{} issuerName := client.ObjectKey{ - Namespace: req.Namespace, + Namespace: utilx.IfElse(utilx.Empty(account.Spec.OperatorRef.Namespace), req.Namespace, account.Spec.OperatorRef.Namespace), Name: account.Spec.OperatorRef.Name, } @@ -287,6 +287,5 @@ func (r *NatsAccountReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&natsv1alpha1.NatsAccount{}). Owns(&corev1.Secret{}). - Owns(&natsv1alpha1.NatsUser{}). Complete(r) } diff --git a/controllers/natsuser_controller.go b/controllers/natsuser_controller.go index 619280d..6ee53ee 100644 --- a/controllers/natsuser_controller.go +++ b/controllers/natsuser_controller.go @@ -143,7 +143,7 @@ func (r *NatsUserReconciler) reconcileUser(ctx context.Context, req ctrl.Request issuer := &natsv1alpha1.NatsAccount{} issuerName := client.ObjectKey{ - Namespace: req.Namespace, + Namespace: utilx.IfElse(utilx.Empty(user.Spec.AccountRef.Namespace), req.Namespace, user.Spec.AccountRef.Namespace), Name: user.Spec.AccountRef.Name, } @@ -154,7 +154,7 @@ func (r *NatsUserReconciler) reconcileUser(ctx context.Context, req ctrl.Request op, err := controllerutil.CreateOrUpdate(ctx, r.Client, user, func() error { controllerutil.AddFinalizer(user, natsv1alpha1.FinalizerName) - return controllerutil.SetControllerReference(issuer, user, r.Scheme) + return nil }) if err != nil { return err @@ -195,7 +195,7 @@ func (r *NatsUserReconciler) reconcileSecret(ctx context.Context, user *natsv1al issuer := &natsv1alpha1.NatsAccount{} issuerName := client.ObjectKey{ - Namespace: user.Namespace, + Namespace: utilx.IfElse(utilx.Empty(user.Spec.AccountRef.Namespace), user.Namespace, user.Spec.AccountRef.Namespace), Name: user.Spec.AccountRef.Name, } diff --git a/examples/user.yaml b/examples/user.yaml index 10eee92..a8205fb 100644 --- a/examples/user.yaml +++ b/examples/user.yaml @@ -4,6 +4,7 @@ metadata: name: knative-eventing-user spec: accountRef: + namespace: default name: knative-eventing-account limits: payload: -1