@@ -51,7 +51,6 @@ import (
5151 "sigs.k8s.io/controller-runtime/pkg/handler"
5252 "sigs.k8s.io/controller-runtime/pkg/predicate"
5353 "sigs.k8s.io/controller-runtime/pkg/reconcile"
54- "sigs.k8s.io/controller-runtime/pkg/source"
5554
5655 operatorv1 "github.com/IBM/ibm-namespace-scope-operator/v4/api/v1"
5756 util "github.com/IBM/ibm-namespace-scope-operator/v4/controllers/common"
@@ -94,7 +93,7 @@ func (r *NamespaceScopeReconciler) Reconcile(ctx context.Context, req ctrl.Reque
9493 // Remove NamespaceScopeFinalizer. Once all finalizers have been
9594 // removed, the object will be deleted.
9695 controllerutil .RemoveFinalizer (instance , constant .NamespaceScopeFinalizer )
97- if err := r .Update (ctx , instance ); err != nil {
96+ if err := r .Client . Update (ctx , instance ); err != nil {
9897 return ctrl.Result {}, err
9998 }
10099 }
@@ -183,7 +182,7 @@ func (r *NamespaceScopeReconciler) addFinalizer(ctx context.Context, nss *operat
183182 return nil
184183 }
185184 controllerutil .AddFinalizer (nss , constant .NamespaceScopeFinalizer )
186- if err := r .Update (ctx , nss ); err != nil {
185+ if err := r .Client . Update (ctx , nss ); err != nil {
187186 klog .Errorf ("Failed to update NamespaceScope with finalizer: %v" , err )
188187 return err
189188 }
@@ -201,7 +200,7 @@ func (r *NamespaceScopeReconciler) UpdateStatus(ctx context.Context, instance *o
201200 // Update instance status with the validated namespaces
202201 if ! util .StringSliceContentEqual (instance .Status .ValidatedMembers , validatedNamespaces ) {
203202 instance .Status .ValidatedMembers = validatedNamespaces
204- if err := r .Status ().Update (ctx , instance ); err != nil {
203+ if err := r .Client . Status ().Update (ctx , instance ); err != nil {
205204 klog .Errorf ("Failed to update instance %s/%s: %v" , instance .Namespace , instance .Name , err )
206205 return err
207206 }
@@ -233,7 +232,7 @@ func (r *NamespaceScopeReconciler) UpdateConfigMap(ctx context.Context, instance
233232 return err
234233 }
235234
236- if err := r .Create (ctx , cm ); err != nil {
235+ if err := r .Client . Create (ctx , cm ); err != nil {
237236 klog .Errorf ("Failed to create ConfigMap %s: %v" , cmKey .String (), err )
238237 return err
239238 }
@@ -258,7 +257,7 @@ func (r *NamespaceScopeReconciler) UpdateConfigMap(ctx context.Context, instance
258257 return err
259258 }
260259
261- if err := r .Update (ctx , cm ); err != nil {
260+ if err := r .Client . Update (ctx , cm ); err != nil {
262261 klog .Errorf ("Failed to update ConfigMap %s : %v" , cmKey .String (), err )
263262 return err
264263 }
@@ -450,7 +449,7 @@ func (r *NamespaceScopeReconciler) createRuntimeRoleForNSS(ctx context.Context,
450449 },
451450 Rules : summarizedRules ,
452451 }
453- if err := r .Create (ctx , role ); err != nil {
452+ if err := r .Client . Create (ctx , role ); err != nil {
454453 if errors .IsAlreadyExists (err ) {
455454 return err
456455 }
@@ -474,7 +473,7 @@ func (r *NamespaceScopeReconciler) updateRuntimeRoleForNSS(ctx context.Context,
474473 Rules : summarizedRules ,
475474 }
476475
477- if err := r .Update (ctx , role ); err != nil {
476+ if err := r .Client . Update (ctx , role ); err != nil {
478477 klog .Errorf ("Failed to create role %s/%s: %v" , namespace , name , err )
479478 return err
480479 }
@@ -658,9 +657,9 @@ func (r *NamespaceScopeReconciler) CreateRole(ctx context.Context, roleNames []s
658657 },
659658 Rules : rules ,
660659 }
661- if err := r .Create (ctx , role ); err != nil {
660+ if err := r .Client . Create (ctx , role ); err != nil {
662661 if errors .IsAlreadyExists (err ) {
663- if err := r .Update (ctx , role ); err != nil {
662+ if err := r .Client . Update (ctx , role ); err != nil {
664663 klog .Errorf ("Failed to update role %s/%s: %v" , namespace , name , err )
665664 return err
666665 }
@@ -679,7 +678,7 @@ func (r *NamespaceScopeReconciler) DeleteRole(ctx context.Context, labels map[st
679678 client .MatchingLabels (labels ),
680679 client .InNamespace (toNs ),
681680 }
682- if err := r .DeleteAllOf (ctx , & rbacv1.Role {}, opts ... ); err != nil {
681+ if err := r .Client . DeleteAllOf (ctx , & rbacv1.Role {}, opts ... ); err != nil {
683682 klog .Errorf ("Failed to delete role with labels %v in namespace %s: %v" , labels , toNs , err )
684683 return err
685684 }
@@ -713,7 +712,7 @@ func (r *NamespaceScopeReconciler) CreateRoleBinding(ctx context.Context, roleNa
713712 },
714713 }
715714
716- if err := r .Create (ctx , roleBinding ); err != nil {
715+ if err := r .Client . Create (ctx , roleBinding ); err != nil {
717716 if errors .IsAlreadyExists (err ) {
718717 return nil
719718 }
@@ -730,7 +729,7 @@ func (r *NamespaceScopeReconciler) DeleteRoleBinding(ctx context.Context, labels
730729 client .MatchingLabels (labels ),
731730 client .InNamespace (toNs ),
732731 }
733- if err := r .DeleteAllOf (ctx , & rbacv1.RoleBinding {}, opts ... ); err != nil {
732+ if err := r .Client . DeleteAllOf (ctx , & rbacv1.RoleBinding {}, opts ... ); err != nil {
734733 klog .Errorf ("Failed to delete rolebinding with labels %v in namespace %s: %v" , labels , toNs , err )
735734 return err
736735 }
@@ -804,7 +803,7 @@ func (r *NamespaceScopeReconciler) RestartPods(ctx context.Context, labels map[s
804803 deploy .Spec .Template .Annotations = make (map [string ]string )
805804 }
806805 deploy .Spec .Template .Annotations ["nss.ibm.com/namespaceList" ] = annotationValue
807- if err := r .Update (ctx , deploy ); err != nil {
806+ if err := r .Client . Update (ctx , deploy ); err != nil {
808807 klog .Errorf ("Failed to update the annotation of the deployment %s in namespace %s: %v" , deploymentName , namespace , err )
809808 return err
810809 }
@@ -823,7 +822,7 @@ func (r *NamespaceScopeReconciler) RestartPods(ctx context.Context, labels map[s
823822 daemonSet .Spec .Template .Annotations = make (map [string ]string )
824823 }
825824 daemonSet .Spec .Template .Annotations ["nss.ibm.com/namespaceList" ] = annotationValue
826- if err := r .Patch (ctx , daemonSet , client .MergeFrom (originalDaemonSet )); err != nil {
825+ if err := r .Client . Patch (ctx , daemonSet , client .MergeFrom (originalDaemonSet )); err != nil {
827826 klog .Errorf ("Failed to update the annotation of the daemonSet %s in namespace %s: %v" , daemonSetName , namespace , err )
828827 return err
829828 }
@@ -842,7 +841,7 @@ func (r *NamespaceScopeReconciler) RestartPods(ctx context.Context, labels map[s
842841 statefulSet .Spec .Template .Annotations = make (map [string ]string )
843842 }
844843 statefulSet .Spec .Template .Annotations ["nss.ibm.com/namespaceList" ] = annotationValue
845- if err := r .Patch (ctx , statefulSet , client .MergeFrom (originalStatefulSet )); err != nil {
844+ if err := r .Client . Patch (ctx , statefulSet , client .MergeFrom (originalStatefulSet )); err != nil {
846845 klog .Errorf ("Failed to update the annotation of the statefulSet %s in namespace %s: %v" , statefulSetName , namespace , err )
847846 return err
848847 }
@@ -909,7 +908,7 @@ func (r *NamespaceScopeReconciler) checkGetNSAuth(ctx context.Context) bool {
909908 },
910909 }
911910
912- if err := r .Create (ctx , sar ); err != nil {
911+ if err := r .Client . Create (ctx , sar ); err != nil {
913912 klog .Errorf ("Failed to check if operator has permission to get namespace: %v" , err )
914913 return false
915914 }
@@ -1278,7 +1277,7 @@ func (r *NamespaceScopeReconciler) patchMutatingWebhook(ctx context.Context, web
12781277 }
12791278 }
12801279 klog .Infof ("Patching webhook scope for: %s" , webhookconfig .Name )
1281- if err := r .Update (ctx , webhookconfig ); err != nil {
1280+ if err := r .Client . Update (ctx , webhookconfig ); err != nil {
12821281 klog .Errorf ("failed to update webhook %s: %v" , webhookconfig .Name , err )
12831282 return err
12841283 }
@@ -1318,78 +1317,77 @@ func (r *NamespaceScopeReconciler) patchValidatingWebhook(ctx context.Context, w
13181317 }
13191318
13201319 klog .Infof ("Patching webhookconfig scope for: %s" , webhookconfig .Name )
1321- if err := r .Update (ctx , webhookconfig ); err != nil {
1320+ if err := r .Client . Update (ctx , webhookconfig ); err != nil {
13221321 klog .Errorf ("failed to update webhook %s: %v" , webhookconfig .Name , err )
13231322 return err
13241323 }
13251324 return nil
13261325}
13271326
1328- func (r * NamespaceScopeReconciler ) csvtoRequest () handler.MapFunc {
1329- return func (object client.Object ) []ctrl.Request {
1330- nssList := & operatorv1.NamespaceScopeList {}
1331- err := r .Client .List (context .TODO (), nssList , & client.ListOptions {Namespace : object .GetNamespace ()})
1332- if err != nil {
1333- klog .Error (err )
1334- }
1335- requests := []ctrl.Request {}
1327+ func (r * NamespaceScopeReconciler ) csvtoRequest (ctx context.Context , obj client.Object ) []ctrl.Request {
1328+ nssList := & operatorv1.NamespaceScopeList {}
1329+ err := r .Client .List (context .TODO (), nssList , & client.ListOptions {Namespace : obj .GetNamespace ()})
1330+ if err != nil {
1331+ klog .Error (err )
1332+ }
1333+ requests := []ctrl.Request {}
13361334
1337- for _ , request := range nssList .Items {
1338- namespaceName := types.NamespacedName {Name : request .Name , Namespace : request .Namespace }
1339- req := ctrl.Request {NamespacedName : namespaceName }
1340- requests = append (requests , req )
1341- }
1342- return requests
1335+ for _ , request := range nssList .Items {
1336+ namespaceName := types.NamespacedName {Name : request .Name , Namespace : request .Namespace }
1337+ req := ctrl.Request {NamespacedName : namespaceName }
1338+ requests = append (requests , req )
13431339 }
1340+ return requests
1341+
13441342}
13451343
1346- func (r * NamespaceScopeReconciler ) validatingwebhookconfigtoRequest () handler.MapFunc {
1347- return func (object client.Object ) []ctrl.Request {
1348- nssList := & operatorv1.NamespaceScopeList {}
1349- err := r .Client .List (context .TODO (), nssList , & client.ListOptions {Namespace : object .GetNamespace ()})
1350- if err != nil {
1351- klog .Error (err )
1352- }
1353- requests := []ctrl.Request {}
1344+ func (r * NamespaceScopeReconciler ) validatingwebhookconfigtoRequest (ctx context.Context , obj client.Object ) []ctrl.Request {
1345+ nssList := & operatorv1.NamespaceScopeList {}
1346+ err := r .Client .List (context .TODO (), nssList , & client.ListOptions {Namespace : obj .GetNamespace ()})
1347+ if err != nil {
1348+ klog .Error (err )
1349+ }
1350+ requests := []ctrl.Request {}
13541351
1355- for _ , request := range nssList .Items {
1356- namespaceName := types.NamespacedName {Name : request .Name , Namespace : request .Namespace }
1357- req := ctrl.Request {NamespacedName : namespaceName }
1358- requests = append (requests , req )
1359- }
1360- return requests
1352+ for _ , request := range nssList .Items {
1353+ namespaceName := types.NamespacedName {Name : request .Name , Namespace : request .Namespace }
1354+ req := ctrl.Request {NamespacedName : namespaceName }
1355+ requests = append (requests , req )
13611356 }
1357+ return requests
1358+
13621359}
13631360
1364- func (r * NamespaceScopeReconciler ) mutatingwebhookconfigtoRequest () handler.MapFunc {
1365- return func (object client.Object ) []ctrl.Request {
1366- nssList := & operatorv1.NamespaceScopeList {}
1367- err := r .Client .List (context .TODO (), nssList , & client.ListOptions {Namespace : object .GetNamespace ()})
1368- if err != nil {
1369- klog .Error (err )
1370- }
1371- requests := []ctrl.Request {}
1361+ func (r * NamespaceScopeReconciler ) mutatingwebhookconfigtoRequest (ctx context.Context , obj client.Object ) []ctrl.Request {
1362+ nssList := & operatorv1.NamespaceScopeList {}
1363+ err := r .Client .List (context .TODO (), nssList , & client.ListOptions {Namespace : obj .GetNamespace ()})
1364+ if err != nil {
1365+ klog .Error (err )
1366+ }
1367+ requests := []ctrl.Request {}
13721368
1373- for _ , request := range nssList .Items {
1374- namespaceName := types.NamespacedName {Name : request .Name , Namespace : request .Namespace }
1375- req := ctrl.Request {NamespacedName : namespaceName }
1376- requests = append (requests , req )
1377- }
1378- return requests
1369+ for _ , request := range nssList .Items {
1370+ namespaceName := types.NamespacedName {Name : request .Name , Namespace : request .Namespace }
1371+ req := ctrl.Request {NamespacedName : namespaceName }
1372+ requests = append (requests , req )
13791373 }
1374+ return requests
1375+
13801376}
13811377
13821378func (r * NamespaceScopeReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
13831379 err := ctrl .NewControllerManagedBy (mgr ).
1380+ Named ("NamespaceScope contorller" ).
13841381 Owns (& corev1.ConfigMap {}).
13851382 For (& operatorv1.NamespaceScope {}).
13861383 Complete (reconcile .Func (r .Reconcile ))
13871384 if err != nil {
13881385 return err
13891386 }
13901387 err = ctrl .NewControllerManagedBy (mgr ).
1388+ Named ("NamespaceScope CSV contorller" ).
13911389 For (& operatorv1.NamespaceScope {}, builder .WithPredicates (predicate.GenerationChangedPredicate {})).
1392- Watches (& source. Kind { Type : & olmv1alpha1.ClusterServiceVersion {}} , handler .EnqueueRequestsFromMapFunc (r .csvtoRequest () ),
1390+ Watches (& olmv1alpha1.ClusterServiceVersion {}, handler .EnqueueRequestsFromMapFunc (r .csvtoRequest ),
13931391 builder .WithPredicates (predicate.Funcs {
13941392 DeleteFunc : func (e event.DeleteEvent ) bool {
13951393 // Evaluates to false if the object has been confirmed deleted.
@@ -1404,7 +1402,7 @@ func (r *NamespaceScopeReconciler) SetupWithManager(mgr ctrl.Manager) error {
14041402 return true
14051403 },
14061404 })).
1407- Watches (& source. Kind { Type : & admissionv1.ValidatingWebhookConfiguration {}} , handler .EnqueueRequestsFromMapFunc (r .validatingwebhookconfigtoRequest () ),
1405+ Watches (& admissionv1.ValidatingWebhookConfiguration {}, handler .EnqueueRequestsFromMapFunc (r .validatingwebhookconfigtoRequest ),
14081406 builder .WithPredicates (predicate.Funcs {
14091407 DeleteFunc : func (e event.DeleteEvent ) bool {
14101408 // Evaluates to false if the object has been confirmed deleted.
@@ -1419,7 +1417,7 @@ func (r *NamespaceScopeReconciler) SetupWithManager(mgr ctrl.Manager) error {
14191417 return true
14201418 },
14211419 })).
1422- Watches (& source. Kind { Type : & admissionv1.MutatingWebhookConfiguration {}} , handler .EnqueueRequestsFromMapFunc (r .mutatingwebhookconfigtoRequest () ),
1420+ Watches (& admissionv1.MutatingWebhookConfiguration {}, handler .EnqueueRequestsFromMapFunc (r .mutatingwebhookconfigtoRequest ),
14231421 builder .WithPredicates (predicate.Funcs {
14241422 DeleteFunc : func (e event.DeleteEvent ) bool {
14251423 // Evaluates to false if the object has been confirmed deleted.
0 commit comments