From e4b7116d3b6e806dff863ebc61e4a473272164ee Mon Sep 17 00:00:00 2001 From: rmweir Date: Thu, 28 Mar 2019 11:02:24 -0700 Subject: [PATCH] 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. --- store/proxy/proxy_store.go | 39 ++++++++++++++++++++++++++++++++++---- types/server_types.go | 1 + 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/store/proxy/proxy_store.go b/store/proxy/proxy_store.go index 3fb722eca..cc0de88a2 100644 --- a/store/proxy/proxy_store.go +++ b/store/proxy/proxy_store.go @@ -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 apiContext.SubContext["/v3/schemas/project"] == "" { + 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{} diff --git a/types/server_types.go b/types/server_types.go index 7fede86f1..e42fd4298 100644 --- a/types/server_types.go +++ b/types/server_types.go @@ -184,6 +184,7 @@ type QueryOptions struct { Pagination *Pagination Conditions []*QueryCondition Options map[string]string + Namespaces []string } type ReferenceValidator interface {