@@ -11,7 +11,6 @@ import (
11
11
"sync"
12
12
"time"
13
13
14
- "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/internal/alongside"
15
14
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/labeller"
16
15
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/validatingroundtripper"
17
16
errorwrap "github.com/pkg/errors"
@@ -187,6 +186,11 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
187
186
return nil , err
188
187
}
189
188
189
+ canFilter , err := labeller .Validate (ctx , logger , metadataClient )
190
+ if err != nil {
191
+ return nil , err
192
+ }
193
+
190
194
// Allocate the new instance of an Operator.
191
195
op := & Operator {
192
196
Operator : queueOperator ,
@@ -363,7 +367,14 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
363
367
}
364
368
365
369
// Wire k8s sharedIndexInformers
366
- k8sInformerFactory := informers .NewSharedInformerFactoryWithOptions (op .opClient .KubernetesInterface (), resyncPeriod ())
370
+ k8sInformerFactory := informers .NewSharedInformerFactoryWithOptions (op .opClient .KubernetesInterface (), resyncPeriod (), func () []informers.SharedInformerOption {
371
+ if ! canFilter {
372
+ return nil
373
+ }
374
+ return []informers.SharedInformerOption {informers .WithTweakListOptions (func (options * metav1.ListOptions ) {
375
+ options .LabelSelector = labels .SelectorFromSet (labels.Set {install .OLMManagedLabelKey : install .OLMManagedLabelValue }).String ()
376
+ })}
377
+ }()... )
367
378
sharedIndexInformers := []cache.SharedIndexInformer {}
368
379
369
380
// Wire Roles
@@ -372,6 +383,9 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
372
383
sharedIndexInformers = append (sharedIndexInformers , roleInformer .Informer ())
373
384
374
385
labelObjects := func (gvr schema.GroupVersionResource , informer cache.SharedIndexInformer , sync queueinformer.LegacySyncHandler ) error {
386
+ if canFilter {
387
+ return nil
388
+ }
375
389
op .k8sLabelQueueSets [gvr ] = workqueue .NewRateLimitingQueueWithConfig (workqueue .DefaultControllerRateLimiter (), workqueue.RateLimitingQueueConfig {
376
390
Name : gvr .String (),
377
391
})
@@ -392,8 +406,9 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
392
406
return nil
393
407
}
394
408
395
- if err := labelObjects (rbacv1 .SchemeGroupVersion .WithResource ("roles" ), roleInformer .Informer (), labeller .ObjectLabeler [* rbacv1.Role , * rbacv1applyconfigurations.RoleApplyConfiguration ](
396
- ctx , op .logger , labeller .HasOLMOwnerRef ,
409
+ rolesgvk := rbacv1 .SchemeGroupVersion .WithResource ("roles" )
410
+ if err := labelObjects (rolesgvk , roleInformer .Informer (), labeller .ObjectLabeler [* rbacv1.Role , * rbacv1applyconfigurations.RoleApplyConfiguration ](
411
+ ctx , op .logger , labeller .Filter (rolesgvk ),
397
412
rbacv1applyconfigurations .Role ,
398
413
func (namespace string , ctx context.Context , cfg * rbacv1applyconfigurations.RoleApplyConfiguration , opts metav1.ApplyOptions ) (* rbacv1.Role , error ) {
399
414
return op .opClient .KubernetesInterface ().RbacV1 ().Roles (namespace ).Apply (ctx , cfg , opts )
@@ -407,8 +422,9 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
407
422
op .lister .RbacV1 ().RegisterRoleBindingLister (metav1 .NamespaceAll , roleBindingInformer .Lister ())
408
423
sharedIndexInformers = append (sharedIndexInformers , roleBindingInformer .Informer ())
409
424
410
- if err := labelObjects (rbacv1 .SchemeGroupVersion .WithResource ("rolebindings" ), roleBindingInformer .Informer (), labeller .ObjectLabeler [* rbacv1.RoleBinding , * rbacv1applyconfigurations.RoleBindingApplyConfiguration ](
411
- ctx , op .logger , labeller .HasOLMOwnerRef ,
425
+ rolebindingsgvk := rbacv1 .SchemeGroupVersion .WithResource ("rolebindings" )
426
+ if err := labelObjects (rolebindingsgvk , roleBindingInformer .Informer (), labeller .ObjectLabeler [* rbacv1.RoleBinding , * rbacv1applyconfigurations.RoleBindingApplyConfiguration ](
427
+ ctx , op .logger , labeller .Filter (rolebindingsgvk ),
412
428
rbacv1applyconfigurations .RoleBinding ,
413
429
func (namespace string , ctx context.Context , cfg * rbacv1applyconfigurations.RoleBindingApplyConfiguration , opts metav1.ApplyOptions ) (* rbacv1.RoleBinding , error ) {
414
430
return op .opClient .KubernetesInterface ().RbacV1 ().RoleBindings (namespace ).Apply (ctx , cfg , opts )
@@ -422,10 +438,9 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
422
438
op .lister .CoreV1 ().RegisterServiceAccountLister (metav1 .NamespaceAll , serviceAccountInformer .Lister ())
423
439
sharedIndexInformers = append (sharedIndexInformers , serviceAccountInformer .Informer ())
424
440
425
- if err := labelObjects (corev1 .SchemeGroupVersion .WithResource ("serviceaccounts" ), serviceAccountInformer .Informer (), labeller .ObjectLabeler [* corev1.ServiceAccount , * corev1applyconfigurations.ServiceAccountApplyConfiguration ](
426
- ctx , op .logger , func (object metav1.Object ) bool {
427
- return labeller .HasOLMOwnerRef (object ) || labeller .HasOLMLabel (object )
428
- },
441
+ serviceaccountsgvk := corev1 .SchemeGroupVersion .WithResource ("serviceaccounts" )
442
+ if err := labelObjects (serviceaccountsgvk , serviceAccountInformer .Informer (), labeller .ObjectLabeler [* corev1.ServiceAccount , * corev1applyconfigurations.ServiceAccountApplyConfiguration ](
443
+ ctx , op .logger , labeller .Filter (serviceaccountsgvk ),
429
444
corev1applyconfigurations .ServiceAccount ,
430
445
func (namespace string , ctx context.Context , cfg * corev1applyconfigurations.ServiceAccountApplyConfiguration , opts metav1.ApplyOptions ) (* corev1.ServiceAccount , error ) {
431
446
return op .opClient .KubernetesInterface ().CoreV1 ().ServiceAccounts (namespace ).Apply (ctx , cfg , opts )
@@ -439,8 +454,9 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
439
454
op .lister .CoreV1 ().RegisterServiceLister (metav1 .NamespaceAll , serviceInformer .Lister ())
440
455
sharedIndexInformers = append (sharedIndexInformers , serviceInformer .Informer ())
441
456
442
- if err := labelObjects (corev1 .SchemeGroupVersion .WithResource ("services" ), serviceInformer .Informer (), labeller .ObjectLabeler [* corev1.Service , * corev1applyconfigurations.ServiceApplyConfiguration ](
443
- ctx , op .logger , labeller .HasOLMOwnerRef ,
457
+ servicesgvk := corev1 .SchemeGroupVersion .WithResource ("services" )
458
+ if err := labelObjects (servicesgvk , serviceInformer .Informer (), labeller .ObjectLabeler [* corev1.Service , * corev1applyconfigurations.ServiceApplyConfiguration ](
459
+ ctx , op .logger , labeller .Filter (servicesgvk ),
444
460
corev1applyconfigurations .Service ,
445
461
func (namespace string , ctx context.Context , cfg * corev1applyconfigurations.ServiceApplyConfiguration , opts metav1.ApplyOptions ) (* corev1.Service , error ) {
446
462
return op .opClient .KubernetesInterface ().CoreV1 ().Services (namespace ).Apply (ctx , cfg , opts )
@@ -463,11 +479,9 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
463
479
op .lister .CoreV1 ().RegisterPodLister (metav1 .NamespaceAll , csPodInformer .Lister ())
464
480
sharedIndexInformers = append (sharedIndexInformers , csPodInformer .Informer ())
465
481
466
- if err := labelObjects (corev1 .SchemeGroupVersion .WithResource ("pods" ), csPodInformer .Informer (), labeller .ObjectLabeler [* corev1.Pod , * corev1applyconfigurations.PodApplyConfiguration ](
467
- ctx , op .logger , func (object metav1.Object ) bool {
468
- _ , ok := object .GetLabels ()[reconciler .CatalogSourceLabelKey ]
469
- return ok
470
- },
482
+ podsgvk := corev1 .SchemeGroupVersion .WithResource ("pods" )
483
+ if err := labelObjects (podsgvk , csPodInformer .Informer (), labeller .ObjectLabeler [* corev1.Pod , * corev1applyconfigurations.PodApplyConfiguration ](
484
+ ctx , op .logger , labeller .Filter (podsgvk ),
471
485
corev1applyconfigurations .Pod ,
472
486
func (namespace string , ctx context.Context , cfg * corev1applyconfigurations.PodApplyConfiguration , opts metav1.ApplyOptions ) (* corev1.Pod , error ) {
473
487
return op .opClient .KubernetesInterface ().CoreV1 ().Pods (namespace ).Apply (ctx , cfg , opts )
@@ -500,19 +514,11 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
500
514
jobInformer := k8sInformerFactory .Batch ().V1 ().Jobs ()
501
515
sharedIndexInformers = append (sharedIndexInformers , jobInformer .Informer ())
502
516
503
- if err := labelObjects (batchv1 .SchemeGroupVersion .WithResource ("jobs" ), jobInformer .Informer (), labeller .ObjectLabeler [* batchv1.Job , * batchv1applyconfigurations.JobApplyConfiguration ](
504
- ctx , op .logger , func (object metav1.Object ) bool {
505
- for _ , ownerRef := range object .GetOwnerReferences () {
506
- if ownerRef .APIVersion == corev1 .SchemeGroupVersion .String () && ownerRef .Kind == "ConfigMap" {
507
- cm , err := configMapInformer .Lister ().ConfigMaps (object .GetNamespace ()).Get (ownerRef .Name )
508
- if err != nil {
509
- return false
510
- }
511
- return labeller .HasOLMOwnerRef (cm )
512
- }
513
- }
514
- return false
515
- },
517
+ jobsgvk := batchv1 .SchemeGroupVersion .WithResource ("jobs" )
518
+ if err := labelObjects (jobsgvk , jobInformer .Informer (), labeller .ObjectLabeler [* batchv1.Job , * batchv1applyconfigurations.JobApplyConfiguration ](
519
+ ctx , op .logger , labeller .JobFilter (func (namespace , name string ) (metav1.Object , error ) {
520
+ return configMapInformer .Lister ().ConfigMaps (namespace ).Get (name )
521
+ }),
516
522
batchv1applyconfigurations .Job ,
517
523
func (namespace string , ctx context.Context , cfg * batchv1applyconfigurations.JobApplyConfiguration , opts metav1.ApplyOptions ) (* batchv1.Job , error ) {
518
524
return op .opClient .KubernetesInterface ().BatchV1 ().Jobs (namespace ).Apply (ctx , cfg , opts )
@@ -585,15 +591,9 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
585
591
return nil , err
586
592
}
587
593
588
- if err := labelObjects (apiextensionsv1 .SchemeGroupVersion .WithResource ("customresourcedefinitions" ), crdInformer , labeller .ObjectPatchLabeler (
589
- ctx , op .logger , func (object metav1.Object ) bool {
590
- for key := range object .GetAnnotations () {
591
- if strings .HasPrefix (key , alongside .AnnotationPrefix ) {
592
- return true
593
- }
594
- }
595
- return false
596
- },
594
+ customresourcedefinitionsgvk := apiextensionsv1 .SchemeGroupVersion .WithResource ("customresourcedefinitions" )
595
+ if err := labelObjects (customresourcedefinitionsgvk , crdInformer , labeller .ObjectPatchLabeler (
596
+ ctx , op .logger , labeller .Filter (customresourcedefinitionsgvk ),
597
597
op .opClient .ApiextensionsInterface ().ApiextensionsV1 ().CustomResourceDefinitions ().Patch ,
598
598
)); err != nil {
599
599
return nil , err
0 commit comments