1
0
mirror of https://github.com/rancher/norman.git synced 2025-07-15 08:01:53 +00:00

Track namespaces in options property

Now, identifies and assigns namespaces. Prior, the
backend listed items belongng to all namespaces in
all projects no matter what because they were not
being tracked. This led to longer request times
for projects that contained a fraction of total
resources. Now, rancher can filter project
resource requests; times are improved and
largely dependent on resource amount for the given
project.
This commit is contained in:
rmweir 2019-03-28 11:02:24 -07:00 committed by Craig Jellick
parent 9836657574
commit c55b1eed18
2 changed files with 37 additions and 4 deletions

View File

@ -17,6 +17,7 @@ import (
"github.com/rancher/norman/types/convert/merge"
"github.com/rancher/norman/types/values"
"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -192,11 +193,41 @@ func (s *Store) Context() types.StorageContext {
}
func (s *Store) List(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) ([]map[string]interface{}, error) {
namespace := getNamespace(apiContext, opt)
var resultList unstructured.UnstructuredList
resultList, err := s.retryList(namespace, apiContext)
if err != nil {
return nil, err
// if there are no namespaces field in options, a single request is made
if opt == nil || opt.Namespaces == nil {
ns := getNamespace(apiContext, opt)
list, err := s.retryList(ns, apiContext)
if err != nil {
return nil, err
}
resultList = *list
} else {
var (
errGroup errgroup.Group
mux sync.Mutex
)
allNS := opt.Namespaces
for _, ns := range allNS {
nsCopy := ns
errGroup.Go(func() error {
list, err := s.retryList(nsCopy, apiContext)
if err != nil {
return err
}
mux.Lock()
resultList.Items = append(resultList.Items, list.Items...)
mux.Unlock()
return nil
})
}
if err := errGroup.Wait(); err != nil {
return nil, err
}
}
var result []map[string]interface{}

View File

@ -184,6 +184,8 @@ type QueryOptions struct {
Pagination *Pagination
Conditions []*QueryCondition
Options map[string]string
// Set namespaces to an empty array will result in an empty response
Namespaces []string
}
type ReferenceValidator interface {