@@ -50,6 +50,7 @@ import (
5050 "sigs.k8s.io/controller-runtime/pkg/client"
5151 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
5252 "sigs.k8s.io/controller-runtime/pkg/event"
53+ "sigs.k8s.io/controller-runtime/pkg/handler"
5354 logf "sigs.k8s.io/controller-runtime/pkg/log"
5455 "sigs.k8s.io/controller-runtime/pkg/predicate"
5556 "sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -106,6 +107,11 @@ func (r *ReconcileGitopsService) SetupWithManager(mgr ctrl.Manager) error {
106107 Owns (& appsv1.Deployment {}, builder .WithPredicates (pred )).
107108 Owns (& corev1.Service {}, builder .WithPredicates (pred )).
108109 Owns (& routev1.Route {}, builder .WithPredicates (pred )).
110+ Watches (& corev1.Namespace {ObjectMeta : metav1.ObjectMeta {
111+ Name : "openshift-gitops" ,
112+ }},
113+ handler .EnqueueRequestsFromMapFunc (namespaceMapper ),
114+ ).
109115 Complete (r )
110116}
111117
@@ -219,7 +225,7 @@ func (r *ReconcileGitopsService) Reconcile(ctx context.Context, request reconcil
219225
220226 // Create namespace if it doesn't already exist
221227 namespaceRef := newRestrictedNamespace (namespace )
222- err = r .Client .Get (ctx , types.NamespacedName {Name : namespace }, & corev1. Namespace {} )
228+ err = r .Client .Get (ctx , types.NamespacedName {Name : namespace }, namespaceRef )
223229 if err != nil {
224230 if errors .IsNotFound (err ) {
225231 reqLogger .Info ("Creating a new Namespace" , "Name" , namespace )
@@ -231,8 +237,8 @@ func (r *ReconcileGitopsService) Reconcile(ctx context.Context, request reconcil
231237 return reconcile.Result {}, err
232238 }
233239 } else {
234- needUpdate , updateNameSpace := ensurePodSecurityLabels (namespaceRef )
235- if needUpdate {
240+ needsUpdate , updateNameSpace := ensurePodSecurityLabels (namespaceRef )
241+ if needsUpdate {
236242 err = r .Client .Update (context .TODO (), updateNameSpace )
237243 if err != nil {
238244 return reconcile.Result {}, err
@@ -345,7 +351,7 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli
345351 // 4.6 Cluster: Backend in openshift-pipelines-app-delivery namespace and argocd in openshift-gitops namespace
346352 // 4.7 Cluster: Both backend and argocd instance in openshift-gitops namespace
347353 argocdNS := newRestrictedNamespace (defaultArgoCDInstance .Namespace )
348- err = r .Client .Get (context .TODO (), types.NamespacedName {Name : argocdNS .Name }, & corev1. Namespace {} )
354+ err = r .Client .Get (context .TODO (), types.NamespacedName {Name : argocdNS .Name }, argocdNS )
349355 if err != nil {
350356 if errors .IsNotFound (err ) {
351357 reqLogger .Info ("Creating a new Namespace" , "Name" , argocdNS .Name )
@@ -378,8 +384,8 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli
378384 }
379385 }
380386
381- needUpdate , updateNameSpace := ensurePodSecurityLabels (argocdNS )
382- if needUpdate {
387+ needsUpdate , updateNameSpace := ensurePodSecurityLabels (argocdNS )
388+ if needsUpdate {
383389 err = r .Client .Update (context .TODO (), updateNameSpace )
384390 if err != nil {
385391 return reconcile.Result {}, err
@@ -959,3 +965,17 @@ func ensurePodSecurityLabels(namespace *corev1.Namespace) (bool, *corev1.Namespa
959965 }
960966 return changed , namespace
961967}
968+
969+ func namespaceMapper (ctx context.Context , o client.Object ) []reconcile.Request {
970+ // var result = []reconcile.Request{}
971+ namespacedName := client.ObjectKey {
972+ Name : o .GetName (),
973+ }
974+ // result := []reconcile.Request{
975+ // {NamespacedName: namespacedName},
976+ // }
977+ // return result
978+ return []reconcile.Request {
979+ {NamespacedName : namespacedName },
980+ }
981+ }
0 commit comments