Skip to content

Commit

Permalink
feat(interceptor): add label filtering for HTTPScaledObjects
Browse files Browse the repository at this point in the history
Signed-off-by: kahirokunn <[email protected]>
  • Loading branch information
kahirokunn committed Oct 22, 2024
1 parent 48a1881 commit ed529df
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions interceptor/config/serving.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 18 additions & 1 deletion interceptor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit ed529df

Please sign in to comment.