1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-16 15:29:04 +00:00

Add watch filtering support for vai (#654)

* Add support for watch filtering

* Remove debug Println

* Validate watch selector
This commit is contained in:
Tom Lebreux
2025-06-03 16:10:36 -06:00
committed by GitHub
parent e3f207ddc2
commit b0aa90cd22
4 changed files with 263 additions and 13 deletions

View File

@@ -19,6 +19,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
apitypes "k8s.io/apimachinery/pkg/types"
@@ -36,6 +37,7 @@ import (
"github.com/rancher/steve/pkg/sqlcache/partition"
"github.com/rancher/steve/pkg/sqlcache/sqltypes"
"github.com/rancher/wrangler/v3/pkg/data"
"github.com/rancher/wrangler/v3/pkg/kv"
"github.com/rancher/wrangler/v3/pkg/schemas"
"github.com/rancher/wrangler/v3/pkg/schemas/validation"
"github.com/rancher/wrangler/v3/pkg/summary"
@@ -550,10 +552,30 @@ func (s *Store) watch(apiOp *types.APIRequest, schema *types.APISchema, w types.
return nil, err
}
result := make(chan watch.Event, 1000)
var selector labels.Selector
if w.Selector != "" {
selector, err = labels.Parse(w.Selector)
if err != nil {
return nil, fmt.Errorf("invalid selector: %w", err)
}
}
result := make(chan watch.Event)
go func() {
ctx := apiOp.Context()
err := inf.ByOptionsLister.Watch(ctx, informer.WatchOptions{}, result)
idNamespace, _ := kv.RSplit(w.ID, "/")
if idNamespace == "" {
idNamespace = apiOp.Namespace
}
opts := informer.WatchOptions{
Filter: informer.WatchFilter{
ID: w.ID,
Namespace: idNamespace,
Selector: selector,
},
}
err := inf.ByOptionsLister.Watch(ctx, opts, result)
if err != nil {
logrus.Error(err)
}