From 810ad5bcf48762eb3fd4ac66ee3b973fc1d0f64e Mon Sep 17 00:00:00 2001 From: kahirokunn Date: Tue, 22 Oct 2024 13:16:50 +0900 Subject: [PATCH] feat(interceptor): add label filtering for HTTPScaledObjects Signed-off-by: kahirokunn --- interceptor/config/serving.go | 6 ++++++ interceptor/main.go | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/interceptor/config/serving.go b/interceptor/config/serving.go index d0a2ff5d0..a2a0d1130 100644 --- a/interceptor/config/serving.go +++ b/interceptor/config/serving.go @@ -15,6 +15,12 @@ type Serving struct { // WatchNamespace is the namespace to watch for new HTTPScaledObjects. // Leave this empty to watch HTTPScaledObjects in all namespaces. WatchNamespace string `envconfig:"KEDA_HTTP_WATCH_NAMESPACE" default:""` + // WatchLabel is the label to watch for new HTTPScaledObjects. + // Leave this empty to watch HTTPScaledObjects in all labels. + // + // Example: + // export KEDA_HTTP_WATCH_LABEL="scope=internal" + WatchLabel string `envconfig:"KEDA_HTTP_WATCH_LABEL" default:""` // ProxyPort is the port that the public proxy should run on ProxyPort int `envconfig:"KEDA_HTTP_PROXY_PORT" required:"true"` // AdminPort is the port that the internal admin server should run on. diff --git a/interceptor/main.go b/interceptor/main.go index 56f451165..99b6892ce 100644 --- a/interceptor/main.go +++ b/interceptor/main.go @@ -34,6 +34,8 @@ import ( "github.com/kedacore/http-add-on/pkg/queue" "github.com/kedacore/http-add-on/pkg/routing" "github.com/kedacore/http-add-on/pkg/util" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" ) var ( @@ -104,7 +106,22 @@ func main() { queues := queue.NewMemory() - sharedInformerFactory := informers.NewSharedInformerFactory(httpCl, servingCfg.ConfigMapCacheRsyncPeriod) + var labelSelector labels.Selector + if servingCfg.WatchLabel != "" { + labelSelector, err = labels.Parse(servingCfg.WatchLabel) + if err != nil { + setupLog.Error(err, "invalid WatchLabel format") + os.Exit(1) + } + } else { + labelSelector = labels.Everything() + } + + sharedInformerFactory := informers.NewSharedInformerFactoryWithOptions(httpCl, servingCfg.ConfigMapCacheRsyncPeriod, + informers.WithTweakListOptions(func(options *v1.ListOptions) { + options.LabelSelector = labelSelector.String() + }), + ) routingTable, err := routing.NewTable(sharedInformerFactory, servingCfg.WatchNamespace, queues) if err != nil { setupLog.Error(err, "fetching routing table")