Support watching names and selector

This commit is contained in:
Darren Shepherd 2020-06-22 09:42:18 -07:00
parent 9571ce9890
commit a9c39ef89b
4 changed files with 19 additions and 6 deletions

View File

@ -67,7 +67,7 @@ func (p *partitioner) Lookup(apiOp *types.APIRequest, schema *types.APISchema, v
return nil, validation.NotFound return nil, validation.NotFound
} }
func (p *partitioner) All(apiOp *types.APIRequest, schema *types.APISchema, verb string) ([]partition.Partition, error) { func (p *partitioner) All(apiOp *types.APIRequest, schema *types.APISchema, verb, id string) ([]partition.Partition, error) {
return all, nil return all, nil
} }

View File

@ -11,7 +11,7 @@ import (
type Partitioner interface { type Partitioner interface {
Lookup(apiOp *types.APIRequest, schema *types.APISchema, verb, id string) (Partition, error) Lookup(apiOp *types.APIRequest, schema *types.APISchema, verb, id string) (Partition, error)
All(apiOp *types.APIRequest, schema *types.APISchema, verb string) ([]Partition, error) All(apiOp *types.APIRequest, schema *types.APISchema, verb, id string) ([]Partition, error)
Store(apiOp *types.APIRequest, partition Partition) (types.Store, error) Store(apiOp *types.APIRequest, partition Partition) (types.Store, error)
} }
@ -74,7 +74,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
result types.APIObjectList result types.APIObjectList
) )
paritions, err := s.Partitioner.All(apiOp, schema, "list") paritions, err := s.Partitioner.All(apiOp, schema, "list", "")
if err != nil { if err != nil {
return result, err return result, err
} }
@ -123,13 +123,13 @@ func (s *Store) Update(apiOp *types.APIRequest, schema *types.APISchema, data ty
} }
func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, wr types.WatchRequest) (chan types.APIEvent, error) { func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, wr types.WatchRequest) (chan types.APIEvent, error) {
partitions, err := s.Partitioner.All(apiOp, schema, "watch") partitions, err := s.Partitioner.All(apiOp, schema, "watch", wr.ID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
ctx, cancel := context.WithCancel(apiOp.Context()) ctx, cancel := context.WithCancel(apiOp.Context())
apiOp = apiOp.WithContext(ctx) apiOp = apiOp.Clone().WithContext(ctx)
eg := errgroup.Group{} eg := errgroup.Group{}
response := make(chan types.APIEvent) response := make(chan types.APIEvent)

View File

@ -287,6 +287,7 @@ func (s *Store) listAndWatch(apiOp *types.APIRequest, k8sClient dynamic.Resource
Watch: true, Watch: true,
TimeoutSeconds: &timeout, TimeoutSeconds: &timeout,
ResourceVersion: rev, ResourceVersion: rev,
LabelSelector: w.Selector,
}) })
if err != nil { if err != nil {
returnErr(errors.Wrapf(err, "stopping watch for %s: %v", schema.ID, err), result) returnErr(errors.Wrapf(err, "stopping watch for %s: %v", schema.ID, err), result)

View File

@ -10,6 +10,7 @@ import (
"github.com/rancher/steve/pkg/accesscontrol" "github.com/rancher/steve/pkg/accesscontrol"
"github.com/rancher/steve/pkg/attributes" "github.com/rancher/steve/pkg/attributes"
"github.com/rancher/steve/pkg/stores/partition" "github.com/rancher/steve/pkg/stores/partition"
"github.com/rancher/wrangler/pkg/kv"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
) )
@ -62,11 +63,22 @@ func (p *rbacPartitioner) Lookup(apiOp *types.APIRequest, schema *types.APISchem
} }
} }
func (p *rbacPartitioner) All(apiOp *types.APIRequest, schema *types.APISchema, verb string) ([]partition.Partition, error) { func (p *rbacPartitioner) All(apiOp *types.APIRequest, schema *types.APISchema, verb, id string) ([]partition.Partition, error) {
switch verb { switch verb {
case "list": case "list":
fallthrough fallthrough
case "watch": case "watch":
if id != "" {
ns, name := kv.RSplit(id, "/")
return []partition.Partition{
Partition{
Namespace: ns,
All: false,
Passthrough: false,
Names: sets.NewString(name),
},
}, nil
}
partitions, passthrough := isPassthrough(apiOp, schema, verb) partitions, passthrough := isPassthrough(apiOp, schema, verb)
if passthrough { if passthrough {
return passthroughPartitions, nil return passthroughPartitions, nil