Skip to content

Commit 810ad5b

Browse files
committed
feat(interceptor): add label filtering for HTTPScaledObjects
Signed-off-by: kahirokunn <[email protected]>
1 parent 6abd032 commit 810ad5b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

interceptor/config/serving.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ type Serving struct {
1515
// WatchNamespace is the namespace to watch for new HTTPScaledObjects.
1616
// Leave this empty to watch HTTPScaledObjects in all namespaces.
1717
WatchNamespace string `envconfig:"KEDA_HTTP_WATCH_NAMESPACE" default:""`
18+
// WatchLabel is the label to watch for new HTTPScaledObjects.
19+
// Leave this empty to watch HTTPScaledObjects in all labels.
20+
//
21+
// Example:
22+
// export KEDA_HTTP_WATCH_LABEL="scope=internal"
23+
WatchLabel string `envconfig:"KEDA_HTTP_WATCH_LABEL" default:""`
1824
// ProxyPort is the port that the public proxy should run on
1925
ProxyPort int `envconfig:"KEDA_HTTP_PROXY_PORT" required:"true"`
2026
// AdminPort is the port that the internal admin server should run on.

interceptor/main.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import (
3434
"github.com/kedacore/http-add-on/pkg/queue"
3535
"github.com/kedacore/http-add-on/pkg/routing"
3636
"github.com/kedacore/http-add-on/pkg/util"
37+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
38+
"k8s.io/apimachinery/pkg/labels"
3739
)
3840

3941
var (
@@ -104,7 +106,22 @@ func main() {
104106

105107
queues := queue.NewMemory()
106108

107-
sharedInformerFactory := informers.NewSharedInformerFactory(httpCl, servingCfg.ConfigMapCacheRsyncPeriod)
109+
var labelSelector labels.Selector
110+
if servingCfg.WatchLabel != "" {
111+
labelSelector, err = labels.Parse(servingCfg.WatchLabel)
112+
if err != nil {
113+
setupLog.Error(err, "invalid WatchLabel format")
114+
os.Exit(1)
115+
}
116+
} else {
117+
labelSelector = labels.Everything()
118+
}
119+
120+
sharedInformerFactory := informers.NewSharedInformerFactoryWithOptions(httpCl, servingCfg.ConfigMapCacheRsyncPeriod,
121+
informers.WithTweakListOptions(func(options *v1.ListOptions) {
122+
options.LabelSelector = labelSelector.String()
123+
}),
124+
)
108125
routingTable, err := routing.NewTable(sharedInformerFactory, servingCfg.WatchNamespace, queues)
109126
if err != nil {
110127
setupLog.Error(err, "fetching routing table")

0 commit comments

Comments
 (0)