@@ -50,6 +50,7 @@ import (
50
50
"sigs.k8s.io/controller-runtime/pkg/client"
51
51
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
52
52
"sigs.k8s.io/controller-runtime/pkg/event"
53
+ "sigs.k8s.io/controller-runtime/pkg/handler"
53
54
logf "sigs.k8s.io/controller-runtime/pkg/log"
54
55
"sigs.k8s.io/controller-runtime/pkg/predicate"
55
56
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -106,6 +107,11 @@ func (r *ReconcileGitopsService) SetupWithManager(mgr ctrl.Manager) error {
106
107
Owns (& appsv1.Deployment {}, builder .WithPredicates (pred )).
107
108
Owns (& corev1.Service {}, builder .WithPredicates (pred )).
108
109
Owns (& routev1.Route {}, builder .WithPredicates (pred )).
110
+ Watches (& corev1.Namespace {ObjectMeta : metav1.ObjectMeta {
111
+ Name : "openshift-gitops" ,
112
+ }},
113
+ handler .EnqueueRequestsFromMapFunc (namespaceMapper ),
114
+ ).
109
115
Complete (r )
110
116
}
111
117
@@ -219,7 +225,7 @@ func (r *ReconcileGitopsService) Reconcile(ctx context.Context, request reconcil
219
225
220
226
// Create namespace if it doesn't already exist
221
227
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 )
223
229
if err != nil {
224
230
if errors .IsNotFound (err ) {
225
231
reqLogger .Info ("Creating a new Namespace" , "Name" , namespace )
@@ -231,8 +237,8 @@ func (r *ReconcileGitopsService) Reconcile(ctx context.Context, request reconcil
231
237
return reconcile.Result {}, err
232
238
}
233
239
} else {
234
- needUpdate , updateNameSpace := ensurePodSecurityLabels (namespaceRef )
235
- if needUpdate {
240
+ needsUpdate , updateNameSpace := ensurePodSecurityLabels (namespaceRef )
241
+ if needsUpdate {
236
242
err = r .Client .Update (context .TODO (), updateNameSpace )
237
243
if err != nil {
238
244
return reconcile.Result {}, err
@@ -345,7 +351,7 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli
345
351
// 4.6 Cluster: Backend in openshift-pipelines-app-delivery namespace and argocd in openshift-gitops namespace
346
352
// 4.7 Cluster: Both backend and argocd instance in openshift-gitops namespace
347
353
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 )
349
355
if err != nil {
350
356
if errors .IsNotFound (err ) {
351
357
reqLogger .Info ("Creating a new Namespace" , "Name" , argocdNS .Name )
@@ -378,8 +384,8 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli
378
384
}
379
385
}
380
386
381
- needUpdate , updateNameSpace := ensurePodSecurityLabels (argocdNS )
382
- if needUpdate {
387
+ needsUpdate , updateNameSpace := ensurePodSecurityLabels (argocdNS )
388
+ if needsUpdate {
383
389
err = r .Client .Update (context .TODO (), updateNameSpace )
384
390
if err != nil {
385
391
return reconcile.Result {}, err
@@ -959,3 +965,17 @@ func ensurePodSecurityLabels(namespace *corev1.Namespace) (bool, *corev1.Namespa
959
965
}
960
966
return changed , namespace
961
967
}
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