mirror of
https://github.com/rancher/steve.git
synced 2025-09-08 18:59:58 +00:00
[v2.9] Virtual Resource filters (#288)
Adds logic which adds virtual fields resources. This allows these fields to be sorted/filtered on when the SQL cache is enabled. Id and metadata.state.name were added as the first two fields. Co-authored-by: Michael Bolot <michael.bolot@suse.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/rancher/steve/pkg/stores/sqlproxy (interfaces: Cache,ClientGetter,CacheFactory,SchemaColumnSetter,RelationshipNotifier)
|
||||
// Source: github.com/rancher/steve/pkg/stores/sqlproxy (interfaces: Cache,ClientGetter,CacheFactory,SchemaColumnSetter,RelationshipNotifier,TransformBuilder)
|
||||
|
||||
// Package sqlproxy is a generated GoMock package.
|
||||
package sqlproxy
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
dynamic "k8s.io/client-go/dynamic"
|
||||
kubernetes "k8s.io/client-go/kubernetes"
|
||||
rest "k8s.io/client-go/rest"
|
||||
cache "k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
// MockCache is a mock of Cache interface.
|
||||
@@ -257,18 +258,18 @@ func (m *MockCacheFactory) EXPECT() *MockCacheFactoryMockRecorder {
|
||||
}
|
||||
|
||||
// CacheFor mocks base method.
|
||||
func (m *MockCacheFactory) CacheFor(arg0 [][]string, arg1 dynamic.ResourceInterface, arg2 schema.GroupVersionKind, arg3 bool) (factory.Cache, error) {
|
||||
func (m *MockCacheFactory) CacheFor(arg0 [][]string, arg1 cache.TransformFunc, arg2 dynamic.ResourceInterface, arg3 schema.GroupVersionKind, arg4 bool) (factory.Cache, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CacheFor", arg0, arg1, arg2, arg3)
|
||||
ret := m.ctrl.Call(m, "CacheFor", arg0, arg1, arg2, arg3, arg4)
|
||||
ret0, _ := ret[0].(factory.Cache)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// CacheFor indicates an expected call of CacheFor.
|
||||
func (mr *MockCacheFactoryMockRecorder) CacheFor(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
|
||||
func (mr *MockCacheFactoryMockRecorder) CacheFor(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CacheFor", reflect.TypeOf((*MockCacheFactory)(nil).CacheFor), arg0, arg1, arg2, arg3)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CacheFor", reflect.TypeOf((*MockCacheFactory)(nil).CacheFor), arg0, arg1, arg2, arg3, arg4)
|
||||
}
|
||||
|
||||
// Reset mocks base method.
|
||||
@@ -358,3 +359,40 @@ func (mr *MockRelationshipNotifierMockRecorder) OnInboundRelationshipChange(arg0
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnInboundRelationshipChange", reflect.TypeOf((*MockRelationshipNotifier)(nil).OnInboundRelationshipChange), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// MockTransformBuilder is a mock of TransformBuilder interface.
|
||||
type MockTransformBuilder struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockTransformBuilderMockRecorder
|
||||
}
|
||||
|
||||
// MockTransformBuilderMockRecorder is the mock recorder for MockTransformBuilder.
|
||||
type MockTransformBuilderMockRecorder struct {
|
||||
mock *MockTransformBuilder
|
||||
}
|
||||
|
||||
// NewMockTransformBuilder creates a new mock instance.
|
||||
func NewMockTransformBuilder(ctrl *gomock.Controller) *MockTransformBuilder {
|
||||
mock := &MockTransformBuilder{ctrl: ctrl}
|
||||
mock.recorder = &MockTransformBuilderMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockTransformBuilder) EXPECT() *MockTransformBuilderMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// GetTransformFunc mocks base method.
|
||||
func (m *MockTransformBuilder) GetTransformFunc(arg0 schema.GroupVersionKind) cache.TransformFunc {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetTransformFunc", arg0)
|
||||
ret0, _ := ret[0].(cache.TransformFunc)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetTransformFunc indicates an expected call of GetTransformFunc.
|
||||
func (mr *MockTransformBuilderMockRecorder) GetTransformFunc(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransformFunc", reflect.TypeOf((*MockTransformBuilder)(nil).GetTransformFunc), arg0)
|
||||
}
|
||||
|
@@ -15,6 +15,15 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/rancher/steve/pkg/attributes"
|
||||
"github.com/rancher/steve/pkg/resources/common"
|
||||
"github.com/rancher/steve/pkg/resources/virtual"
|
||||
virtualCommon "github.com/rancher/steve/pkg/resources/virtual/common"
|
||||
metricsStore "github.com/rancher/steve/pkg/stores/metrics"
|
||||
"github.com/rancher/steve/pkg/stores/sqlpartition/listprocessor"
|
||||
"github.com/rancher/steve/pkg/stores/sqlproxy/tablelistconvert"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
@@ -39,11 +48,7 @@ import (
|
||||
"github.com/rancher/wrangler/v3/pkg/schemas/validation"
|
||||
"github.com/rancher/wrangler/v3/pkg/summary"
|
||||
|
||||
"github.com/rancher/steve/pkg/attributes"
|
||||
"github.com/rancher/steve/pkg/resources/common"
|
||||
metricsStore "github.com/rancher/steve/pkg/stores/metrics"
|
||||
"github.com/rancher/steve/pkg/stores/sqlpartition/listprocessor"
|
||||
"github.com/rancher/steve/pkg/stores/sqlproxy/tablelistconvert"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -63,6 +68,10 @@ var (
|
||||
|
||||
"management.cattle.io_v3_Node": {{`status`, `nodeName`}},
|
||||
}
|
||||
commonIndexFields = [][]string{
|
||||
{`id`},
|
||||
{`metadata`, `state`, `name`},
|
||||
}
|
||||
baseNSSchema = types.APISchema{
|
||||
Schema: &schemas.Schema{
|
||||
Attributes: map[string]interface{}{
|
||||
@@ -124,29 +133,35 @@ type RelationshipNotifier interface {
|
||||
OnInboundRelationshipChange(ctx context.Context, schema *types.APISchema, namespace string) <-chan *summary.Relationship
|
||||
}
|
||||
|
||||
type TransformBuilder interface {
|
||||
GetTransformFunc(gvk schema.GroupVersionKind) cache.TransformFunc
|
||||
}
|
||||
|
||||
type Store struct {
|
||||
clientGetter ClientGetter
|
||||
notifier RelationshipNotifier
|
||||
cacheFactory CacheFactory
|
||||
cfInitializer CacheFactoryInitializer
|
||||
namespaceCache Cache
|
||||
lock sync.Mutex
|
||||
columnSetter SchemaColumnSetter
|
||||
clientGetter ClientGetter
|
||||
notifier RelationshipNotifier
|
||||
cacheFactory CacheFactory
|
||||
cfInitializer CacheFactoryInitializer
|
||||
namespaceCache Cache
|
||||
lock sync.Mutex
|
||||
columnSetter SchemaColumnSetter
|
||||
transformBuilder TransformBuilder
|
||||
}
|
||||
|
||||
type CacheFactoryInitializer func() (CacheFactory, error)
|
||||
|
||||
type CacheFactory interface {
|
||||
CacheFor(fields [][]string, client dynamic.ResourceInterface, gvk schema.GroupVersionKind, namespaced bool) (factory.Cache, error)
|
||||
CacheFor(fields [][]string, transform cache.TransformFunc, client dynamic.ResourceInterface, gvk schema.GroupVersionKind, namespaced bool) (factory.Cache, error)
|
||||
Reset() error
|
||||
}
|
||||
|
||||
// NewProxyStore returns a Store implemented directly on top of kubernetes.
|
||||
func NewProxyStore(c SchemaColumnSetter, clientGetter ClientGetter, notifier RelationshipNotifier, factory CacheFactory) (*Store, error) {
|
||||
func NewProxyStore(c SchemaColumnSetter, clientGetter ClientGetter, notifier RelationshipNotifier, scache virtualCommon.SummaryCache, factory CacheFactory) (*Store, error) {
|
||||
store := &Store{
|
||||
clientGetter: clientGetter,
|
||||
notifier: notifier,
|
||||
columnSetter: c,
|
||||
clientGetter: clientGetter,
|
||||
notifier: notifier,
|
||||
columnSetter: c,
|
||||
transformBuilder: virtual.NewTransformBuilder(scache),
|
||||
}
|
||||
|
||||
if factory == nil {
|
||||
@@ -203,14 +218,18 @@ func (s *Store) initializeNamespaceCache() error {
|
||||
return err
|
||||
}
|
||||
|
||||
gvk := attributes.GVK(&nsSchema)
|
||||
// get fields from schema's columns
|
||||
fields := getFieldsFromSchema(&nsSchema)
|
||||
|
||||
// get any type-specific fields that steve is interested in
|
||||
fields = append(fields, getFieldForGVK(attributes.GVK(&nsSchema))...)
|
||||
fields = append(fields, getFieldForGVK(gvk)...)
|
||||
|
||||
// get the type-specifc transform func
|
||||
transformFunc := s.transformBuilder.GetTransformFunc(gvk)
|
||||
|
||||
// get the ns informer
|
||||
nsInformer, err := s.cacheFactory.CacheFor(fields, &tablelistconvert.Client{ResourceInterface: client}, attributes.GVK(&nsSchema), false)
|
||||
nsInformer, err := s.cacheFactory.CacheFor(fields, transformFunc, &tablelistconvert.Client{ResourceInterface: client}, attributes.GVK(&nsSchema), false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -220,7 +239,13 @@ func (s *Store) initializeNamespaceCache() error {
|
||||
}
|
||||
|
||||
func getFieldForGVK(gvk schema.GroupVersionKind) [][]string {
|
||||
return typeSpecificIndexedFields[keyFromGVK(gvk)]
|
||||
fields := [][]string{}
|
||||
fields = append(fields, commonIndexFields...)
|
||||
typeFields := typeSpecificIndexedFields[keyFromGVK(gvk)]
|
||||
if typeFields != nil {
|
||||
fields = append(fields, typeFields...)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
func keyFromGVK(gvk schema.GroupVersionKind) string {
|
||||
@@ -639,10 +664,12 @@ func (s *Store) ListByPartitions(apiOp *types.APIRequest, schema *types.APISchem
|
||||
if err != nil {
|
||||
return nil, 0, "", err
|
||||
}
|
||||
gvk := attributes.GVK(schema)
|
||||
fields := getFieldsFromSchema(schema)
|
||||
fields = append(fields, getFieldForGVK(attributes.GVK(schema))...)
|
||||
fields = append(fields, getFieldForGVK(gvk)...)
|
||||
transformFunc := s.transformBuilder.GetTransformFunc(gvk)
|
||||
|
||||
inf, err := s.cacheFactory.CacheFor(fields, &tablelistconvert.Client{ResourceInterface: client}, attributes.GVK(schema), attributes.Namespaced(schema))
|
||||
inf, err := s.cacheFactory.CacheFor(fields, transformFunc, &tablelistconvert.Client{ResourceInterface: client}, attributes.GVK(schema), attributes.Namespaced(schema))
|
||||
if err != nil {
|
||||
return nil, 0, "", err
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ import (
|
||||
clientgotesting "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
//go:generate mockgen --build_flags=--mod=mod -package sqlproxy -destination ./proxy_mocks_test.go github.com/rancher/steve/pkg/stores/sqlproxy Cache,ClientGetter,CacheFactory,SchemaColumnSetter,RelationshipNotifier
|
||||
//go:generate mockgen --build_flags=--mod=mod -package sqlproxy -destination ./proxy_mocks_test.go github.com/rancher/steve/pkg/stores/sqlproxy Cache,ClientGetter,CacheFactory,SchemaColumnSetter,RelationshipNotifier,TransformBuilder
|
||||
//go:generate mockgen --build_flags=--mod=mod -package sqlproxy -destination ./sql_informer_mocks_test.go github.com/rancher/lasso/pkg/cache/sql/informer ByOptionsLister
|
||||
//go:generate mockgen --build_flags=--mod=mod -package sqlproxy -destination ./dynamic_mocks_test.go k8s.io/client-go/dynamic ResourceInterface
|
||||
|
||||
@@ -82,9 +82,9 @@ func TestNewProxyStore(t *testing.T) {
|
||||
nsSchema := baseNSSchema
|
||||
scc.EXPECT().SetColumns(context.Background(), &nsSchema).Return(nil)
|
||||
cg.EXPECT().TableAdminClient(nil, &nsSchema, "", &WarningBuffer{}).Return(ri, nil)
|
||||
cf.EXPECT().CacheFor([][]string{{"metadata", "labels[field.cattle.io/projectId]"}}, &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(&nsSchema), false).Return(c, nil)
|
||||
cf.EXPECT().CacheFor([][]string{{`id`}, {`metadata`, `state`, `name`}, {"metadata", "labels[field.cattle.io/projectId]"}}, gomock.Any(), &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(&nsSchema), false).Return(c, nil)
|
||||
|
||||
s, err := NewProxyStore(scc, cg, rn, cf)
|
||||
s, err := NewProxyStore(scc, cg, rn, nil, cf)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, scc, s.columnSetter)
|
||||
assert.Equal(t, cg, s.clientGetter)
|
||||
@@ -105,7 +105,7 @@ func TestNewProxyStore(t *testing.T) {
|
||||
nsSchema := baseNSSchema
|
||||
scc.EXPECT().SetColumns(context.Background(), &nsSchema).Return(fmt.Errorf("error"))
|
||||
|
||||
s, err := NewProxyStore(scc, cg, rn, cf)
|
||||
s, err := NewProxyStore(scc, cg, rn, nil, cf)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, scc, s.columnSetter)
|
||||
assert.Equal(t, cg, s.clientGetter)
|
||||
@@ -127,7 +127,7 @@ func TestNewProxyStore(t *testing.T) {
|
||||
scc.EXPECT().SetColumns(context.Background(), &nsSchema).Return(nil)
|
||||
cg.EXPECT().TableAdminClient(nil, &nsSchema, "", &WarningBuffer{}).Return(nil, fmt.Errorf("error"))
|
||||
|
||||
s, err := NewProxyStore(scc, cg, rn, cf)
|
||||
s, err := NewProxyStore(scc, cg, rn, nil, cf)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, scc, s.columnSetter)
|
||||
assert.Equal(t, cg, s.clientGetter)
|
||||
@@ -149,9 +149,9 @@ func TestNewProxyStore(t *testing.T) {
|
||||
nsSchema := baseNSSchema
|
||||
scc.EXPECT().SetColumns(context.Background(), &nsSchema).Return(nil)
|
||||
cg.EXPECT().TableAdminClient(nil, &nsSchema, "", &WarningBuffer{}).Return(ri, nil)
|
||||
cf.EXPECT().CacheFor([][]string{{"metadata", "labels[field.cattle.io/projectId]"}}, &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(&nsSchema), false).Return(factory.Cache{}, fmt.Errorf("error"))
|
||||
cf.EXPECT().CacheFor([][]string{{`id`}, {`metadata`, `state`, `name`}, {"metadata", "labels[field.cattle.io/projectId]"}}, gomock.Any(), &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(&nsSchema), false).Return(factory.Cache{}, fmt.Errorf("error"))
|
||||
|
||||
s, err := NewProxyStore(scc, cg, rn, cf)
|
||||
s, err := NewProxyStore(scc, cg, rn, nil, cf)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, scc, s.columnSetter)
|
||||
assert.Equal(t, cg, s.clientGetter)
|
||||
@@ -181,6 +181,7 @@ func TestListByPartitions(t *testing.T) {
|
||||
cf := NewMockCacheFactory(gomock.NewController(t))
|
||||
ri := NewMockResourceInterface(gomock.NewController(t))
|
||||
bloi := NewMockByOptionsLister(gomock.NewController(t))
|
||||
tb := NewMockTransformBuilder(gomock.NewController(t))
|
||||
inf := &informer.Informer{
|
||||
ByOptionsLister: bloi,
|
||||
}
|
||||
@@ -188,9 +189,10 @@ func TestListByPartitions(t *testing.T) {
|
||||
ByOptionsLister: inf,
|
||||
}
|
||||
s := &Store{
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
transformBuilder: tb,
|
||||
}
|
||||
var partitions []partition.Partition
|
||||
req := &types.APIRequest{
|
||||
@@ -238,7 +240,8 @@ func TestListByPartitions(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
cg.EXPECT().TableAdminClient(req, schema, "", &WarningBuffer{}).Return(ri, nil)
|
||||
// This tests that fields are being extracted from schema columns and the type specific fields map
|
||||
cf.EXPECT().CacheFor([][]string{{"some", "field"}, {"gvk", "specific", "fields"}}, &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(schema), attributes.Namespaced(schema)).Return(c, nil)
|
||||
cf.EXPECT().CacheFor([][]string{{"some", "field"}, {`id`}, {`metadata`, `state`, `name`}, {"gvk", "specific", "fields"}}, gomock.Any(), &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(schema), attributes.Namespaced(schema)).Return(c, nil)
|
||||
tb.EXPECT().GetTransformFunc(attributes.GVK(schema)).Return(func(obj interface{}) (interface{}, error) { return obj, nil })
|
||||
bloi.EXPECT().ListByOptions(req.Context(), opts, partitions, req.Namespace).Return(listToReturn, len(listToReturn.Items), "", nil)
|
||||
list, total, contToken, err := s.ListByPartitions(req, schema, partitions)
|
||||
assert.Nil(t, err)
|
||||
@@ -253,11 +256,13 @@ func TestListByPartitions(t *testing.T) {
|
||||
nsi := NewMockCache(gomock.NewController(t))
|
||||
cg := NewMockClientGetter(gomock.NewController(t))
|
||||
cf := NewMockCacheFactory(gomock.NewController(t))
|
||||
tb := NewMockTransformBuilder(gomock.NewController(t))
|
||||
|
||||
s := &Store{
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
transformBuilder: tb,
|
||||
}
|
||||
var partitions []partition.Partition
|
||||
req := &types.APIRequest{
|
||||
@@ -317,11 +322,13 @@ func TestListByPartitions(t *testing.T) {
|
||||
nsi := NewMockCache(gomock.NewController(t))
|
||||
cg := NewMockClientGetter(gomock.NewController(t))
|
||||
cf := NewMockCacheFactory(gomock.NewController(t))
|
||||
tb := NewMockTransformBuilder(gomock.NewController(t))
|
||||
|
||||
s := &Store{
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
transformBuilder: tb,
|
||||
}
|
||||
var partitions []partition.Partition
|
||||
req := &types.APIRequest{
|
||||
@@ -380,11 +387,13 @@ func TestListByPartitions(t *testing.T) {
|
||||
cg := NewMockClientGetter(gomock.NewController(t))
|
||||
cf := NewMockCacheFactory(gomock.NewController(t))
|
||||
ri := NewMockResourceInterface(gomock.NewController(t))
|
||||
tb := NewMockTransformBuilder(gomock.NewController(t))
|
||||
|
||||
s := &Store{
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
transformBuilder: tb,
|
||||
}
|
||||
var partitions []partition.Partition
|
||||
req := &types.APIRequest{
|
||||
@@ -432,7 +441,8 @@ func TestListByPartitions(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
cg.EXPECT().TableAdminClient(req, schema, "", &WarningBuffer{}).Return(ri, nil)
|
||||
// This tests that fields are being extracted from schema columns and the type specific fields map
|
||||
cf.EXPECT().CacheFor([][]string{{"some", "field"}, {"gvk", "specific", "fields"}}, &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(schema), attributes.Namespaced(schema)).Return(factory.Cache{}, fmt.Errorf("error"))
|
||||
tb.EXPECT().GetTransformFunc(attributes.GVK(schema)).Return(func(obj interface{}) (interface{}, error) { return obj, nil })
|
||||
cf.EXPECT().CacheFor([][]string{{"some", "field"}, {`id`}, {`metadata`, `state`, `name`}, {"gvk", "specific", "fields"}}, gomock.Any(), &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(schema), attributes.Namespaced(schema)).Return(factory.Cache{}, fmt.Errorf("error"))
|
||||
|
||||
_, _, _, err = s.ListByPartitions(req, schema, partitions)
|
||||
assert.NotNil(t, err)
|
||||
@@ -447,6 +457,7 @@ func TestListByPartitions(t *testing.T) {
|
||||
cf := NewMockCacheFactory(gomock.NewController(t))
|
||||
ri := NewMockResourceInterface(gomock.NewController(t))
|
||||
bloi := NewMockByOptionsLister(gomock.NewController(t))
|
||||
tb := NewMockTransformBuilder(gomock.NewController(t))
|
||||
inf := &informer.Informer{
|
||||
ByOptionsLister: bloi,
|
||||
}
|
||||
@@ -454,9 +465,10 @@ func TestListByPartitions(t *testing.T) {
|
||||
ByOptionsLister: inf,
|
||||
}
|
||||
s := &Store{
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
transformBuilder: tb,
|
||||
}
|
||||
var partitions []partition.Partition
|
||||
req := &types.APIRequest{
|
||||
@@ -504,8 +516,9 @@ func TestListByPartitions(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
cg.EXPECT().TableAdminClient(req, schema, "", &WarningBuffer{}).Return(ri, nil)
|
||||
// This tests that fields are being extracted from schema columns and the type specific fields map
|
||||
cf.EXPECT().CacheFor([][]string{{"some", "field"}, {"gvk", "specific", "fields"}}, &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(schema), attributes.Namespaced(schema)).Return(c, nil)
|
||||
cf.EXPECT().CacheFor([][]string{{"some", "field"}, {`id`}, {`metadata`, `state`, `name`}, {"gvk", "specific", "fields"}}, gomock.Any(), &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(schema), attributes.Namespaced(schema)).Return(c, nil)
|
||||
bloi.EXPECT().ListByOptions(req.Context(), opts, partitions, req.Namespace).Return(nil, 0, "", fmt.Errorf("error"))
|
||||
tb.EXPECT().GetTransformFunc(attributes.GVK(schema)).Return(func(obj interface{}) (interface{}, error) { return obj, nil })
|
||||
|
||||
_, _, _, err = s.ListByPartitions(req, schema, partitions)
|
||||
assert.NotNil(t, err)
|
||||
@@ -531,19 +544,22 @@ func TestReset(t *testing.T) {
|
||||
cf := NewMockCacheFactory(gomock.NewController(t))
|
||||
cs := NewMockSchemaColumnSetter(gomock.NewController(t))
|
||||
ri := NewMockResourceInterface(gomock.NewController(t))
|
||||
tb := NewMockTransformBuilder(gomock.NewController(t))
|
||||
nsc2 := factory.Cache{}
|
||||
s := &Store{
|
||||
namespaceCache: nsc,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
columnSetter: cs,
|
||||
cfInitializer: func() (CacheFactory, error) { return cf, nil },
|
||||
namespaceCache: nsc,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
columnSetter: cs,
|
||||
cfInitializer: func() (CacheFactory, error) { return cf, nil },
|
||||
transformBuilder: tb,
|
||||
}
|
||||
nsSchema := baseNSSchema
|
||||
cf.EXPECT().Reset().Return(nil)
|
||||
cs.EXPECT().SetColumns(gomock.Any(), gomock.Any()).Return(nil)
|
||||
cg.EXPECT().TableAdminClient(nil, &nsSchema, "", &WarningBuffer{}).Return(ri, nil)
|
||||
cf.EXPECT().CacheFor([][]string{{"metadata", "labels[field.cattle.io/projectId]"}}, &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(&nsSchema), false).Return(nsc2, nil)
|
||||
cf.EXPECT().CacheFor([][]string{{`id`}, {`metadata`, `state`, `name`}, {"metadata", "labels[field.cattle.io/projectId]"}}, gomock.Any(), &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(&nsSchema), false).Return(nsc2, nil)
|
||||
tb.EXPECT().GetTransformFunc(attributes.GVK(&nsSchema)).Return(func(obj interface{}) (interface{}, error) { return obj, nil })
|
||||
err := s.Reset()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, nsc2, s.namespaceCache)
|
||||
@@ -556,13 +572,15 @@ func TestReset(t *testing.T) {
|
||||
cg := NewMockClientGetter(gomock.NewController(t))
|
||||
cf := NewMockCacheFactory(gomock.NewController(t))
|
||||
cs := NewMockSchemaColumnSetter(gomock.NewController(t))
|
||||
tb := NewMockTransformBuilder(gomock.NewController(t))
|
||||
|
||||
s := &Store{
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
columnSetter: cs,
|
||||
cfInitializer: func() (CacheFactory, error) { return cf, nil },
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
columnSetter: cs,
|
||||
cfInitializer: func() (CacheFactory, error) { return cf, nil },
|
||||
transformBuilder: tb,
|
||||
}
|
||||
|
||||
cf.EXPECT().Reset().Return(fmt.Errorf("error"))
|
||||
@@ -577,13 +595,15 @@ func TestReset(t *testing.T) {
|
||||
cg := NewMockClientGetter(gomock.NewController(t))
|
||||
cf := NewMockCacheFactory(gomock.NewController(t))
|
||||
cs := NewMockSchemaColumnSetter(gomock.NewController(t))
|
||||
tb := NewMockTransformBuilder(gomock.NewController(t))
|
||||
|
||||
s := &Store{
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
columnSetter: cs,
|
||||
cfInitializer: func() (CacheFactory, error) { return cf, nil },
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
columnSetter: cs,
|
||||
cfInitializer: func() (CacheFactory, error) { return cf, nil },
|
||||
transformBuilder: tb,
|
||||
}
|
||||
|
||||
cf.EXPECT().Reset().Return(nil)
|
||||
@@ -599,13 +619,15 @@ func TestReset(t *testing.T) {
|
||||
cg := NewMockClientGetter(gomock.NewController(t))
|
||||
cf := NewMockCacheFactory(gomock.NewController(t))
|
||||
cs := NewMockSchemaColumnSetter(gomock.NewController(t))
|
||||
tb := NewMockTransformBuilder(gomock.NewController(t))
|
||||
|
||||
s := &Store{
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
columnSetter: cs,
|
||||
cfInitializer: func() (CacheFactory, error) { return cf, nil },
|
||||
namespaceCache: nsi,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
columnSetter: cs,
|
||||
cfInitializer: func() (CacheFactory, error) { return cf, nil },
|
||||
transformBuilder: tb,
|
||||
}
|
||||
nsSchema := baseNSSchema
|
||||
|
||||
@@ -624,20 +646,23 @@ func TestReset(t *testing.T) {
|
||||
cf := NewMockCacheFactory(gomock.NewController(t))
|
||||
cs := NewMockSchemaColumnSetter(gomock.NewController(t))
|
||||
ri := NewMockResourceInterface(gomock.NewController(t))
|
||||
tb := NewMockTransformBuilder(gomock.NewController(t))
|
||||
|
||||
s := &Store{
|
||||
namespaceCache: nsc,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
columnSetter: cs,
|
||||
cfInitializer: func() (CacheFactory, error) { return cf, nil },
|
||||
namespaceCache: nsc,
|
||||
clientGetter: cg,
|
||||
cacheFactory: cf,
|
||||
columnSetter: cs,
|
||||
cfInitializer: func() (CacheFactory, error) { return cf, nil },
|
||||
transformBuilder: tb,
|
||||
}
|
||||
nsSchema := baseNSSchema
|
||||
|
||||
cf.EXPECT().Reset().Return(nil)
|
||||
cs.EXPECT().SetColumns(gomock.Any(), gomock.Any()).Return(nil)
|
||||
cg.EXPECT().TableAdminClient(nil, &nsSchema, "", &WarningBuffer{}).Return(ri, nil)
|
||||
cf.EXPECT().CacheFor([][]string{{"metadata", "labels[field.cattle.io/projectId]"}}, &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(&nsSchema), false).Return(factory.Cache{}, fmt.Errorf("error"))
|
||||
cf.EXPECT().CacheFor([][]string{{`id`}, {`metadata`, `state`, `name`}, {"metadata", "labels[field.cattle.io/projectId]"}}, gomock.Any(), &tablelistconvert.Client{ResourceInterface: ri}, attributes.GVK(&nsSchema), false).Return(factory.Cache{}, fmt.Errorf("error"))
|
||||
tb.EXPECT().GetTransformFunc(attributes.GVK(&nsSchema)).Return(func(obj interface{}) (interface{}, error) { return obj, nil })
|
||||
err := s.Reset()
|
||||
assert.NotNil(t, err)
|
||||
},
|
||||
|
Reference in New Issue
Block a user