Skip to content

Commit b7108b6

Browse files
committed
feat(interceptor): add label filtering for HTTPScaledObjects
Signed-off-by: kahirokunn <[email protected]>
1 parent 48a1881 commit b7108b6

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-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: 20 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,24 @@ 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+
setupLog.Info("watching label", "label", servingCfg.WatchLabel)
117+
} else {
118+
labelSelector = labels.Everything()
119+
setupLog.Info("watching all labels")
120+
}
121+
122+
sharedInformerFactory := informers.NewSharedInformerFactoryWithOptions(httpCl, servingCfg.ConfigMapCacheRsyncPeriod,
123+
informers.WithTweakListOptions(func(options *v1.ListOptions) {
124+
options.LabelSelector = labelSelector.String()
125+
}),
126+
)
108127
routingTable, err := routing.NewTable(sharedInformerFactory, servingCfg.WatchNamespace, queues)
109128
if err != nil {
110129
setupLog.Error(err, "fetching routing table")

0 commit comments

Comments
 (0)