Skip to content

Commit

Permalink
Track namespaces in options property
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rmweir committed Apr 1, 2019
1 parent d499db2 commit 49a37e1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
39 changes: 35 additions & 4 deletions store/proxy/proxy_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.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{}
Expand Down
2 changes: 2 additions & 0 deletions types/server_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 49a37e1

Please sign in to comment.