Skip to content

Commit

Permalink
Merge pull request #649 from huiwq1990/feat-clusterfilter
Browse files Browse the repository at this point in the history
support cluster filter when use memory storage
  • Loading branch information
Iceber authored Feb 19, 2024
2 parents fb92fc1 + fd432ed commit 9f61bd2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/storage/memorystorage/watchcache/watch_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/watch"
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic/registry"
Expand Down Expand Up @@ -303,7 +304,18 @@ func (w *WatchCache) WaitUntilFreshAndList(opts *internal.ListOptions) ([]*Store
}*/
var result []*StoreElement
accessor := meta.NewAccessor()
for _, store := range w.stores {
searchAllCluster := true
searchClusters := sets.NewString()
if opts != nil && len(opts.ClusterNames) != 0 {
for _, tmp := range opts.ClusterNames {
searchClusters.Insert(tmp)
}
searchAllCluster = false
}
for cluster, store := range w.stores {
if !searchAllCluster && !searchClusters.Has(cluster) {
continue
}
for _, obj := range store.List() {
se := obj.(*StoreElement)
ns, err := accessor.Namespace(se.Object)
Expand Down

0 comments on commit 9f61bd2

Please sign in to comment.