This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 1c9e062bd4cbcc02309f9350fee63c5409d0a3e1
Author: Antonin Stefanutti <anto...@stefanutti.fr>
AuthorDate: Thu Sep 30 16:43:44 2021 +0200

    chore: Limit Pods caching by Integration label selector
---
 pkg/cmd/operator/operator.go | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/pkg/cmd/operator/operator.go b/pkg/cmd/operator/operator.go
index 3d046ac..393c3d7 100644
--- a/pkg/cmd/operator/operator.go
+++ b/pkg/cmd/operator/operator.go
@@ -29,10 +29,13 @@ import (
 
        coordination "k8s.io/api/coordination/v1"
        corev1 "k8s.io/api/core/v1"
+       "k8s.io/apimachinery/pkg/labels"
+       "k8s.io/apimachinery/pkg/selection"
        "k8s.io/client-go/tools/leaderelection/resourcelock"
        "k8s.io/client-go/tools/record"
        "k8s.io/klog/v2"
 
+       "sigs.k8s.io/controller-runtime/pkg/cache"
        ctrl "sigs.k8s.io/controller-runtime/pkg/client"
        "sigs.k8s.io/controller-runtime/pkg/healthz"
        logf "sigs.k8s.io/controller-runtime/pkg/log"
@@ -41,6 +44,7 @@ import (
        "sigs.k8s.io/controller-runtime/pkg/manager/signals"
 
        "github.com/apache/camel-k/pkg/apis"
+       v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
        "github.com/apache/camel-k/pkg/client"
        "github.com/apache/camel-k/pkg/controller"
        "github.com/apache/camel-k/pkg/event"
@@ -124,6 +128,9 @@ func Run(healthPort, monitoringPort int32, leaderElection 
bool) {
                log.Info("Leader election is disabled!")
        }
 
+       podLabelSelector, err := labels.NewRequirement(v1.IntegrationLabel, 
selection.Exists, []string{})
+       exitOnError(err, "cannot create Pod labels selector")
+
        mgr, err := manager.New(c.GetConfig(), manager.Options{
                Namespace:                     watchNamespace,
                EventBroadcaster:              broadcaster,
@@ -134,6 +141,15 @@ func Run(healthPort, monitoringPort int32, leaderElection 
bool) {
                LeaderElectionReleaseOnCancel: true,
                HealthProbeBindAddress:        ":" + 
strconv.Itoa(int(healthPort)),
                MetricsBindAddress:            ":" + 
strconv.Itoa(int(monitoringPort)),
+               NewCache: cache.BuilderWithOptions(
+                       cache.Options{
+                               SelectorsByObject: cache.SelectorsByObject{
+                                       &corev1.Pod{}: {
+                                               Label: 
labels.NewSelector().Add(*podLabelSelector),
+                                       },
+                               },
+                       },
+               ),
        })
        exitOnError(err, "")
 

Reply via email to