diff --git a/pkg/fakes/cluster.go b/pkg/fakes/cluster.go new file mode 100644 index 000000000..8d0aeee41 --- /dev/null +++ b/pkg/fakes/cluster.go @@ -0,0 +1,524 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3 (interfaces: ClusterController,ClusterClient,ClusterCache) + +// Package fakes is a generated GoMock package. +package fakes + +import ( + context "context" + reflect "reflect" + time "time" + + gomock "github.com/golang/mock/gomock" + v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" + v30 "github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3" + generic "github.com/rancher/wrangler/pkg/generic" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// MockClusterController is a mock of ClusterController interface. +type MockClusterController struct { + ctrl *gomock.Controller + recorder *MockClusterControllerMockRecorder +} + +// MockClusterControllerMockRecorder is the mock recorder for MockClusterController. +type MockClusterControllerMockRecorder struct { + mock *MockClusterController +} + +// NewMockClusterController creates a new mock instance. +func NewMockClusterController(ctrl *gomock.Controller) *MockClusterController { + mock := &MockClusterController{ctrl: ctrl} + mock.recorder = &MockClusterControllerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockClusterController) EXPECT() *MockClusterControllerMockRecorder { + return m.recorder +} + +// AddGenericHandler mocks base method. +func (m *MockClusterController) AddGenericHandler(arg0 context.Context, arg1 string, arg2 generic.Handler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddGenericHandler", arg0, arg1, arg2) +} + +// AddGenericHandler indicates an expected call of AddGenericHandler. +func (mr *MockClusterControllerMockRecorder) AddGenericHandler(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddGenericHandler", reflect.TypeOf((*MockClusterController)(nil).AddGenericHandler), arg0, arg1, arg2) +} + +// AddGenericRemoveHandler mocks base method. +func (m *MockClusterController) AddGenericRemoveHandler(arg0 context.Context, arg1 string, arg2 generic.Handler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddGenericRemoveHandler", arg0, arg1, arg2) +} + +// AddGenericRemoveHandler indicates an expected call of AddGenericRemoveHandler. +func (mr *MockClusterControllerMockRecorder) AddGenericRemoveHandler(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddGenericRemoveHandler", reflect.TypeOf((*MockClusterController)(nil).AddGenericRemoveHandler), arg0, arg1, arg2) +} + +// Cache mocks base method. +func (m *MockClusterController) Cache() v30.ClusterCache { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Cache") + ret0, _ := ret[0].(v30.ClusterCache) + return ret0 +} + +// Cache indicates an expected call of Cache. +func (mr *MockClusterControllerMockRecorder) Cache() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Cache", reflect.TypeOf((*MockClusterController)(nil).Cache)) +} + +// Create mocks base method. +func (m *MockClusterController) Create(arg0 *v3.Cluster) (*v3.Cluster, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0) + ret0, _ := ret[0].(*v3.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create. +func (mr *MockClusterControllerMockRecorder) Create(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockClusterController)(nil).Create), arg0) +} + +// Delete mocks base method. +func (m *MockClusterController) Delete(arg0 string, arg1 *v1.DeleteOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockClusterControllerMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockClusterController)(nil).Delete), arg0, arg1) +} + +// Enqueue mocks base method. +func (m *MockClusterController) Enqueue(arg0 string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Enqueue", arg0) +} + +// Enqueue indicates an expected call of Enqueue. +func (mr *MockClusterControllerMockRecorder) Enqueue(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Enqueue", reflect.TypeOf((*MockClusterController)(nil).Enqueue), arg0) +} + +// EnqueueAfter mocks base method. +func (m *MockClusterController) EnqueueAfter(arg0 string, arg1 time.Duration) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "EnqueueAfter", arg0, arg1) +} + +// EnqueueAfter indicates an expected call of EnqueueAfter. +func (mr *MockClusterControllerMockRecorder) EnqueueAfter(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnqueueAfter", reflect.TypeOf((*MockClusterController)(nil).EnqueueAfter), arg0, arg1) +} + +// Get mocks base method. +func (m *MockClusterController) Get(arg0 string, arg1 v1.GetOptions) (*v3.Cluster, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1) + ret0, _ := ret[0].(*v3.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockClusterControllerMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockClusterController)(nil).Get), arg0, arg1) +} + +// GroupVersionKind mocks base method. +func (m *MockClusterController) GroupVersionKind() schema.GroupVersionKind { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GroupVersionKind") + ret0, _ := ret[0].(schema.GroupVersionKind) + return ret0 +} + +// GroupVersionKind indicates an expected call of GroupVersionKind. +func (mr *MockClusterControllerMockRecorder) GroupVersionKind() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GroupVersionKind", reflect.TypeOf((*MockClusterController)(nil).GroupVersionKind)) +} + +// Informer mocks base method. +func (m *MockClusterController) Informer() cache.SharedIndexInformer { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Informer") + ret0, _ := ret[0].(cache.SharedIndexInformer) + return ret0 +} + +// Informer indicates an expected call of Informer. +func (mr *MockClusterControllerMockRecorder) Informer() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Informer", reflect.TypeOf((*MockClusterController)(nil).Informer)) +} + +// List mocks base method. +func (m *MockClusterController) List(arg0 v1.ListOptions) (*v3.ClusterList, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0) + ret0, _ := ret[0].(*v3.ClusterList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockClusterControllerMockRecorder) List(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockClusterController)(nil).List), arg0) +} + +// OnChange mocks base method. +func (m *MockClusterController) OnChange(arg0 context.Context, arg1 string, arg2 v30.ClusterHandler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "OnChange", arg0, arg1, arg2) +} + +// OnChange indicates an expected call of OnChange. +func (mr *MockClusterControllerMockRecorder) OnChange(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnChange", reflect.TypeOf((*MockClusterController)(nil).OnChange), arg0, arg1, arg2) +} + +// OnRemove mocks base method. +func (m *MockClusterController) OnRemove(arg0 context.Context, arg1 string, arg2 v30.ClusterHandler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "OnRemove", arg0, arg1, arg2) +} + +// OnRemove indicates an expected call of OnRemove. +func (mr *MockClusterControllerMockRecorder) OnRemove(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnRemove", reflect.TypeOf((*MockClusterController)(nil).OnRemove), arg0, arg1, arg2) +} + +// Patch mocks base method. +func (m *MockClusterController) Patch(arg0 string, arg1 types.PatchType, arg2 []byte, arg3 ...string) (*v3.Cluster, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1, arg2} + for _, a := range arg3 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Patch", varargs...) + ret0, _ := ret[0].(*v3.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Patch indicates an expected call of Patch. +func (mr *MockClusterControllerMockRecorder) Patch(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Patch", reflect.TypeOf((*MockClusterController)(nil).Patch), varargs...) +} + +// Update mocks base method. +func (m *MockClusterController) Update(arg0 *v3.Cluster) (*v3.Cluster, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", arg0) + ret0, _ := ret[0].(*v3.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Update indicates an expected call of Update. +func (mr *MockClusterControllerMockRecorder) Update(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockClusterController)(nil).Update), arg0) +} + +// UpdateStatus mocks base method. +func (m *MockClusterController) UpdateStatus(arg0 *v3.Cluster) (*v3.Cluster, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateStatus", arg0) + ret0, _ := ret[0].(*v3.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateStatus indicates an expected call of UpdateStatus. +func (mr *MockClusterControllerMockRecorder) UpdateStatus(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateStatus", reflect.TypeOf((*MockClusterController)(nil).UpdateStatus), arg0) +} + +// Updater mocks base method. +func (m *MockClusterController) Updater() generic.Updater { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Updater") + ret0, _ := ret[0].(generic.Updater) + return ret0 +} + +// Updater indicates an expected call of Updater. +func (mr *MockClusterControllerMockRecorder) Updater() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Updater", reflect.TypeOf((*MockClusterController)(nil).Updater)) +} + +// Watch mocks base method. +func (m *MockClusterController) Watch(arg0 v1.ListOptions) (watch.Interface, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Watch", arg0) + ret0, _ := ret[0].(watch.Interface) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Watch indicates an expected call of Watch. +func (mr *MockClusterControllerMockRecorder) Watch(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Watch", reflect.TypeOf((*MockClusterController)(nil).Watch), arg0) +} + +// MockClusterClient is a mock of ClusterClient interface. +type MockClusterClient struct { + ctrl *gomock.Controller + recorder *MockClusterClientMockRecorder +} + +// MockClusterClientMockRecorder is the mock recorder for MockClusterClient. +type MockClusterClientMockRecorder struct { + mock *MockClusterClient +} + +// NewMockClusterClient creates a new mock instance. +func NewMockClusterClient(ctrl *gomock.Controller) *MockClusterClient { + mock := &MockClusterClient{ctrl: ctrl} + mock.recorder = &MockClusterClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockClusterClient) EXPECT() *MockClusterClientMockRecorder { + return m.recorder +} + +// Create mocks base method. +func (m *MockClusterClient) Create(arg0 *v3.Cluster) (*v3.Cluster, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0) + ret0, _ := ret[0].(*v3.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create. +func (mr *MockClusterClientMockRecorder) Create(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockClusterClient)(nil).Create), arg0) +} + +// Delete mocks base method. +func (m *MockClusterClient) Delete(arg0 string, arg1 *v1.DeleteOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockClusterClientMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockClusterClient)(nil).Delete), arg0, arg1) +} + +// Get mocks base method. +func (m *MockClusterClient) Get(arg0 string, arg1 v1.GetOptions) (*v3.Cluster, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1) + ret0, _ := ret[0].(*v3.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockClusterClientMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockClusterClient)(nil).Get), arg0, arg1) +} + +// List mocks base method. +func (m *MockClusterClient) List(arg0 v1.ListOptions) (*v3.ClusterList, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0) + ret0, _ := ret[0].(*v3.ClusterList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockClusterClientMockRecorder) List(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockClusterClient)(nil).List), arg0) +} + +// Patch mocks base method. +func (m *MockClusterClient) Patch(arg0 string, arg1 types.PatchType, arg2 []byte, arg3 ...string) (*v3.Cluster, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1, arg2} + for _, a := range arg3 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Patch", varargs...) + ret0, _ := ret[0].(*v3.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Patch indicates an expected call of Patch. +func (mr *MockClusterClientMockRecorder) Patch(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Patch", reflect.TypeOf((*MockClusterClient)(nil).Patch), varargs...) +} + +// Update mocks base method. +func (m *MockClusterClient) Update(arg0 *v3.Cluster) (*v3.Cluster, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", arg0) + ret0, _ := ret[0].(*v3.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Update indicates an expected call of Update. +func (mr *MockClusterClientMockRecorder) Update(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockClusterClient)(nil).Update), arg0) +} + +// UpdateStatus mocks base method. +func (m *MockClusterClient) UpdateStatus(arg0 *v3.Cluster) (*v3.Cluster, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateStatus", arg0) + ret0, _ := ret[0].(*v3.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateStatus indicates an expected call of UpdateStatus. +func (mr *MockClusterClientMockRecorder) UpdateStatus(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateStatus", reflect.TypeOf((*MockClusterClient)(nil).UpdateStatus), arg0) +} + +// Watch mocks base method. +func (m *MockClusterClient) Watch(arg0 v1.ListOptions) (watch.Interface, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Watch", arg0) + ret0, _ := ret[0].(watch.Interface) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Watch indicates an expected call of Watch. +func (mr *MockClusterClientMockRecorder) Watch(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Watch", reflect.TypeOf((*MockClusterClient)(nil).Watch), arg0) +} + +// MockClusterCache is a mock of ClusterCache interface. +type MockClusterCache struct { + ctrl *gomock.Controller + recorder *MockClusterCacheMockRecorder +} + +// MockClusterCacheMockRecorder is the mock recorder for MockClusterCache. +type MockClusterCacheMockRecorder struct { + mock *MockClusterCache +} + +// NewMockClusterCache creates a new mock instance. +func NewMockClusterCache(ctrl *gomock.Controller) *MockClusterCache { + mock := &MockClusterCache{ctrl: ctrl} + mock.recorder = &MockClusterCacheMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockClusterCache) EXPECT() *MockClusterCacheMockRecorder { + return m.recorder +} + +// AddIndexer mocks base method. +func (m *MockClusterCache) AddIndexer(arg0 string, arg1 v30.ClusterIndexer) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddIndexer", arg0, arg1) +} + +// AddIndexer indicates an expected call of AddIndexer. +func (mr *MockClusterCacheMockRecorder) AddIndexer(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddIndexer", reflect.TypeOf((*MockClusterCache)(nil).AddIndexer), arg0, arg1) +} + +// Get mocks base method. +func (m *MockClusterCache) Get(arg0 string) (*v3.Cluster, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0) + ret0, _ := ret[0].(*v3.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockClusterCacheMockRecorder) Get(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockClusterCache)(nil).Get), arg0) +} + +// GetByIndex mocks base method. +func (m *MockClusterCache) GetByIndex(arg0, arg1 string) ([]*v3.Cluster, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetByIndex", arg0, arg1) + ret0, _ := ret[0].([]*v3.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetByIndex indicates an expected call of GetByIndex. +func (mr *MockClusterCacheMockRecorder) GetByIndex(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByIndex", reflect.TypeOf((*MockClusterCache)(nil).GetByIndex), arg0, arg1) +} + +// List mocks base method. +func (m *MockClusterCache) List(arg0 labels.Selector) ([]*v3.Cluster, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0) + ret0, _ := ret[0].([]*v3.Cluster) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockClusterCacheMockRecorder) List(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockClusterCache)(nil).List), arg0) +} diff --git a/pkg/fakes/clusterroletemplatebinding.go b/pkg/fakes/clusterroletemplatebinding.go new file mode 100644 index 000000000..2b118d7a2 --- /dev/null +++ b/pkg/fakes/clusterroletemplatebinding.go @@ -0,0 +1,494 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3 (interfaces: ClusterRoleTemplateBindingController,ClusterRoleTemplateBindingClient,ClusterRoleTemplateBindingCache) + +// Package fakes is a generated GoMock package. +package fakes + +import ( + context "context" + reflect "reflect" + time "time" + + gomock "github.com/golang/mock/gomock" + v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" + v30 "github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3" + generic "github.com/rancher/wrangler/pkg/generic" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// MockClusterRoleTemplateBindingController is a mock of ClusterRoleTemplateBindingController interface. +type MockClusterRoleTemplateBindingController struct { + ctrl *gomock.Controller + recorder *MockClusterRoleTemplateBindingControllerMockRecorder +} + +// MockClusterRoleTemplateBindingControllerMockRecorder is the mock recorder for MockClusterRoleTemplateBindingController. +type MockClusterRoleTemplateBindingControllerMockRecorder struct { + mock *MockClusterRoleTemplateBindingController +} + +// NewMockClusterRoleTemplateBindingController creates a new mock instance. +func NewMockClusterRoleTemplateBindingController(ctrl *gomock.Controller) *MockClusterRoleTemplateBindingController { + mock := &MockClusterRoleTemplateBindingController{ctrl: ctrl} + mock.recorder = &MockClusterRoleTemplateBindingControllerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockClusterRoleTemplateBindingController) EXPECT() *MockClusterRoleTemplateBindingControllerMockRecorder { + return m.recorder +} + +// AddGenericHandler mocks base method. +func (m *MockClusterRoleTemplateBindingController) AddGenericHandler(arg0 context.Context, arg1 string, arg2 generic.Handler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddGenericHandler", arg0, arg1, arg2) +} + +// AddGenericHandler indicates an expected call of AddGenericHandler. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) AddGenericHandler(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddGenericHandler", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).AddGenericHandler), arg0, arg1, arg2) +} + +// AddGenericRemoveHandler mocks base method. +func (m *MockClusterRoleTemplateBindingController) AddGenericRemoveHandler(arg0 context.Context, arg1 string, arg2 generic.Handler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddGenericRemoveHandler", arg0, arg1, arg2) +} + +// AddGenericRemoveHandler indicates an expected call of AddGenericRemoveHandler. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) AddGenericRemoveHandler(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddGenericRemoveHandler", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).AddGenericRemoveHandler), arg0, arg1, arg2) +} + +// Cache mocks base method. +func (m *MockClusterRoleTemplateBindingController) Cache() v30.ClusterRoleTemplateBindingCache { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Cache") + ret0, _ := ret[0].(v30.ClusterRoleTemplateBindingCache) + return ret0 +} + +// Cache indicates an expected call of Cache. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) Cache() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Cache", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).Cache)) +} + +// Create mocks base method. +func (m *MockClusterRoleTemplateBindingController) Create(arg0 *v3.ClusterRoleTemplateBinding) (*v3.ClusterRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0) + ret0, _ := ret[0].(*v3.ClusterRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) Create(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).Create), arg0) +} + +// Delete mocks base method. +func (m *MockClusterRoleTemplateBindingController) Delete(arg0, arg1 string, arg2 *v1.DeleteOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).Delete), arg0, arg1, arg2) +} + +// Enqueue mocks base method. +func (m *MockClusterRoleTemplateBindingController) Enqueue(arg0, arg1 string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Enqueue", arg0, arg1) +} + +// Enqueue indicates an expected call of Enqueue. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) Enqueue(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Enqueue", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).Enqueue), arg0, arg1) +} + +// EnqueueAfter mocks base method. +func (m *MockClusterRoleTemplateBindingController) EnqueueAfter(arg0, arg1 string, arg2 time.Duration) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "EnqueueAfter", arg0, arg1, arg2) +} + +// EnqueueAfter indicates an expected call of EnqueueAfter. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) EnqueueAfter(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnqueueAfter", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).EnqueueAfter), arg0, arg1, arg2) +} + +// Get mocks base method. +func (m *MockClusterRoleTemplateBindingController) Get(arg0, arg1 string, arg2 v1.GetOptions) (*v3.ClusterRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2) + ret0, _ := ret[0].(*v3.ClusterRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) Get(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).Get), arg0, arg1, arg2) +} + +// GroupVersionKind mocks base method. +func (m *MockClusterRoleTemplateBindingController) GroupVersionKind() schema.GroupVersionKind { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GroupVersionKind") + ret0, _ := ret[0].(schema.GroupVersionKind) + return ret0 +} + +// GroupVersionKind indicates an expected call of GroupVersionKind. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) GroupVersionKind() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GroupVersionKind", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).GroupVersionKind)) +} + +// Informer mocks base method. +func (m *MockClusterRoleTemplateBindingController) Informer() cache.SharedIndexInformer { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Informer") + ret0, _ := ret[0].(cache.SharedIndexInformer) + return ret0 +} + +// Informer indicates an expected call of Informer. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) Informer() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Informer", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).Informer)) +} + +// List mocks base method. +func (m *MockClusterRoleTemplateBindingController) List(arg0 string, arg1 v1.ListOptions) (*v3.ClusterRoleTemplateBindingList, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0, arg1) + ret0, _ := ret[0].(*v3.ClusterRoleTemplateBindingList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) List(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).List), arg0, arg1) +} + +// OnChange mocks base method. +func (m *MockClusterRoleTemplateBindingController) OnChange(arg0 context.Context, arg1 string, arg2 v30.ClusterRoleTemplateBindingHandler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "OnChange", arg0, arg1, arg2) +} + +// OnChange indicates an expected call of OnChange. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) OnChange(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnChange", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).OnChange), arg0, arg1, arg2) +} + +// OnRemove mocks base method. +func (m *MockClusterRoleTemplateBindingController) OnRemove(arg0 context.Context, arg1 string, arg2 v30.ClusterRoleTemplateBindingHandler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "OnRemove", arg0, arg1, arg2) +} + +// OnRemove indicates an expected call of OnRemove. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) OnRemove(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnRemove", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).OnRemove), arg0, arg1, arg2) +} + +// Patch mocks base method. +func (m *MockClusterRoleTemplateBindingController) Patch(arg0, arg1 string, arg2 types.PatchType, arg3 []byte, arg4 ...string) (*v3.ClusterRoleTemplateBinding, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1, arg2, arg3} + for _, a := range arg4 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Patch", varargs...) + ret0, _ := ret[0].(*v3.ClusterRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Patch indicates an expected call of Patch. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) Patch(arg0, arg1, arg2, arg3 interface{}, arg4 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1, arg2, arg3}, arg4...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Patch", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).Patch), varargs...) +} + +// Update mocks base method. +func (m *MockClusterRoleTemplateBindingController) Update(arg0 *v3.ClusterRoleTemplateBinding) (*v3.ClusterRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", arg0) + ret0, _ := ret[0].(*v3.ClusterRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Update indicates an expected call of Update. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) Update(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).Update), arg0) +} + +// Updater mocks base method. +func (m *MockClusterRoleTemplateBindingController) Updater() generic.Updater { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Updater") + ret0, _ := ret[0].(generic.Updater) + return ret0 +} + +// Updater indicates an expected call of Updater. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) Updater() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Updater", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).Updater)) +} + +// Watch mocks base method. +func (m *MockClusterRoleTemplateBindingController) Watch(arg0 string, arg1 v1.ListOptions) (watch.Interface, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Watch", arg0, arg1) + ret0, _ := ret[0].(watch.Interface) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Watch indicates an expected call of Watch. +func (mr *MockClusterRoleTemplateBindingControllerMockRecorder) Watch(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Watch", reflect.TypeOf((*MockClusterRoleTemplateBindingController)(nil).Watch), arg0, arg1) +} + +// MockClusterRoleTemplateBindingClient is a mock of ClusterRoleTemplateBindingClient interface. +type MockClusterRoleTemplateBindingClient struct { + ctrl *gomock.Controller + recorder *MockClusterRoleTemplateBindingClientMockRecorder +} + +// MockClusterRoleTemplateBindingClientMockRecorder is the mock recorder for MockClusterRoleTemplateBindingClient. +type MockClusterRoleTemplateBindingClientMockRecorder struct { + mock *MockClusterRoleTemplateBindingClient +} + +// NewMockClusterRoleTemplateBindingClient creates a new mock instance. +func NewMockClusterRoleTemplateBindingClient(ctrl *gomock.Controller) *MockClusterRoleTemplateBindingClient { + mock := &MockClusterRoleTemplateBindingClient{ctrl: ctrl} + mock.recorder = &MockClusterRoleTemplateBindingClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockClusterRoleTemplateBindingClient) EXPECT() *MockClusterRoleTemplateBindingClientMockRecorder { + return m.recorder +} + +// Create mocks base method. +func (m *MockClusterRoleTemplateBindingClient) Create(arg0 *v3.ClusterRoleTemplateBinding) (*v3.ClusterRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0) + ret0, _ := ret[0].(*v3.ClusterRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create. +func (mr *MockClusterRoleTemplateBindingClientMockRecorder) Create(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockClusterRoleTemplateBindingClient)(nil).Create), arg0) +} + +// Delete mocks base method. +func (m *MockClusterRoleTemplateBindingClient) Delete(arg0, arg1 string, arg2 *v1.DeleteOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockClusterRoleTemplateBindingClientMockRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockClusterRoleTemplateBindingClient)(nil).Delete), arg0, arg1, arg2) +} + +// Get mocks base method. +func (m *MockClusterRoleTemplateBindingClient) Get(arg0, arg1 string, arg2 v1.GetOptions) (*v3.ClusterRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2) + ret0, _ := ret[0].(*v3.ClusterRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockClusterRoleTemplateBindingClientMockRecorder) Get(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockClusterRoleTemplateBindingClient)(nil).Get), arg0, arg1, arg2) +} + +// List mocks base method. +func (m *MockClusterRoleTemplateBindingClient) List(arg0 string, arg1 v1.ListOptions) (*v3.ClusterRoleTemplateBindingList, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0, arg1) + ret0, _ := ret[0].(*v3.ClusterRoleTemplateBindingList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockClusterRoleTemplateBindingClientMockRecorder) List(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockClusterRoleTemplateBindingClient)(nil).List), arg0, arg1) +} + +// Patch mocks base method. +func (m *MockClusterRoleTemplateBindingClient) Patch(arg0, arg1 string, arg2 types.PatchType, arg3 []byte, arg4 ...string) (*v3.ClusterRoleTemplateBinding, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1, arg2, arg3} + for _, a := range arg4 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Patch", varargs...) + ret0, _ := ret[0].(*v3.ClusterRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Patch indicates an expected call of Patch. +func (mr *MockClusterRoleTemplateBindingClientMockRecorder) Patch(arg0, arg1, arg2, arg3 interface{}, arg4 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1, arg2, arg3}, arg4...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Patch", reflect.TypeOf((*MockClusterRoleTemplateBindingClient)(nil).Patch), varargs...) +} + +// Update mocks base method. +func (m *MockClusterRoleTemplateBindingClient) Update(arg0 *v3.ClusterRoleTemplateBinding) (*v3.ClusterRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", arg0) + ret0, _ := ret[0].(*v3.ClusterRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Update indicates an expected call of Update. +func (mr *MockClusterRoleTemplateBindingClientMockRecorder) Update(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockClusterRoleTemplateBindingClient)(nil).Update), arg0) +} + +// Watch mocks base method. +func (m *MockClusterRoleTemplateBindingClient) Watch(arg0 string, arg1 v1.ListOptions) (watch.Interface, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Watch", arg0, arg1) + ret0, _ := ret[0].(watch.Interface) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Watch indicates an expected call of Watch. +func (mr *MockClusterRoleTemplateBindingClientMockRecorder) Watch(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Watch", reflect.TypeOf((*MockClusterRoleTemplateBindingClient)(nil).Watch), arg0, arg1) +} + +// MockClusterRoleTemplateBindingCache is a mock of ClusterRoleTemplateBindingCache interface. +type MockClusterRoleTemplateBindingCache struct { + ctrl *gomock.Controller + recorder *MockClusterRoleTemplateBindingCacheMockRecorder +} + +// MockClusterRoleTemplateBindingCacheMockRecorder is the mock recorder for MockClusterRoleTemplateBindingCache. +type MockClusterRoleTemplateBindingCacheMockRecorder struct { + mock *MockClusterRoleTemplateBindingCache +} + +// NewMockClusterRoleTemplateBindingCache creates a new mock instance. +func NewMockClusterRoleTemplateBindingCache(ctrl *gomock.Controller) *MockClusterRoleTemplateBindingCache { + mock := &MockClusterRoleTemplateBindingCache{ctrl: ctrl} + mock.recorder = &MockClusterRoleTemplateBindingCacheMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockClusterRoleTemplateBindingCache) EXPECT() *MockClusterRoleTemplateBindingCacheMockRecorder { + return m.recorder +} + +// AddIndexer mocks base method. +func (m *MockClusterRoleTemplateBindingCache) AddIndexer(arg0 string, arg1 v30.ClusterRoleTemplateBindingIndexer) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddIndexer", arg0, arg1) +} + +// AddIndexer indicates an expected call of AddIndexer. +func (mr *MockClusterRoleTemplateBindingCacheMockRecorder) AddIndexer(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddIndexer", reflect.TypeOf((*MockClusterRoleTemplateBindingCache)(nil).AddIndexer), arg0, arg1) +} + +// Get mocks base method. +func (m *MockClusterRoleTemplateBindingCache) Get(arg0, arg1 string) (*v3.ClusterRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1) + ret0, _ := ret[0].(*v3.ClusterRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockClusterRoleTemplateBindingCacheMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockClusterRoleTemplateBindingCache)(nil).Get), arg0, arg1) +} + +// GetByIndex mocks base method. +func (m *MockClusterRoleTemplateBindingCache) GetByIndex(arg0, arg1 string) ([]*v3.ClusterRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetByIndex", arg0, arg1) + ret0, _ := ret[0].([]*v3.ClusterRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetByIndex indicates an expected call of GetByIndex. +func (mr *MockClusterRoleTemplateBindingCacheMockRecorder) GetByIndex(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByIndex", reflect.TypeOf((*MockClusterRoleTemplateBindingCache)(nil).GetByIndex), arg0, arg1) +} + +// List mocks base method. +func (m *MockClusterRoleTemplateBindingCache) List(arg0 string, arg1 labels.Selector) ([]*v3.ClusterRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0, arg1) + ret0, _ := ret[0].([]*v3.ClusterRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockClusterRoleTemplateBindingCacheMockRecorder) List(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockClusterRoleTemplateBindingCache)(nil).List), arg0, arg1) +} diff --git a/pkg/fakes/globalrole.go b/pkg/fakes/globalrole.go new file mode 100644 index 000000000..e381a9b55 --- /dev/null +++ b/pkg/fakes/globalrole.go @@ -0,0 +1,494 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3 (interfaces: GlobalRoleController,GlobalRoleClient,GlobalRoleCache) + +// Package fakes is a generated GoMock package. +package fakes + +import ( + context "context" + reflect "reflect" + time "time" + + gomock "github.com/golang/mock/gomock" + v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" + v30 "github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3" + generic "github.com/rancher/wrangler/pkg/generic" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// MockGlobalRoleController is a mock of GlobalRoleController interface. +type MockGlobalRoleController struct { + ctrl *gomock.Controller + recorder *MockGlobalRoleControllerMockRecorder +} + +// MockGlobalRoleControllerMockRecorder is the mock recorder for MockGlobalRoleController. +type MockGlobalRoleControllerMockRecorder struct { + mock *MockGlobalRoleController +} + +// NewMockGlobalRoleController creates a new mock instance. +func NewMockGlobalRoleController(ctrl *gomock.Controller) *MockGlobalRoleController { + mock := &MockGlobalRoleController{ctrl: ctrl} + mock.recorder = &MockGlobalRoleControllerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGlobalRoleController) EXPECT() *MockGlobalRoleControllerMockRecorder { + return m.recorder +} + +// AddGenericHandler mocks base method. +func (m *MockGlobalRoleController) AddGenericHandler(arg0 context.Context, arg1 string, arg2 generic.Handler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddGenericHandler", arg0, arg1, arg2) +} + +// AddGenericHandler indicates an expected call of AddGenericHandler. +func (mr *MockGlobalRoleControllerMockRecorder) AddGenericHandler(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddGenericHandler", reflect.TypeOf((*MockGlobalRoleController)(nil).AddGenericHandler), arg0, arg1, arg2) +} + +// AddGenericRemoveHandler mocks base method. +func (m *MockGlobalRoleController) AddGenericRemoveHandler(arg0 context.Context, arg1 string, arg2 generic.Handler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddGenericRemoveHandler", arg0, arg1, arg2) +} + +// AddGenericRemoveHandler indicates an expected call of AddGenericRemoveHandler. +func (mr *MockGlobalRoleControllerMockRecorder) AddGenericRemoveHandler(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddGenericRemoveHandler", reflect.TypeOf((*MockGlobalRoleController)(nil).AddGenericRemoveHandler), arg0, arg1, arg2) +} + +// Cache mocks base method. +func (m *MockGlobalRoleController) Cache() v30.GlobalRoleCache { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Cache") + ret0, _ := ret[0].(v30.GlobalRoleCache) + return ret0 +} + +// Cache indicates an expected call of Cache. +func (mr *MockGlobalRoleControllerMockRecorder) Cache() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Cache", reflect.TypeOf((*MockGlobalRoleController)(nil).Cache)) +} + +// Create mocks base method. +func (m *MockGlobalRoleController) Create(arg0 *v3.GlobalRole) (*v3.GlobalRole, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0) + ret0, _ := ret[0].(*v3.GlobalRole) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create. +func (mr *MockGlobalRoleControllerMockRecorder) Create(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockGlobalRoleController)(nil).Create), arg0) +} + +// Delete mocks base method. +func (m *MockGlobalRoleController) Delete(arg0 string, arg1 *v1.DeleteOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockGlobalRoleControllerMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockGlobalRoleController)(nil).Delete), arg0, arg1) +} + +// Enqueue mocks base method. +func (m *MockGlobalRoleController) Enqueue(arg0 string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Enqueue", arg0) +} + +// Enqueue indicates an expected call of Enqueue. +func (mr *MockGlobalRoleControllerMockRecorder) Enqueue(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Enqueue", reflect.TypeOf((*MockGlobalRoleController)(nil).Enqueue), arg0) +} + +// EnqueueAfter mocks base method. +func (m *MockGlobalRoleController) EnqueueAfter(arg0 string, arg1 time.Duration) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "EnqueueAfter", arg0, arg1) +} + +// EnqueueAfter indicates an expected call of EnqueueAfter. +func (mr *MockGlobalRoleControllerMockRecorder) EnqueueAfter(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnqueueAfter", reflect.TypeOf((*MockGlobalRoleController)(nil).EnqueueAfter), arg0, arg1) +} + +// Get mocks base method. +func (m *MockGlobalRoleController) Get(arg0 string, arg1 v1.GetOptions) (*v3.GlobalRole, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1) + ret0, _ := ret[0].(*v3.GlobalRole) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockGlobalRoleControllerMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockGlobalRoleController)(nil).Get), arg0, arg1) +} + +// GroupVersionKind mocks base method. +func (m *MockGlobalRoleController) GroupVersionKind() schema.GroupVersionKind { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GroupVersionKind") + ret0, _ := ret[0].(schema.GroupVersionKind) + return ret0 +} + +// GroupVersionKind indicates an expected call of GroupVersionKind. +func (mr *MockGlobalRoleControllerMockRecorder) GroupVersionKind() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GroupVersionKind", reflect.TypeOf((*MockGlobalRoleController)(nil).GroupVersionKind)) +} + +// Informer mocks base method. +func (m *MockGlobalRoleController) Informer() cache.SharedIndexInformer { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Informer") + ret0, _ := ret[0].(cache.SharedIndexInformer) + return ret0 +} + +// Informer indicates an expected call of Informer. +func (mr *MockGlobalRoleControllerMockRecorder) Informer() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Informer", reflect.TypeOf((*MockGlobalRoleController)(nil).Informer)) +} + +// List mocks base method. +func (m *MockGlobalRoleController) List(arg0 v1.ListOptions) (*v3.GlobalRoleList, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0) + ret0, _ := ret[0].(*v3.GlobalRoleList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockGlobalRoleControllerMockRecorder) List(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockGlobalRoleController)(nil).List), arg0) +} + +// OnChange mocks base method. +func (m *MockGlobalRoleController) OnChange(arg0 context.Context, arg1 string, arg2 v30.GlobalRoleHandler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "OnChange", arg0, arg1, arg2) +} + +// OnChange indicates an expected call of OnChange. +func (mr *MockGlobalRoleControllerMockRecorder) OnChange(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnChange", reflect.TypeOf((*MockGlobalRoleController)(nil).OnChange), arg0, arg1, arg2) +} + +// OnRemove mocks base method. +func (m *MockGlobalRoleController) OnRemove(arg0 context.Context, arg1 string, arg2 v30.GlobalRoleHandler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "OnRemove", arg0, arg1, arg2) +} + +// OnRemove indicates an expected call of OnRemove. +func (mr *MockGlobalRoleControllerMockRecorder) OnRemove(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnRemove", reflect.TypeOf((*MockGlobalRoleController)(nil).OnRemove), arg0, arg1, arg2) +} + +// Patch mocks base method. +func (m *MockGlobalRoleController) Patch(arg0 string, arg1 types.PatchType, arg2 []byte, arg3 ...string) (*v3.GlobalRole, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1, arg2} + for _, a := range arg3 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Patch", varargs...) + ret0, _ := ret[0].(*v3.GlobalRole) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Patch indicates an expected call of Patch. +func (mr *MockGlobalRoleControllerMockRecorder) Patch(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Patch", reflect.TypeOf((*MockGlobalRoleController)(nil).Patch), varargs...) +} + +// Update mocks base method. +func (m *MockGlobalRoleController) Update(arg0 *v3.GlobalRole) (*v3.GlobalRole, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", arg0) + ret0, _ := ret[0].(*v3.GlobalRole) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Update indicates an expected call of Update. +func (mr *MockGlobalRoleControllerMockRecorder) Update(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockGlobalRoleController)(nil).Update), arg0) +} + +// Updater mocks base method. +func (m *MockGlobalRoleController) Updater() generic.Updater { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Updater") + ret0, _ := ret[0].(generic.Updater) + return ret0 +} + +// Updater indicates an expected call of Updater. +func (mr *MockGlobalRoleControllerMockRecorder) Updater() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Updater", reflect.TypeOf((*MockGlobalRoleController)(nil).Updater)) +} + +// Watch mocks base method. +func (m *MockGlobalRoleController) Watch(arg0 v1.ListOptions) (watch.Interface, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Watch", arg0) + ret0, _ := ret[0].(watch.Interface) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Watch indicates an expected call of Watch. +func (mr *MockGlobalRoleControllerMockRecorder) Watch(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Watch", reflect.TypeOf((*MockGlobalRoleController)(nil).Watch), arg0) +} + +// MockGlobalRoleClient is a mock of GlobalRoleClient interface. +type MockGlobalRoleClient struct { + ctrl *gomock.Controller + recorder *MockGlobalRoleClientMockRecorder +} + +// MockGlobalRoleClientMockRecorder is the mock recorder for MockGlobalRoleClient. +type MockGlobalRoleClientMockRecorder struct { + mock *MockGlobalRoleClient +} + +// NewMockGlobalRoleClient creates a new mock instance. +func NewMockGlobalRoleClient(ctrl *gomock.Controller) *MockGlobalRoleClient { + mock := &MockGlobalRoleClient{ctrl: ctrl} + mock.recorder = &MockGlobalRoleClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGlobalRoleClient) EXPECT() *MockGlobalRoleClientMockRecorder { + return m.recorder +} + +// Create mocks base method. +func (m *MockGlobalRoleClient) Create(arg0 *v3.GlobalRole) (*v3.GlobalRole, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0) + ret0, _ := ret[0].(*v3.GlobalRole) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create. +func (mr *MockGlobalRoleClientMockRecorder) Create(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockGlobalRoleClient)(nil).Create), arg0) +} + +// Delete mocks base method. +func (m *MockGlobalRoleClient) Delete(arg0 string, arg1 *v1.DeleteOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockGlobalRoleClientMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockGlobalRoleClient)(nil).Delete), arg0, arg1) +} + +// Get mocks base method. +func (m *MockGlobalRoleClient) Get(arg0 string, arg1 v1.GetOptions) (*v3.GlobalRole, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1) + ret0, _ := ret[0].(*v3.GlobalRole) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockGlobalRoleClientMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockGlobalRoleClient)(nil).Get), arg0, arg1) +} + +// List mocks base method. +func (m *MockGlobalRoleClient) List(arg0 v1.ListOptions) (*v3.GlobalRoleList, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0) + ret0, _ := ret[0].(*v3.GlobalRoleList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockGlobalRoleClientMockRecorder) List(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockGlobalRoleClient)(nil).List), arg0) +} + +// Patch mocks base method. +func (m *MockGlobalRoleClient) Patch(arg0 string, arg1 types.PatchType, arg2 []byte, arg3 ...string) (*v3.GlobalRole, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1, arg2} + for _, a := range arg3 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Patch", varargs...) + ret0, _ := ret[0].(*v3.GlobalRole) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Patch indicates an expected call of Patch. +func (mr *MockGlobalRoleClientMockRecorder) Patch(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Patch", reflect.TypeOf((*MockGlobalRoleClient)(nil).Patch), varargs...) +} + +// Update mocks base method. +func (m *MockGlobalRoleClient) Update(arg0 *v3.GlobalRole) (*v3.GlobalRole, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", arg0) + ret0, _ := ret[0].(*v3.GlobalRole) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Update indicates an expected call of Update. +func (mr *MockGlobalRoleClientMockRecorder) Update(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockGlobalRoleClient)(nil).Update), arg0) +} + +// Watch mocks base method. +func (m *MockGlobalRoleClient) Watch(arg0 v1.ListOptions) (watch.Interface, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Watch", arg0) + ret0, _ := ret[0].(watch.Interface) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Watch indicates an expected call of Watch. +func (mr *MockGlobalRoleClientMockRecorder) Watch(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Watch", reflect.TypeOf((*MockGlobalRoleClient)(nil).Watch), arg0) +} + +// MockGlobalRoleCache is a mock of GlobalRoleCache interface. +type MockGlobalRoleCache struct { + ctrl *gomock.Controller + recorder *MockGlobalRoleCacheMockRecorder +} + +// MockGlobalRoleCacheMockRecorder is the mock recorder for MockGlobalRoleCache. +type MockGlobalRoleCacheMockRecorder struct { + mock *MockGlobalRoleCache +} + +// NewMockGlobalRoleCache creates a new mock instance. +func NewMockGlobalRoleCache(ctrl *gomock.Controller) *MockGlobalRoleCache { + mock := &MockGlobalRoleCache{ctrl: ctrl} + mock.recorder = &MockGlobalRoleCacheMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGlobalRoleCache) EXPECT() *MockGlobalRoleCacheMockRecorder { + return m.recorder +} + +// AddIndexer mocks base method. +func (m *MockGlobalRoleCache) AddIndexer(arg0 string, arg1 v30.GlobalRoleIndexer) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddIndexer", arg0, arg1) +} + +// AddIndexer indicates an expected call of AddIndexer. +func (mr *MockGlobalRoleCacheMockRecorder) AddIndexer(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddIndexer", reflect.TypeOf((*MockGlobalRoleCache)(nil).AddIndexer), arg0, arg1) +} + +// Get mocks base method. +func (m *MockGlobalRoleCache) Get(arg0 string) (*v3.GlobalRole, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0) + ret0, _ := ret[0].(*v3.GlobalRole) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockGlobalRoleCacheMockRecorder) Get(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockGlobalRoleCache)(nil).Get), arg0) +} + +// GetByIndex mocks base method. +func (m *MockGlobalRoleCache) GetByIndex(arg0, arg1 string) ([]*v3.GlobalRole, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetByIndex", arg0, arg1) + ret0, _ := ret[0].([]*v3.GlobalRole) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetByIndex indicates an expected call of GetByIndex. +func (mr *MockGlobalRoleCacheMockRecorder) GetByIndex(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByIndex", reflect.TypeOf((*MockGlobalRoleCache)(nil).GetByIndex), arg0, arg1) +} + +// List mocks base method. +func (m *MockGlobalRoleCache) List(arg0 labels.Selector) ([]*v3.GlobalRole, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0) + ret0, _ := ret[0].([]*v3.GlobalRole) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockGlobalRoleCacheMockRecorder) List(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockGlobalRoleCache)(nil).List), arg0) +} diff --git a/pkg/fakes/k8Validation.go b/pkg/fakes/k8Validation.go new file mode 100644 index 000000000..049ae14c8 --- /dev/null +++ b/pkg/fakes/k8Validation.go @@ -0,0 +1,79 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: k8s.io/kubernetes/pkg/registry/rbac/validation (interfaces: AuthorizationRuleResolver) + +// Package fakes is a generated GoMock package. +package fakes + +import ( + fmt "fmt" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + v1 "k8s.io/api/rbac/v1" + user "k8s.io/apiserver/pkg/authentication/user" +) + +// MockAuthorizationRuleResolver is a mock of AuthorizationRuleResolver interface. +type MockAuthorizationRuleResolver struct { + ctrl *gomock.Controller + recorder *MockAuthorizationRuleResolverMockRecorder +} + +// MockAuthorizationRuleResolverMockRecorder is the mock recorder for MockAuthorizationRuleResolver. +type MockAuthorizationRuleResolverMockRecorder struct { + mock *MockAuthorizationRuleResolver +} + +// NewMockAuthorizationRuleResolver creates a new mock instance. +func NewMockAuthorizationRuleResolver(ctrl *gomock.Controller) *MockAuthorizationRuleResolver { + mock := &MockAuthorizationRuleResolver{ctrl: ctrl} + mock.recorder = &MockAuthorizationRuleResolverMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAuthorizationRuleResolver) EXPECT() *MockAuthorizationRuleResolverMockRecorder { + return m.recorder +} + +// GetRoleReferenceRules mocks base method. +func (m *MockAuthorizationRuleResolver) GetRoleReferenceRules(arg0 v1.RoleRef, arg1 string) ([]v1.PolicyRule, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRoleReferenceRules", arg0, arg1) + ret0, _ := ret[0].([]v1.PolicyRule) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetRoleReferenceRules indicates an expected call of GetRoleReferenceRules. +func (mr *MockAuthorizationRuleResolverMockRecorder) GetRoleReferenceRules(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRoleReferenceRules", reflect.TypeOf((*MockAuthorizationRuleResolver)(nil).GetRoleReferenceRules), arg0, arg1) +} + +// RulesFor mocks base method. +func (m *MockAuthorizationRuleResolver) RulesFor(arg0 user.Info, arg1 string) ([]v1.PolicyRule, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RulesFor", arg0, arg1) + ret0, _ := ret[0].([]v1.PolicyRule) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// RulesFor indicates an expected call of RulesFor. +func (mr *MockAuthorizationRuleResolverMockRecorder) RulesFor(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RulesFor", reflect.TypeOf((*MockAuthorizationRuleResolver)(nil).RulesFor), arg0, arg1) +} + +// VisitRulesFor mocks base method. +func (m *MockAuthorizationRuleResolver) VisitRulesFor(arg0 user.Info, arg1 string, arg2 func(fmt.Stringer, *v1.PolicyRule, error) bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "VisitRulesFor", arg0, arg1, arg2) +} + +// VisitRulesFor indicates an expected call of VisitRulesFor. +func (mr *MockAuthorizationRuleResolverMockRecorder) VisitRulesFor(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VisitRulesFor", reflect.TypeOf((*MockAuthorizationRuleResolver)(nil).VisitRulesFor), arg0, arg1, arg2) +} diff --git a/pkg/fakes/projectroletemplatebinding.go b/pkg/fakes/projectroletemplatebinding.go new file mode 100644 index 000000000..898097aff --- /dev/null +++ b/pkg/fakes/projectroletemplatebinding.go @@ -0,0 +1,494 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3 (interfaces: ProjectRoleTemplateBindingController,ProjectRoleTemplateBindingClient,ProjectRoleTemplateBindingCache) + +// Package fakes is a generated GoMock package. +package fakes + +import ( + context "context" + reflect "reflect" + time "time" + + gomock "github.com/golang/mock/gomock" + v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" + v30 "github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3" + generic "github.com/rancher/wrangler/pkg/generic" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// MockProjectRoleTemplateBindingController is a mock of ProjectRoleTemplateBindingController interface. +type MockProjectRoleTemplateBindingController struct { + ctrl *gomock.Controller + recorder *MockProjectRoleTemplateBindingControllerMockRecorder +} + +// MockProjectRoleTemplateBindingControllerMockRecorder is the mock recorder for MockProjectRoleTemplateBindingController. +type MockProjectRoleTemplateBindingControllerMockRecorder struct { + mock *MockProjectRoleTemplateBindingController +} + +// NewMockProjectRoleTemplateBindingController creates a new mock instance. +func NewMockProjectRoleTemplateBindingController(ctrl *gomock.Controller) *MockProjectRoleTemplateBindingController { + mock := &MockProjectRoleTemplateBindingController{ctrl: ctrl} + mock.recorder = &MockProjectRoleTemplateBindingControllerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockProjectRoleTemplateBindingController) EXPECT() *MockProjectRoleTemplateBindingControllerMockRecorder { + return m.recorder +} + +// AddGenericHandler mocks base method. +func (m *MockProjectRoleTemplateBindingController) AddGenericHandler(arg0 context.Context, arg1 string, arg2 generic.Handler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddGenericHandler", arg0, arg1, arg2) +} + +// AddGenericHandler indicates an expected call of AddGenericHandler. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) AddGenericHandler(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddGenericHandler", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).AddGenericHandler), arg0, arg1, arg2) +} + +// AddGenericRemoveHandler mocks base method. +func (m *MockProjectRoleTemplateBindingController) AddGenericRemoveHandler(arg0 context.Context, arg1 string, arg2 generic.Handler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddGenericRemoveHandler", arg0, arg1, arg2) +} + +// AddGenericRemoveHandler indicates an expected call of AddGenericRemoveHandler. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) AddGenericRemoveHandler(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddGenericRemoveHandler", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).AddGenericRemoveHandler), arg0, arg1, arg2) +} + +// Cache mocks base method. +func (m *MockProjectRoleTemplateBindingController) Cache() v30.ProjectRoleTemplateBindingCache { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Cache") + ret0, _ := ret[0].(v30.ProjectRoleTemplateBindingCache) + return ret0 +} + +// Cache indicates an expected call of Cache. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) Cache() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Cache", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).Cache)) +} + +// Create mocks base method. +func (m *MockProjectRoleTemplateBindingController) Create(arg0 *v3.ProjectRoleTemplateBinding) (*v3.ProjectRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0) + ret0, _ := ret[0].(*v3.ProjectRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) Create(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).Create), arg0) +} + +// Delete mocks base method. +func (m *MockProjectRoleTemplateBindingController) Delete(arg0, arg1 string, arg2 *v1.DeleteOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).Delete), arg0, arg1, arg2) +} + +// Enqueue mocks base method. +func (m *MockProjectRoleTemplateBindingController) Enqueue(arg0, arg1 string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Enqueue", arg0, arg1) +} + +// Enqueue indicates an expected call of Enqueue. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) Enqueue(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Enqueue", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).Enqueue), arg0, arg1) +} + +// EnqueueAfter mocks base method. +func (m *MockProjectRoleTemplateBindingController) EnqueueAfter(arg0, arg1 string, arg2 time.Duration) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "EnqueueAfter", arg0, arg1, arg2) +} + +// EnqueueAfter indicates an expected call of EnqueueAfter. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) EnqueueAfter(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnqueueAfter", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).EnqueueAfter), arg0, arg1, arg2) +} + +// Get mocks base method. +func (m *MockProjectRoleTemplateBindingController) Get(arg0, arg1 string, arg2 v1.GetOptions) (*v3.ProjectRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2) + ret0, _ := ret[0].(*v3.ProjectRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) Get(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).Get), arg0, arg1, arg2) +} + +// GroupVersionKind mocks base method. +func (m *MockProjectRoleTemplateBindingController) GroupVersionKind() schema.GroupVersionKind { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GroupVersionKind") + ret0, _ := ret[0].(schema.GroupVersionKind) + return ret0 +} + +// GroupVersionKind indicates an expected call of GroupVersionKind. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) GroupVersionKind() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GroupVersionKind", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).GroupVersionKind)) +} + +// Informer mocks base method. +func (m *MockProjectRoleTemplateBindingController) Informer() cache.SharedIndexInformer { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Informer") + ret0, _ := ret[0].(cache.SharedIndexInformer) + return ret0 +} + +// Informer indicates an expected call of Informer. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) Informer() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Informer", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).Informer)) +} + +// List mocks base method. +func (m *MockProjectRoleTemplateBindingController) List(arg0 string, arg1 v1.ListOptions) (*v3.ProjectRoleTemplateBindingList, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0, arg1) + ret0, _ := ret[0].(*v3.ProjectRoleTemplateBindingList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) List(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).List), arg0, arg1) +} + +// OnChange mocks base method. +func (m *MockProjectRoleTemplateBindingController) OnChange(arg0 context.Context, arg1 string, arg2 v30.ProjectRoleTemplateBindingHandler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "OnChange", arg0, arg1, arg2) +} + +// OnChange indicates an expected call of OnChange. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) OnChange(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnChange", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).OnChange), arg0, arg1, arg2) +} + +// OnRemove mocks base method. +func (m *MockProjectRoleTemplateBindingController) OnRemove(arg0 context.Context, arg1 string, arg2 v30.ProjectRoleTemplateBindingHandler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "OnRemove", arg0, arg1, arg2) +} + +// OnRemove indicates an expected call of OnRemove. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) OnRemove(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnRemove", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).OnRemove), arg0, arg1, arg2) +} + +// Patch mocks base method. +func (m *MockProjectRoleTemplateBindingController) Patch(arg0, arg1 string, arg2 types.PatchType, arg3 []byte, arg4 ...string) (*v3.ProjectRoleTemplateBinding, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1, arg2, arg3} + for _, a := range arg4 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Patch", varargs...) + ret0, _ := ret[0].(*v3.ProjectRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Patch indicates an expected call of Patch. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) Patch(arg0, arg1, arg2, arg3 interface{}, arg4 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1, arg2, arg3}, arg4...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Patch", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).Patch), varargs...) +} + +// Update mocks base method. +func (m *MockProjectRoleTemplateBindingController) Update(arg0 *v3.ProjectRoleTemplateBinding) (*v3.ProjectRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", arg0) + ret0, _ := ret[0].(*v3.ProjectRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Update indicates an expected call of Update. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) Update(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).Update), arg0) +} + +// Updater mocks base method. +func (m *MockProjectRoleTemplateBindingController) Updater() generic.Updater { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Updater") + ret0, _ := ret[0].(generic.Updater) + return ret0 +} + +// Updater indicates an expected call of Updater. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) Updater() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Updater", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).Updater)) +} + +// Watch mocks base method. +func (m *MockProjectRoleTemplateBindingController) Watch(arg0 string, arg1 v1.ListOptions) (watch.Interface, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Watch", arg0, arg1) + ret0, _ := ret[0].(watch.Interface) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Watch indicates an expected call of Watch. +func (mr *MockProjectRoleTemplateBindingControllerMockRecorder) Watch(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Watch", reflect.TypeOf((*MockProjectRoleTemplateBindingController)(nil).Watch), arg0, arg1) +} + +// MockProjectRoleTemplateBindingClient is a mock of ProjectRoleTemplateBindingClient interface. +type MockProjectRoleTemplateBindingClient struct { + ctrl *gomock.Controller + recorder *MockProjectRoleTemplateBindingClientMockRecorder +} + +// MockProjectRoleTemplateBindingClientMockRecorder is the mock recorder for MockProjectRoleTemplateBindingClient. +type MockProjectRoleTemplateBindingClientMockRecorder struct { + mock *MockProjectRoleTemplateBindingClient +} + +// NewMockProjectRoleTemplateBindingClient creates a new mock instance. +func NewMockProjectRoleTemplateBindingClient(ctrl *gomock.Controller) *MockProjectRoleTemplateBindingClient { + mock := &MockProjectRoleTemplateBindingClient{ctrl: ctrl} + mock.recorder = &MockProjectRoleTemplateBindingClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockProjectRoleTemplateBindingClient) EXPECT() *MockProjectRoleTemplateBindingClientMockRecorder { + return m.recorder +} + +// Create mocks base method. +func (m *MockProjectRoleTemplateBindingClient) Create(arg0 *v3.ProjectRoleTemplateBinding) (*v3.ProjectRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0) + ret0, _ := ret[0].(*v3.ProjectRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create. +func (mr *MockProjectRoleTemplateBindingClientMockRecorder) Create(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockProjectRoleTemplateBindingClient)(nil).Create), arg0) +} + +// Delete mocks base method. +func (m *MockProjectRoleTemplateBindingClient) Delete(arg0, arg1 string, arg2 *v1.DeleteOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockProjectRoleTemplateBindingClientMockRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockProjectRoleTemplateBindingClient)(nil).Delete), arg0, arg1, arg2) +} + +// Get mocks base method. +func (m *MockProjectRoleTemplateBindingClient) Get(arg0, arg1 string, arg2 v1.GetOptions) (*v3.ProjectRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2) + ret0, _ := ret[0].(*v3.ProjectRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockProjectRoleTemplateBindingClientMockRecorder) Get(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockProjectRoleTemplateBindingClient)(nil).Get), arg0, arg1, arg2) +} + +// List mocks base method. +func (m *MockProjectRoleTemplateBindingClient) List(arg0 string, arg1 v1.ListOptions) (*v3.ProjectRoleTemplateBindingList, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0, arg1) + ret0, _ := ret[0].(*v3.ProjectRoleTemplateBindingList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockProjectRoleTemplateBindingClientMockRecorder) List(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockProjectRoleTemplateBindingClient)(nil).List), arg0, arg1) +} + +// Patch mocks base method. +func (m *MockProjectRoleTemplateBindingClient) Patch(arg0, arg1 string, arg2 types.PatchType, arg3 []byte, arg4 ...string) (*v3.ProjectRoleTemplateBinding, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1, arg2, arg3} + for _, a := range arg4 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Patch", varargs...) + ret0, _ := ret[0].(*v3.ProjectRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Patch indicates an expected call of Patch. +func (mr *MockProjectRoleTemplateBindingClientMockRecorder) Patch(arg0, arg1, arg2, arg3 interface{}, arg4 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1, arg2, arg3}, arg4...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Patch", reflect.TypeOf((*MockProjectRoleTemplateBindingClient)(nil).Patch), varargs...) +} + +// Update mocks base method. +func (m *MockProjectRoleTemplateBindingClient) Update(arg0 *v3.ProjectRoleTemplateBinding) (*v3.ProjectRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", arg0) + ret0, _ := ret[0].(*v3.ProjectRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Update indicates an expected call of Update. +func (mr *MockProjectRoleTemplateBindingClientMockRecorder) Update(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockProjectRoleTemplateBindingClient)(nil).Update), arg0) +} + +// Watch mocks base method. +func (m *MockProjectRoleTemplateBindingClient) Watch(arg0 string, arg1 v1.ListOptions) (watch.Interface, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Watch", arg0, arg1) + ret0, _ := ret[0].(watch.Interface) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Watch indicates an expected call of Watch. +func (mr *MockProjectRoleTemplateBindingClientMockRecorder) Watch(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Watch", reflect.TypeOf((*MockProjectRoleTemplateBindingClient)(nil).Watch), arg0, arg1) +} + +// MockProjectRoleTemplateBindingCache is a mock of ProjectRoleTemplateBindingCache interface. +type MockProjectRoleTemplateBindingCache struct { + ctrl *gomock.Controller + recorder *MockProjectRoleTemplateBindingCacheMockRecorder +} + +// MockProjectRoleTemplateBindingCacheMockRecorder is the mock recorder for MockProjectRoleTemplateBindingCache. +type MockProjectRoleTemplateBindingCacheMockRecorder struct { + mock *MockProjectRoleTemplateBindingCache +} + +// NewMockProjectRoleTemplateBindingCache creates a new mock instance. +func NewMockProjectRoleTemplateBindingCache(ctrl *gomock.Controller) *MockProjectRoleTemplateBindingCache { + mock := &MockProjectRoleTemplateBindingCache{ctrl: ctrl} + mock.recorder = &MockProjectRoleTemplateBindingCacheMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockProjectRoleTemplateBindingCache) EXPECT() *MockProjectRoleTemplateBindingCacheMockRecorder { + return m.recorder +} + +// AddIndexer mocks base method. +func (m *MockProjectRoleTemplateBindingCache) AddIndexer(arg0 string, arg1 v30.ProjectRoleTemplateBindingIndexer) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddIndexer", arg0, arg1) +} + +// AddIndexer indicates an expected call of AddIndexer. +func (mr *MockProjectRoleTemplateBindingCacheMockRecorder) AddIndexer(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddIndexer", reflect.TypeOf((*MockProjectRoleTemplateBindingCache)(nil).AddIndexer), arg0, arg1) +} + +// Get mocks base method. +func (m *MockProjectRoleTemplateBindingCache) Get(arg0, arg1 string) (*v3.ProjectRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1) + ret0, _ := ret[0].(*v3.ProjectRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockProjectRoleTemplateBindingCacheMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockProjectRoleTemplateBindingCache)(nil).Get), arg0, arg1) +} + +// GetByIndex mocks base method. +func (m *MockProjectRoleTemplateBindingCache) GetByIndex(arg0, arg1 string) ([]*v3.ProjectRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetByIndex", arg0, arg1) + ret0, _ := ret[0].([]*v3.ProjectRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetByIndex indicates an expected call of GetByIndex. +func (mr *MockProjectRoleTemplateBindingCacheMockRecorder) GetByIndex(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByIndex", reflect.TypeOf((*MockProjectRoleTemplateBindingCache)(nil).GetByIndex), arg0, arg1) +} + +// List mocks base method. +func (m *MockProjectRoleTemplateBindingCache) List(arg0 string, arg1 labels.Selector) ([]*v3.ProjectRoleTemplateBinding, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0, arg1) + ret0, _ := ret[0].([]*v3.ProjectRoleTemplateBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockProjectRoleTemplateBindingCacheMockRecorder) List(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockProjectRoleTemplateBindingCache)(nil).List), arg0, arg1) +} diff --git a/pkg/fakes/roleTemplateCache.go b/pkg/fakes/roleTemplateCache.go deleted file mode 100644 index 0d3c86f57..000000000 --- a/pkg/fakes/roleTemplateCache.go +++ /dev/null @@ -1,94 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3 (interfaces: RoleTemplateCache) - -// Package fakes is a generated GoMock package. -package fakes - -import ( - reflect "reflect" - - gomock "github.com/golang/mock/gomock" - v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" - v30 "github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3" - labels "k8s.io/apimachinery/pkg/labels" -) - -// MockRoleTemplateCache is a mock of RoleTemplateCache interface. -type MockRoleTemplateCache struct { - ctrl *gomock.Controller - recorder *MockRoleTemplateCacheMockRecorder -} - -// MockRoleTemplateCacheMockRecorder is the mock recorder for MockRoleTemplateCache. -type MockRoleTemplateCacheMockRecorder struct { - mock *MockRoleTemplateCache -} - -// NewMockRoleTemplateCache creates a new mock instance. -func NewMockRoleTemplateCache(ctrl *gomock.Controller) *MockRoleTemplateCache { - mock := &MockRoleTemplateCache{ctrl: ctrl} - mock.recorder = &MockRoleTemplateCacheMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockRoleTemplateCache) EXPECT() *MockRoleTemplateCacheMockRecorder { - return m.recorder -} - -// AddIndexer mocks base method. -func (m *MockRoleTemplateCache) AddIndexer(arg0 string, arg1 v30.RoleTemplateIndexer) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "AddIndexer", arg0, arg1) -} - -// AddIndexer indicates an expected call of AddIndexer. -func (mr *MockRoleTemplateCacheMockRecorder) AddIndexer(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddIndexer", reflect.TypeOf((*MockRoleTemplateCache)(nil).AddIndexer), arg0, arg1) -} - -// Get mocks base method. -func (m *MockRoleTemplateCache) Get(arg0 string) (*v3.RoleTemplate, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Get", arg0) - ret0, _ := ret[0].(*v3.RoleTemplate) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Get indicates an expected call of Get. -func (mr *MockRoleTemplateCacheMockRecorder) Get(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockRoleTemplateCache)(nil).Get), arg0) -} - -// GetByIndex mocks base method. -func (m *MockRoleTemplateCache) GetByIndex(arg0, arg1 string) ([]*v3.RoleTemplate, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetByIndex", arg0, arg1) - ret0, _ := ret[0].([]*v3.RoleTemplate) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetByIndex indicates an expected call of GetByIndex. -func (mr *MockRoleTemplateCacheMockRecorder) GetByIndex(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByIndex", reflect.TypeOf((*MockRoleTemplateCache)(nil).GetByIndex), arg0, arg1) -} - -// List mocks base method. -func (m *MockRoleTemplateCache) List(arg0 labels.Selector) ([]*v3.RoleTemplate, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "List", arg0) - ret0, _ := ret[0].([]*v3.RoleTemplate) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// List indicates an expected call of List. -func (mr *MockRoleTemplateCacheMockRecorder) List(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockRoleTemplateCache)(nil).List), arg0) -} diff --git a/pkg/fakes/roletemplate.go b/pkg/fakes/roletemplate.go new file mode 100644 index 000000000..a15be1628 --- /dev/null +++ b/pkg/fakes/roletemplate.go @@ -0,0 +1,494 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3 (interfaces: RoleTemplateController,RoleTemplateClient,RoleTemplateCache) + +// Package fakes is a generated GoMock package. +package fakes + +import ( + context "context" + reflect "reflect" + time "time" + + gomock "github.com/golang/mock/gomock" + v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" + v30 "github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3" + generic "github.com/rancher/wrangler/pkg/generic" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// MockRoleTemplateController is a mock of RoleTemplateController interface. +type MockRoleTemplateController struct { + ctrl *gomock.Controller + recorder *MockRoleTemplateControllerMockRecorder +} + +// MockRoleTemplateControllerMockRecorder is the mock recorder for MockRoleTemplateController. +type MockRoleTemplateControllerMockRecorder struct { + mock *MockRoleTemplateController +} + +// NewMockRoleTemplateController creates a new mock instance. +func NewMockRoleTemplateController(ctrl *gomock.Controller) *MockRoleTemplateController { + mock := &MockRoleTemplateController{ctrl: ctrl} + mock.recorder = &MockRoleTemplateControllerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockRoleTemplateController) EXPECT() *MockRoleTemplateControllerMockRecorder { + return m.recorder +} + +// AddGenericHandler mocks base method. +func (m *MockRoleTemplateController) AddGenericHandler(arg0 context.Context, arg1 string, arg2 generic.Handler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddGenericHandler", arg0, arg1, arg2) +} + +// AddGenericHandler indicates an expected call of AddGenericHandler. +func (mr *MockRoleTemplateControllerMockRecorder) AddGenericHandler(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddGenericHandler", reflect.TypeOf((*MockRoleTemplateController)(nil).AddGenericHandler), arg0, arg1, arg2) +} + +// AddGenericRemoveHandler mocks base method. +func (m *MockRoleTemplateController) AddGenericRemoveHandler(arg0 context.Context, arg1 string, arg2 generic.Handler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddGenericRemoveHandler", arg0, arg1, arg2) +} + +// AddGenericRemoveHandler indicates an expected call of AddGenericRemoveHandler. +func (mr *MockRoleTemplateControllerMockRecorder) AddGenericRemoveHandler(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddGenericRemoveHandler", reflect.TypeOf((*MockRoleTemplateController)(nil).AddGenericRemoveHandler), arg0, arg1, arg2) +} + +// Cache mocks base method. +func (m *MockRoleTemplateController) Cache() v30.RoleTemplateCache { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Cache") + ret0, _ := ret[0].(v30.RoleTemplateCache) + return ret0 +} + +// Cache indicates an expected call of Cache. +func (mr *MockRoleTemplateControllerMockRecorder) Cache() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Cache", reflect.TypeOf((*MockRoleTemplateController)(nil).Cache)) +} + +// Create mocks base method. +func (m *MockRoleTemplateController) Create(arg0 *v3.RoleTemplate) (*v3.RoleTemplate, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0) + ret0, _ := ret[0].(*v3.RoleTemplate) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create. +func (mr *MockRoleTemplateControllerMockRecorder) Create(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockRoleTemplateController)(nil).Create), arg0) +} + +// Delete mocks base method. +func (m *MockRoleTemplateController) Delete(arg0 string, arg1 *v1.DeleteOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockRoleTemplateControllerMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockRoleTemplateController)(nil).Delete), arg0, arg1) +} + +// Enqueue mocks base method. +func (m *MockRoleTemplateController) Enqueue(arg0 string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Enqueue", arg0) +} + +// Enqueue indicates an expected call of Enqueue. +func (mr *MockRoleTemplateControllerMockRecorder) Enqueue(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Enqueue", reflect.TypeOf((*MockRoleTemplateController)(nil).Enqueue), arg0) +} + +// EnqueueAfter mocks base method. +func (m *MockRoleTemplateController) EnqueueAfter(arg0 string, arg1 time.Duration) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "EnqueueAfter", arg0, arg1) +} + +// EnqueueAfter indicates an expected call of EnqueueAfter. +func (mr *MockRoleTemplateControllerMockRecorder) EnqueueAfter(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnqueueAfter", reflect.TypeOf((*MockRoleTemplateController)(nil).EnqueueAfter), arg0, arg1) +} + +// Get mocks base method. +func (m *MockRoleTemplateController) Get(arg0 string, arg1 v1.GetOptions) (*v3.RoleTemplate, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1) + ret0, _ := ret[0].(*v3.RoleTemplate) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockRoleTemplateControllerMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockRoleTemplateController)(nil).Get), arg0, arg1) +} + +// GroupVersionKind mocks base method. +func (m *MockRoleTemplateController) GroupVersionKind() schema.GroupVersionKind { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GroupVersionKind") + ret0, _ := ret[0].(schema.GroupVersionKind) + return ret0 +} + +// GroupVersionKind indicates an expected call of GroupVersionKind. +func (mr *MockRoleTemplateControllerMockRecorder) GroupVersionKind() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GroupVersionKind", reflect.TypeOf((*MockRoleTemplateController)(nil).GroupVersionKind)) +} + +// Informer mocks base method. +func (m *MockRoleTemplateController) Informer() cache.SharedIndexInformer { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Informer") + ret0, _ := ret[0].(cache.SharedIndexInformer) + return ret0 +} + +// Informer indicates an expected call of Informer. +func (mr *MockRoleTemplateControllerMockRecorder) Informer() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Informer", reflect.TypeOf((*MockRoleTemplateController)(nil).Informer)) +} + +// List mocks base method. +func (m *MockRoleTemplateController) List(arg0 v1.ListOptions) (*v3.RoleTemplateList, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0) + ret0, _ := ret[0].(*v3.RoleTemplateList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockRoleTemplateControllerMockRecorder) List(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockRoleTemplateController)(nil).List), arg0) +} + +// OnChange mocks base method. +func (m *MockRoleTemplateController) OnChange(arg0 context.Context, arg1 string, arg2 v30.RoleTemplateHandler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "OnChange", arg0, arg1, arg2) +} + +// OnChange indicates an expected call of OnChange. +func (mr *MockRoleTemplateControllerMockRecorder) OnChange(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnChange", reflect.TypeOf((*MockRoleTemplateController)(nil).OnChange), arg0, arg1, arg2) +} + +// OnRemove mocks base method. +func (m *MockRoleTemplateController) OnRemove(arg0 context.Context, arg1 string, arg2 v30.RoleTemplateHandler) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "OnRemove", arg0, arg1, arg2) +} + +// OnRemove indicates an expected call of OnRemove. +func (mr *MockRoleTemplateControllerMockRecorder) OnRemove(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnRemove", reflect.TypeOf((*MockRoleTemplateController)(nil).OnRemove), arg0, arg1, arg2) +} + +// Patch mocks base method. +func (m *MockRoleTemplateController) Patch(arg0 string, arg1 types.PatchType, arg2 []byte, arg3 ...string) (*v3.RoleTemplate, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1, arg2} + for _, a := range arg3 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Patch", varargs...) + ret0, _ := ret[0].(*v3.RoleTemplate) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Patch indicates an expected call of Patch. +func (mr *MockRoleTemplateControllerMockRecorder) Patch(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Patch", reflect.TypeOf((*MockRoleTemplateController)(nil).Patch), varargs...) +} + +// Update mocks base method. +func (m *MockRoleTemplateController) Update(arg0 *v3.RoleTemplate) (*v3.RoleTemplate, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", arg0) + ret0, _ := ret[0].(*v3.RoleTemplate) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Update indicates an expected call of Update. +func (mr *MockRoleTemplateControllerMockRecorder) Update(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockRoleTemplateController)(nil).Update), arg0) +} + +// Updater mocks base method. +func (m *MockRoleTemplateController) Updater() generic.Updater { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Updater") + ret0, _ := ret[0].(generic.Updater) + return ret0 +} + +// Updater indicates an expected call of Updater. +func (mr *MockRoleTemplateControllerMockRecorder) Updater() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Updater", reflect.TypeOf((*MockRoleTemplateController)(nil).Updater)) +} + +// Watch mocks base method. +func (m *MockRoleTemplateController) Watch(arg0 v1.ListOptions) (watch.Interface, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Watch", arg0) + ret0, _ := ret[0].(watch.Interface) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Watch indicates an expected call of Watch. +func (mr *MockRoleTemplateControllerMockRecorder) Watch(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Watch", reflect.TypeOf((*MockRoleTemplateController)(nil).Watch), arg0) +} + +// MockRoleTemplateClient is a mock of RoleTemplateClient interface. +type MockRoleTemplateClient struct { + ctrl *gomock.Controller + recorder *MockRoleTemplateClientMockRecorder +} + +// MockRoleTemplateClientMockRecorder is the mock recorder for MockRoleTemplateClient. +type MockRoleTemplateClientMockRecorder struct { + mock *MockRoleTemplateClient +} + +// NewMockRoleTemplateClient creates a new mock instance. +func NewMockRoleTemplateClient(ctrl *gomock.Controller) *MockRoleTemplateClient { + mock := &MockRoleTemplateClient{ctrl: ctrl} + mock.recorder = &MockRoleTemplateClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockRoleTemplateClient) EXPECT() *MockRoleTemplateClientMockRecorder { + return m.recorder +} + +// Create mocks base method. +func (m *MockRoleTemplateClient) Create(arg0 *v3.RoleTemplate) (*v3.RoleTemplate, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0) + ret0, _ := ret[0].(*v3.RoleTemplate) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create. +func (mr *MockRoleTemplateClientMockRecorder) Create(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockRoleTemplateClient)(nil).Create), arg0) +} + +// Delete mocks base method. +func (m *MockRoleTemplateClient) Delete(arg0 string, arg1 *v1.DeleteOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockRoleTemplateClientMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockRoleTemplateClient)(nil).Delete), arg0, arg1) +} + +// Get mocks base method. +func (m *MockRoleTemplateClient) Get(arg0 string, arg1 v1.GetOptions) (*v3.RoleTemplate, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1) + ret0, _ := ret[0].(*v3.RoleTemplate) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockRoleTemplateClientMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockRoleTemplateClient)(nil).Get), arg0, arg1) +} + +// List mocks base method. +func (m *MockRoleTemplateClient) List(arg0 v1.ListOptions) (*v3.RoleTemplateList, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0) + ret0, _ := ret[0].(*v3.RoleTemplateList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockRoleTemplateClientMockRecorder) List(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockRoleTemplateClient)(nil).List), arg0) +} + +// Patch mocks base method. +func (m *MockRoleTemplateClient) Patch(arg0 string, arg1 types.PatchType, arg2 []byte, arg3 ...string) (*v3.RoleTemplate, error) { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1, arg2} + for _, a := range arg3 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Patch", varargs...) + ret0, _ := ret[0].(*v3.RoleTemplate) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Patch indicates an expected call of Patch. +func (mr *MockRoleTemplateClientMockRecorder) Patch(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Patch", reflect.TypeOf((*MockRoleTemplateClient)(nil).Patch), varargs...) +} + +// Update mocks base method. +func (m *MockRoleTemplateClient) Update(arg0 *v3.RoleTemplate) (*v3.RoleTemplate, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", arg0) + ret0, _ := ret[0].(*v3.RoleTemplate) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Update indicates an expected call of Update. +func (mr *MockRoleTemplateClientMockRecorder) Update(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockRoleTemplateClient)(nil).Update), arg0) +} + +// Watch mocks base method. +func (m *MockRoleTemplateClient) Watch(arg0 v1.ListOptions) (watch.Interface, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Watch", arg0) + ret0, _ := ret[0].(watch.Interface) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Watch indicates an expected call of Watch. +func (mr *MockRoleTemplateClientMockRecorder) Watch(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Watch", reflect.TypeOf((*MockRoleTemplateClient)(nil).Watch), arg0) +} + +// MockRoleTemplateCache is a mock of RoleTemplateCache interface. +type MockRoleTemplateCache struct { + ctrl *gomock.Controller + recorder *MockRoleTemplateCacheMockRecorder +} + +// MockRoleTemplateCacheMockRecorder is the mock recorder for MockRoleTemplateCache. +type MockRoleTemplateCacheMockRecorder struct { + mock *MockRoleTemplateCache +} + +// NewMockRoleTemplateCache creates a new mock instance. +func NewMockRoleTemplateCache(ctrl *gomock.Controller) *MockRoleTemplateCache { + mock := &MockRoleTemplateCache{ctrl: ctrl} + mock.recorder = &MockRoleTemplateCacheMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockRoleTemplateCache) EXPECT() *MockRoleTemplateCacheMockRecorder { + return m.recorder +} + +// AddIndexer mocks base method. +func (m *MockRoleTemplateCache) AddIndexer(arg0 string, arg1 v30.RoleTemplateIndexer) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddIndexer", arg0, arg1) +} + +// AddIndexer indicates an expected call of AddIndexer. +func (mr *MockRoleTemplateCacheMockRecorder) AddIndexer(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddIndexer", reflect.TypeOf((*MockRoleTemplateCache)(nil).AddIndexer), arg0, arg1) +} + +// Get mocks base method. +func (m *MockRoleTemplateCache) Get(arg0 string) (*v3.RoleTemplate, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0) + ret0, _ := ret[0].(*v3.RoleTemplate) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockRoleTemplateCacheMockRecorder) Get(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockRoleTemplateCache)(nil).Get), arg0) +} + +// GetByIndex mocks base method. +func (m *MockRoleTemplateCache) GetByIndex(arg0, arg1 string) ([]*v3.RoleTemplate, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetByIndex", arg0, arg1) + ret0, _ := ret[0].([]*v3.RoleTemplate) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetByIndex indicates an expected call of GetByIndex. +func (mr *MockRoleTemplateCacheMockRecorder) GetByIndex(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByIndex", reflect.TypeOf((*MockRoleTemplateCache)(nil).GetByIndex), arg0, arg1) +} + +// List mocks base method. +func (m *MockRoleTemplateCache) List(arg0 labels.Selector) ([]*v3.RoleTemplate, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0) + ret0, _ := ret[0].([]*v3.RoleTemplate) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockRoleTemplateCacheMockRecorder) List(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockRoleTemplateCache)(nil).List), arg0) +} diff --git a/pkg/resolvers/aggregateResolver_test.go b/pkg/resolvers/aggregateResolver_test.go new file mode 100644 index 000000000..0f8fdf9ed --- /dev/null +++ b/pkg/resolvers/aggregateResolver_test.go @@ -0,0 +1,169 @@ +package resolvers_test + +import ( + "fmt" + "testing" + + "github.com/golang/mock/gomock" + "github.com/rancher/webhook/pkg/fakes" + "github.com/rancher/webhook/pkg/resolvers" + "github.com/stretchr/testify/suite" + rbacv1 "k8s.io/api/rbac/v1" + "k8s.io/apiserver/pkg/authentication/user" + "k8s.io/kubernetes/pkg/registry/rbac/validation" +) + +type AggregateResolverSuite struct { + suite.Suite + ruleReadPods rbacv1.PolicyRule + ruleAdmin rbacv1.PolicyRule +} + +func TestAggregateResolver(t *testing.T) { + t.Parallel() + suite.Run(t, new(AggregateResolverSuite)) +} + +func (a *AggregateResolverSuite) SetupSuite() { + a.ruleReadPods = rbacv1.PolicyRule{ + Verbs: []string{"GET", "WATCH"}, + APIGroups: []string{"v1"}, + Resources: []string{"pods"}, + } + a.ruleAdmin = rbacv1.PolicyRule{ + Verbs: []string{"*"}, + APIGroups: []string{"*"}, + Resources: []string{"*"}, + } +} + +func (a *AggregateResolverSuite) TestAggregateRuleResolverGetRules() { + const testNameSpace = "namespace1" + testUser := NewUserInfo("testUser") + + tests := []struct { + name string + user user.Info + namespace string + resolvers func(*testing.T) ([]validation.AuthorizationRuleResolver, Rules) + wantRules Rules + wantErr bool + }{ + { + name: "rules from single resolver", + user: testUser, + namespace: testNameSpace, + resolvers: func(t *testing.T) ([]validation.AuthorizationRuleResolver, Rules) { + expectedRules := []rbacv1.PolicyRule{a.ruleAdmin} + resolver := fakes.NewMockAuthorizationRuleResolver(gomock.NewController(t)) + resolver.EXPECT().VisitRulesFor(testUser, testNameSpace, gomock.Any()). + DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool { + for _, rule := range expectedRules { + visitor(nil, &rule, nil) + } + return true + }) + resolver.EXPECT().GetRoleReferenceRules(gomock.Any(), gomock.Any()).Return(expectedRules, nil) + return []validation.AuthorizationRuleResolver{resolver}, expectedRules + }, + }, + { + name: "rules from invalid user", + user: NewUserInfo("invalidUser"), + namespace: testNameSpace, + wantErr: true, + resolvers: func(t *testing.T) ([]validation.AuthorizationRuleResolver, Rules) { + expectedRules := []rbacv1.PolicyRule{} + resolver := fakes.NewMockAuthorizationRuleResolver(gomock.NewController(t)) + resolver.EXPECT().VisitRulesFor(gomock.Any(), testNameSpace, gomock.Any()). + DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool { + visitor(nil, nil, errNotFound) + return true + }) + resolver2 := fakes.NewMockAuthorizationRuleResolver(gomock.NewController(t)) + resolver2.EXPECT().VisitRulesFor(gomock.Any(), testNameSpace, gomock.Any()). + DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool { + visitor(nil, nil, errNotFound) + return true + }) + return []validation.AuthorizationRuleResolver{resolver, resolver2}, expectedRules + }, + }, + { + name: "rules from second resolver in list", + user: testUser, + namespace: testNameSpace, + resolvers: func(t *testing.T) ([]validation.AuthorizationRuleResolver, Rules) { + expectedRules := []rbacv1.PolicyRule{a.ruleReadPods} + resolver := fakes.NewMockAuthorizationRuleResolver(gomock.NewController(t)) + resolver.EXPECT().VisitRulesFor(testUser, testNameSpace, gomock.Any()). + DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool { + return true + }) + resolver.EXPECT().GetRoleReferenceRules(gomock.Any(), gomock.Any()).Return(expectedRules, nil) + resolver2 := fakes.NewMockAuthorizationRuleResolver(gomock.NewController(t)) + resolver2.EXPECT().VisitRulesFor(testUser, testNameSpace, gomock.Any()). + DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool { + for _, rule := range expectedRules { + visitor(nil, &rule, nil) + } + return true + }) + resolver2.EXPECT().GetRoleReferenceRules(gomock.Any(), gomock.Any()).Return(nil, nil) + return []validation.AuthorizationRuleResolver{resolver, resolver2}, expectedRules + }, + }, + { + name: "rules from both resolvers in list", + user: testUser, + namespace: testNameSpace, + resolvers: func(t *testing.T) ([]validation.AuthorizationRuleResolver, Rules) { + expectedRules1 := []rbacv1.PolicyRule{a.ruleAdmin} + expectedRules2 := []rbacv1.PolicyRule{a.ruleReadPods} + resolver := fakes.NewMockAuthorizationRuleResolver(gomock.NewController(t)) + resolver.EXPECT().VisitRulesFor(testUser, testNameSpace, gomock.Any()). + DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool { + for _, rule := range expectedRules1 { + visitor(nil, &rule, nil) + } + return true + }) + resolver.EXPECT().GetRoleReferenceRules(gomock.Any(), gomock.Any()).Return(expectedRules1, nil) + resolver2 := fakes.NewMockAuthorizationRuleResolver(gomock.NewController(t)) + resolver2.EXPECT().VisitRulesFor(testUser, testNameSpace, gomock.Any()). + DoAndReturn(func(userInfo user.Info, namespace string, visitor func(source fmt.Stringer, rule *rbacv1.PolicyRule, err error) bool) bool { + for _, rule := range expectedRules2 { + visitor(nil, &rule, nil) + } + return true + }) + resolver2.EXPECT().GetRoleReferenceRules(gomock.Any(), gomock.Any()).Return(expectedRules2, nil) + return []validation.AuthorizationRuleResolver{resolver, resolver2}, append(expectedRules1, expectedRules2...) + }, + }, + } + for _, tt := range tests { + a.Run(tt.name, func() { + resolverList, expectedRules := tt.resolvers(a.T()) + agg := resolvers.NewAggregateRuleResolver(resolverList...) + gotRules, err := agg.RulesFor(tt.user, tt.namespace) + if tt.wantErr { + a.Errorf(err, "AggregateRuleResolver.RulesFor() error = %v, wantErr %v", err, tt.wantErr) + // still check result because function is suppose to return partial results. + + if !expectedRules.Equal(gotRules) { + a.Fail("List of rules did not match", "wanted=%+v got=%+v", expectedRules, gotRules) + } + return + } + a.NoError(err, "unexpected error") + if !expectedRules.Equal(gotRules) { + a.Fail("List of rules did not match", "wanted=%+v got=%+v", expectedRules, gotRules) + } + gotRules, err = agg.GetRoleReferenceRules(rbacv1.RoleRef{}, tt.namespace) + if !expectedRules.Equal(gotRules) { + a.Fail("List of rules did not match", "wanted=%+v got=%+v", expectedRules, gotRules) + } + }) + } +} diff --git a/pkg/resolvers/crtbResolver_test.go b/pkg/resolvers/crtbResolver_test.go new file mode 100644 index 000000000..5c971a5ef --- /dev/null +++ b/pkg/resolvers/crtbResolver_test.go @@ -0,0 +1,228 @@ +package resolvers_test + +import ( + "testing" + + "github.com/golang/mock/gomock" + apisv3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" + "github.com/rancher/webhook/pkg/auth" + "github.com/rancher/webhook/pkg/fakes" + v3 "github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3" + "github.com/rancher/webhook/pkg/resolvers" + "github.com/stretchr/testify/suite" + rbacv1 "k8s.io/api/rbac/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apiserver/pkg/authentication/user" +) + +type CRTBResolverSuite struct { + suite.Suite + adminRT *apisv3.RoleTemplate + readRT *apisv3.RoleTemplate + writeRT *apisv3.RoleTemplate + user1AdminCRTB *apisv3.ClusterRoleTemplateBinding + user1AReadNS2CRTB *apisv3.ClusterRoleTemplateBinding + user1InvalidNS2CRTB *apisv3.ClusterRoleTemplateBinding + user2WriteCRTB *apisv3.ClusterRoleTemplateBinding + user2ReadCRTB *apisv3.ClusterRoleTemplateBinding +} + +func TestCRTBResolver(t *testing.T) { + t.Parallel() + suite.Run(t, new(CRTBResolverSuite)) +} + +func (c *CRTBResolverSuite) SetupSuite() { + ruleReadPods := rbacv1.PolicyRule{ + Verbs: []string{"GET", "WATCH"}, + APIGroups: []string{"v1"}, + Resources: []string{"pods"}, + } + ruleReadServices := rbacv1.PolicyRule{ + Verbs: []string{"GET", "WATCH"}, + APIGroups: []string{"v1"}, + Resources: []string{"services"}, + } + ruleWriteNodes := rbacv1.PolicyRule{ + Verbs: []string{"PUT", "CREATE", "UPDATE"}, + APIGroups: []string{"v1"}, + Resources: []string{"nodes"}, + } + ruleAdmin := rbacv1.PolicyRule{ + Verbs: []string{"*"}, + APIGroups: []string{"*"}, + Resources: []string{"*"}, + } + c.readRT = &apisv3.RoleTemplate{ + ObjectMeta: metav1.ObjectMeta{ + Name: "read-role", + }, + DisplayName: "Read Role", + Rules: []rbacv1.PolicyRule{ruleReadPods, ruleReadServices}, + Context: "cluster", + } + c.adminRT = &apisv3.RoleTemplate{ + ObjectMeta: metav1.ObjectMeta{ + Name: "admin-role", + }, + DisplayName: "Admin Role", + Rules: []rbacv1.PolicyRule{ruleAdmin}, + Builtin: true, + Administrative: true, + Context: "cluster", + } + c.writeRT = &apisv3.RoleTemplate{ + ObjectMeta: metav1.ObjectMeta{ + Name: "locked-role", + }, + DisplayName: "Locked Role", + Rules: []rbacv1.PolicyRule{ruleWriteNodes}, + Locked: true, + Context: "cluster", + } + c.user1AdminCRTB = &apisv3.ClusterRoleTemplateBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "user1-admin", + Namespace: "namespace1", + }, + UserName: "user1", + RoleTemplateName: c.adminRT.Name, + } + c.user1AReadNS2CRTB = &apisv3.ClusterRoleTemplateBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "user1-read", + Namespace: "namespace2", + }, + UserName: "user1", + RoleTemplateName: c.readRT.Name, + } + c.user1InvalidNS2CRTB = &apisv3.ClusterRoleTemplateBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "user1-invalid", + Namespace: "namespace2", + }, + UserName: "user1", + RoleTemplateName: invalidName, + } + c.user2WriteCRTB = &apisv3.ClusterRoleTemplateBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "user2-write", + Namespace: "namespace1", + }, + UserName: "user2", + RoleTemplateName: c.writeRT.Name, + } + c.user2ReadCRTB = &apisv3.ClusterRoleTemplateBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "user2-read", + Namespace: "namespace1", + }, + UserName: "user2", + RoleTemplateName: c.readRT.Name, + } + +} + +func (c *CRTBResolverSuite) TestCRTBRuleResolver() { + resolver := c.NewTestCRTBResolver() + tests := []struct { + name string + user user.Info + namespace string + wantRules Rules + wantErr bool + }{ + // user with one CRTB in the namespace + { + name: "single CRTB rules", + user: NewUserInfo(c.user1AdminCRTB.UserName), + namespace: c.user1AdminCRTB.Namespace, + wantRules: c.adminRT.Rules, + }, + // user that belongs to no CRTBs no rules + { + name: "user with no rules", + user: NewUserInfo("invalidUser"), + namespace: c.user1AdminCRTB.Namespace, + wantRules: nil, + }, + // users with CRTB in different namespace no rules + { + name: "user with no rules in namespace", + user: NewUserInfo(c.user2WriteCRTB.UserName), + namespace: c.user1AReadNS2CRTB.Namespace, + wantRules: nil, + }, + // user with two CRTB + { + name: "user with multiple CRTB", + user: NewUserInfo(c.user2ReadCRTB.UserName), + namespace: c.user2ReadCRTB.Namespace, + wantRules: append(c.readRT.Rules, c.writeRT.Rules...), + }, + // users with one valid and one invalid CRTB partial rules + { + name: "partial rules", + user: NewUserInfo(c.user1InvalidNS2CRTB.UserName), + namespace: c.user1InvalidNS2CRTB.Namespace, + wantRules: c.readRT.Rules, + wantErr: true, + }, + } + for _, tt := range tests { + c.Run(tt.name, func() { + gotRules, err := resolver.RulesFor(tt.user, tt.namespace) + if tt.wantErr { + c.Errorf(err, "CRTBRuleResolver.RulesFor() error = %v, wantErr %v", err, tt.wantErr) + // still check result because function is suppose to return partial results. + + if !tt.wantRules.Equal(gotRules) { + c.Fail("List of rules did not match", "wanted=%+v got=%+v", tt.wantRules, gotRules) + } + return + } + c.NoError(err, "unexpected error") + if !tt.wantRules.Equal(gotRules) { + c.Fail("List of rules did not match", "wanted=%+v got=%+v", tt.wantRules, gotRules) + } + }) + } +} +func (c *CRTBResolverSuite) NewTestCRTBResolver() *resolvers.CRTBRuleResolver { + ctrl := gomock.NewController(c.T()) + bindings := []*apisv3.ClusterRoleTemplateBinding{c.user1AdminCRTB, c.user1AReadNS2CRTB, c.user1InvalidNS2CRTB, c.user2WriteCRTB, c.user2ReadCRTB} + crtbCache := NewCRTBCache(ctrl, bindings) + clusterRoleCache := fakes.NewMockClusterRoleCache(ctrl) + roleTemplateCache := fakes.NewMockRoleTemplateCache(ctrl) + roleTemplateCache.EXPECT().Get(c.adminRT.Name).Return(c.adminRT, nil).AnyTimes() + roleTemplateCache.EXPECT().Get(c.readRT.Name).Return(c.readRT, nil).AnyTimes() + roleTemplateCache.EXPECT().Get(c.writeRT.Name).Return(c.writeRT, nil).AnyTimes() + roleTemplateCache.EXPECT().Get(invalidName).Return(nil, errNotFound).AnyTimes() + roleResolver := auth.NewRoleTemplateResolver(roleTemplateCache, clusterRoleCache) + return resolvers.NewCRTBRuleResolver(crtbCache, roleResolver) +} + +func NewCRTBCache(ctrl *gomock.Controller, bindings []*apisv3.ClusterRoleTemplateBinding) v3.ClusterRoleTemplateBindingCache { + clusterCache := fakes.NewMockClusterRoleTemplateBindingCache(ctrl) + + clusterCache.EXPECT().Get(gomock.Any(), gomock.Any()).DoAndReturn(func(namespace, name string) (*apisv3.ClusterRoleTemplateBinding, error) { + for _, binding := range bindings { + if binding.Namespace == namespace && binding.Name == name { + return binding, nil + } + } + return nil, errNotFound + }).AnyTimes() + + clusterCache.EXPECT().List(gomock.Any(), gomock.Any()).DoAndReturn(func(namespace string, _ interface{}) ([]*apisv3.ClusterRoleTemplateBinding, error) { + retList := []*apisv3.ClusterRoleTemplateBinding{} + for _, binding := range bindings { + if binding.Namespace == namespace { + retList = append(retList, binding) + } + } + return retList, nil + }).AnyTimes() + + return clusterCache +} diff --git a/pkg/resolvers/prtbResolver_test.go b/pkg/resolvers/prtbResolver_test.go new file mode 100644 index 000000000..4ad6a1ca0 --- /dev/null +++ b/pkg/resolvers/prtbResolver_test.go @@ -0,0 +1,229 @@ +package resolvers_test + +import ( + "testing" + + "github.com/golang/mock/gomock" + apisv3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" + "github.com/rancher/webhook/pkg/auth" + "github.com/rancher/webhook/pkg/fakes" + v3 "github.com/rancher/webhook/pkg/generated/controllers/management.cattle.io/v3" + "github.com/rancher/webhook/pkg/resolvers" + "github.com/stretchr/testify/suite" + rbacv1 "k8s.io/api/rbac/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apiserver/pkg/authentication/user" +) + +type PRTBResolverSuite struct { + suite.Suite + adminRT *apisv3.RoleTemplate + readRT *apisv3.RoleTemplate + writeRT *apisv3.RoleTemplate + user1AdminPRTB *apisv3.ProjectRoleTemplateBinding + user1AReadNS2PRTB *apisv3.ProjectRoleTemplateBinding + user1InvalidNS2PRTB *apisv3.ProjectRoleTemplateBinding + user2WritePRTB *apisv3.ProjectRoleTemplateBinding + user2ReadPRTB *apisv3.ProjectRoleTemplateBinding +} + +func TestPRTBResolver(t *testing.T) { + t.Parallel() + suite.Run(t, new(PRTBResolverSuite)) +} + +func (p *PRTBResolverSuite) SetupSuite() { + ruleReadPods := rbacv1.PolicyRule{ + Verbs: []string{"GET", "WATCH"}, + APIGroups: []string{"v1"}, + Resources: []string{"pods"}, + } + ruleReadServices := rbacv1.PolicyRule{ + Verbs: []string{"GET", "WATCH"}, + APIGroups: []string{"v1"}, + Resources: []string{"services"}, + } + ruleWriteNodes := rbacv1.PolicyRule{ + Verbs: []string{"PUT", "CREATE", "UPDATE"}, + APIGroups: []string{"v1"}, + Resources: []string{"nodes"}, + } + ruleAdmin := rbacv1.PolicyRule{ + Verbs: []string{"*"}, + APIGroups: []string{"*"}, + Resources: []string{"*"}, + } + p.readRT = &apisv3.RoleTemplate{ + ObjectMeta: metav1.ObjectMeta{ + Name: "read-role", + }, + DisplayName: "Read Role", + Rules: []rbacv1.PolicyRule{ruleReadPods, ruleReadServices}, + Context: "project", + } + p.adminRT = &apisv3.RoleTemplate{ + ObjectMeta: metav1.ObjectMeta{ + Name: "admin-role", + }, + DisplayName: "Admin Role", + Rules: []rbacv1.PolicyRule{ruleAdmin}, + Builtin: true, + Administrative: true, + Context: "project", + } + p.writeRT = &apisv3.RoleTemplate{ + ObjectMeta: metav1.ObjectMeta{ + Name: "locked-role", + }, + DisplayName: "Locked Role", + Rules: []rbacv1.PolicyRule{ruleWriteNodes}, + Locked: true, + Context: "project", + } + p.user1AdminPRTB = &apisv3.ProjectRoleTemplateBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "user1-admin", + Namespace: "namespace1", + }, + UserName: "user1", + RoleTemplateName: p.adminRT.Name, + } + p.user1AReadNS2PRTB = &apisv3.ProjectRoleTemplateBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "user1-read", + Namespace: "namespace2", + }, + UserName: "user1", + RoleTemplateName: p.readRT.Name, + } + p.user1InvalidNS2PRTB = &apisv3.ProjectRoleTemplateBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "user1-invalid", + Namespace: "namespace2", + }, + UserName: "user1", + RoleTemplateName: invalidName, + } + p.user2WritePRTB = &apisv3.ProjectRoleTemplateBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "user2-write", + Namespace: "namespace1", + }, + UserName: "user2", + RoleTemplateName: p.writeRT.Name, + } + p.user2ReadPRTB = &apisv3.ProjectRoleTemplateBinding{ + ObjectMeta: metav1.ObjectMeta{ + Name: "user2-read", + Namespace: "namespace1", + }, + UserName: "user2", + RoleTemplateName: p.readRT.Name, + } +} + +func (p *PRTBResolverSuite) TestPRTBRuleResolver() { + resolver := p.NewTestPRTBResolver() + + tests := []struct { + name string + user user.Info + namespace string + wantRules Rules + wantErr bool + }{ + // user with one PRTB in the namespace + { + name: "single PRTB rules", + user: NewUserInfo(p.user1AdminPRTB.UserName), + namespace: p.user1AdminPRTB.Namespace, + wantRules: p.adminRT.Rules, + }, + // user that belongs to no PRTBs no rules + { + name: "user with no rules", + user: NewUserInfo("invalidUser"), + namespace: p.user1AdminPRTB.Namespace, + wantRules: nil, + }, + // users with PRTB in different namespace no rules + { + name: "user with no rules in namespace", + user: NewUserInfo(p.user2WritePRTB.UserName), + namespace: p.user1AReadNS2PRTB.Namespace, + wantRules: nil, + }, + // user with two PRTB + { + name: "user with multiple PRTB", + user: NewUserInfo(p.user2ReadPRTB.UserName), + namespace: p.user2ReadPRTB.Namespace, + wantRules: append(p.readRT.Rules, p.writeRT.Rules...), + }, + // users with one valid and one invalid PRTB partial rules + { + name: "partial rules", + user: NewUserInfo(p.user1InvalidNS2PRTB.UserName), + namespace: p.user1InvalidNS2PRTB.Namespace, + wantRules: p.readRT.Rules, + wantErr: true, + }, + } + for _, tt := range tests { + p.Run(tt.name, func() { + gotRules, err := resolver.RulesFor(tt.user, tt.namespace) + if tt.wantErr { + p.Errorf(err, "PRTBRuleResolver.RulesFor() error = %v, wantErr %v", err, tt.wantErr) + // still check result because function is suppose to return partial results. + + if !tt.wantRules.Equal(gotRules) { + p.Fail("List of rules did not match", "wanted=%+v got=%+v", tt.wantRules, gotRules) + } + return + } + p.NoError(err, "unexpected error") + if !tt.wantRules.Equal(gotRules) { + p.Fail("List of rules did not match", "wanted=%+v got=%+v", tt.wantRules, gotRules) + } + }) + } +} + +func (p *PRTBResolverSuite) NewTestPRTBResolver() *resolvers.PRTBRuleResolver { + ctrl := gomock.NewController(p.T()) + bindings := []*apisv3.ProjectRoleTemplateBinding{p.user1AdminPRTB, p.user1AReadNS2PRTB, p.user1InvalidNS2PRTB, p.user2WritePRTB, p.user2ReadPRTB} + PRTBCache := NewPRTBCache(ctrl, bindings) + clusterRoleCache := fakes.NewMockClusterRoleCache(ctrl) + roleTemplateCache := fakes.NewMockRoleTemplateCache(ctrl) + roleTemplateCache.EXPECT().Get(p.adminRT.Name).Return(p.adminRT, nil).AnyTimes() + roleTemplateCache.EXPECT().Get(p.readRT.Name).Return(p.readRT, nil).AnyTimes() + roleTemplateCache.EXPECT().Get(p.writeRT.Name).Return(p.writeRT, nil).AnyTimes() + roleTemplateCache.EXPECT().Get(invalidName).Return(nil, errNotFound).AnyTimes() + roleResolver := auth.NewRoleTemplateResolver(roleTemplateCache, clusterRoleCache) + return resolvers.NewPRTBRuleResolver(PRTBCache, roleResolver) +} + +func NewPRTBCache(ctrl *gomock.Controller, bindings []*apisv3.ProjectRoleTemplateBinding) v3.ProjectRoleTemplateBindingCache { + projectCache := fakes.NewMockProjectRoleTemplateBindingCache(ctrl) + + projectCache.EXPECT().Get(gomock.Any(), gomock.Any()).DoAndReturn(func(namespace, name string) (*apisv3.ProjectRoleTemplateBinding, error) { + for _, binding := range bindings { + if binding.Namespace == namespace && binding.Name == name { + return binding, nil + } + } + return nil, errNotFound + }).AnyTimes() + + projectCache.EXPECT().List(gomock.Any(), gomock.Any()).DoAndReturn(func(namespace string, _ interface{}) ([]*apisv3.ProjectRoleTemplateBinding, error) { + retList := []*apisv3.ProjectRoleTemplateBinding{} + for _, binding := range bindings { + if binding.Namespace == namespace { + retList = append(retList, binding) + } + } + return retList, nil + }).AnyTimes() + + return projectCache +} diff --git a/pkg/resolvers/resolver_test.go b/pkg/resolvers/resolver_test.go deleted file mode 100644 index e9c1b65f5..000000000 --- a/pkg/resolvers/resolver_test.go +++ /dev/null @@ -1,3 +0,0 @@ -package resolvers - -// TODO scrap request for test cases diff --git a/pkg/resolvers/resolvers_test.go b/pkg/resolvers/resolvers_test.go new file mode 100644 index 000000000..5061ad02a --- /dev/null +++ b/pkg/resolvers/resolvers_test.go @@ -0,0 +1,53 @@ +package resolvers_test + +import ( + "encoding/json" + "errors" + "reflect" + "sort" + + rbacv1 "k8s.io/api/rbac/v1" + "k8s.io/apiserver/pkg/authentication/user" +) + +var errNotFound = errors.New("notFound") + +const invalidName = "invalidName" + +type Rules []rbacv1.PolicyRule + +func (r Rules) Len() int { return len(r) } +func (r Rules) Swap(i, j int) { r[i], r[j] = r[j], r[i] } +func (r Rules) Less(i, j int) bool { + iData, _ := json.Marshal(r[i]) + jData, _ := json.Marshal(r[j]) + return string(iData) < string(jData) +} + +// Equal check if to list of policy rules are equal ignoring rule order, but not duplicates. +func (r Rules) Equal(r2 Rules) bool { + if (r == nil || r.Len() == 0) && (r2 == nil || r2.Len() == 0) { + return true + } + if r == nil || r2 == nil { + return false + } + if r.Len() != r2.Len() { + return false + } + // sort the list since we don't care about rule order + sort.Stable(r) + sort.Stable(r2) + + for i := range r { + if !reflect.DeepEqual(r[i], r2[i]) { + return false + } + } + return true +} +func NewUserInfo(username string) *user.DefaultInfo { + return &user.DefaultInfo{ + Name: username, + } +} diff --git a/pkg/resources/validation/clusterroletemplatebinding/clusterrtb_test.go b/pkg/resources/validation/clusterroletemplatebinding/clusterrtb_test.go index 08a80ada9..70f278b24 100644 --- a/pkg/resources/validation/clusterroletemplatebinding/clusterrtb_test.go +++ b/pkg/resources/validation/clusterroletemplatebinding/clusterrtb_test.go @@ -16,12 +16,9 @@ import ( "github.com/stretchr/testify/suite" v1 "k8s.io/api/admission/v1" v1authentication "k8s.io/api/authentication/v1" - k8authrizationv1 "k8s.io/api/authorization/v1" rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - k8fake "k8s.io/client-go/kubernetes/typed/authorization/v1/fake" - k8testing "k8s.io/client-go/testing" "k8s.io/kubernetes/pkg/registry/rbac/validation" ) @@ -110,7 +107,7 @@ func (c *ClusterRoleTemplateBindingSuite) Test_PrivilegeEscalation() { const adminUser = "admin-userid" const testUser = "test-userid" const errorUser = "error-userid" - const escalateUser = "escalate-userid" + const crtbUser = "escalate-userid" roles := []*rbacv1.Role{c.readServiceRole} clusterRoles := []*rbacv1.ClusterRole{c.adminCR, c.writeNodeCR} roleBindings := []*rbacv1.RoleBinding{ @@ -133,30 +130,20 @@ func (c *ClusterRoleTemplateBindingSuite) Test_PrivilegeEscalation() { } resolver, _ := validation.NewTestRuleResolver(roles, roleBindings, clusterRoles, clusterRoleBindings) - k8Fake := &k8testing.Fake{} - fakeSAR := &k8fake.FakeSubjectAccessReviews{Fake: &k8fake.FakeAuthorizationV1{Fake: k8Fake}} - k8Fake.AddReactor("create", "subjectaccessreviews", func(action k8testing.Action) (handled bool, ret runtime.Object, err error) { - createAction := action.(k8testing.CreateActionImpl) - review := createAction.GetObject().(*k8authrizationv1.SubjectAccessReview) - if review.Spec.User == errorUser { - return true, nil, errExpected - } - if review.Spec.User == escalateUser { - review.Status.Allowed = true - } - - return true, review, nil - }) - ctrl := gomock.NewController(c.T()) roleTemplateCache := fakes.NewMockRoleTemplateCache(ctrl) roleTemplateCache.EXPECT().Get(c.adminRT.Name).Return(c.adminRT, nil).AnyTimes() clusterRoleCache := fakes.NewMockClusterRoleCache(ctrl) roleResolver := auth.NewRoleTemplateResolver(roleTemplateCache, clusterRoleCache) - - validator := clusterroletemplatebinding.NewValidator(resolver, + crtbCache := fakes.NewMockClusterRoleTemplateBindingCache(ctrl) + crtbCache.EXPECT().List(newDefaultCRTB().ClusterName, gomock.Any()).Return([]*apisv3.ClusterRoleTemplateBinding{ + { + UserName: crtbUser, + RoleTemplateName: c.adminRT.Name, + }, + }, nil).AnyTimes() + validator := clusterroletemplatebinding.NewValidator(crtbCache, resolver, roleResolver, - fakeSAR, ) type args struct { oldCRTB func() *apisv3.ClusterRoleTemplateBinding @@ -185,11 +172,11 @@ func (c *ClusterRoleTemplateBindingSuite) Test_PrivilegeEscalation() { allowed: true, }, - // Users escalating privileges with the escalate verb {PASS}. + // Users privileges evaluated via CRTB {PASS}. { - name: "escalate verb test", + name: "crtb check test", args: args{ - username: escalateUser, + username: crtbUser, newCRTB: func() *apisv3.ClusterRoleTemplateBinding { baseCRTB := newDefaultCRTB() baseCRTB.UserName = testUser @@ -208,7 +195,7 @@ func (c *ClusterRoleTemplateBindingSuite) Test_PrivilegeEscalation() { username: testUser, newCRTB: func() *apisv3.ClusterRoleTemplateBinding { baseCRTB := newDefaultCRTB() - baseCRTB.UserName = escalateUser + baseCRTB.UserName = crtbUser baseCRTB.RoleTemplateName = c.adminRT.Name return baseCRTB }, @@ -253,7 +240,6 @@ func (c *ClusterRoleTemplateBindingSuite) Test_PrivilegeEscalation() { for i := range tests { test := tests[i] c.Run(test.name, func() { - c.T().Parallel() resp, req := createCRTBRequestAndResponse(c.T(), test.args.oldCRTB(), test.args.newCRTB(), test.args.username) err := validator.Admit(resp, req) c.NoError(err, "Admit failed") @@ -282,19 +268,17 @@ func (c *ClusterRoleTemplateBindingSuite) Test_UpdateValidation() { } resolver, _ := validation.NewTestRuleResolver(nil, nil, clusterRoles, clusterRoleBindings) - k8Fake := &k8testing.Fake{} - fakeSAR := &k8fake.FakeSubjectAccessReviews{Fake: &k8fake.FakeAuthorizationV1{Fake: k8Fake}} - ctrl := gomock.NewController(c.T()) roleTemplateCache := fakes.NewMockRoleTemplateCache(ctrl) roleTemplateCache.EXPECT().Get(c.adminRT.Name).Return(c.adminRT, nil).AnyTimes() roleTemplateCache.EXPECT().List(gomock.Any()).Return([]*apisv3.RoleTemplate{c.adminRT}, nil).AnyTimes() clusterRoleCache := fakes.NewMockClusterRoleCache(ctrl) roleResolver := auth.NewRoleTemplateResolver(roleTemplateCache, clusterRoleCache) + crtbCache := fakes.NewMockClusterRoleTemplateBindingCache(ctrl) + crtbCache.EXPECT().List(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() - validator := clusterroletemplatebinding.NewValidator(resolver, + validator := clusterroletemplatebinding.NewValidator(crtbCache, resolver, roleResolver, - fakeSAR, ) type args struct { oldCRTB func() *apisv3.ClusterRoleTemplateBinding @@ -580,9 +564,6 @@ func (c *ClusterRoleTemplateBindingSuite) Test_Create() { } resolver, _ := validation.NewTestRuleResolver(nil, nil, clusterRoles, clusterRoleBindings) - k8Fake := &k8testing.Fake{} - fakeSAR := &k8fake.FakeSubjectAccessReviews{Fake: &k8fake.FakeAuthorizationV1{Fake: k8Fake}} - ctrl := gomock.NewController(c.T()) roleTemplateCache := fakes.NewMockRoleTemplateCache(ctrl) roleTemplateCache.EXPECT().Get(c.adminRT.Name).Return(c.adminRT, nil).AnyTimes() @@ -591,10 +572,11 @@ func (c *ClusterRoleTemplateBindingSuite) Test_Create() { roleTemplateCache.EXPECT().Get("").Return(nil, errExpected).AnyTimes() clusterRoleCache := fakes.NewMockClusterRoleCache(ctrl) roleResolver := auth.NewRoleTemplateResolver(roleTemplateCache, clusterRoleCache) + crtbCache := fakes.NewMockClusterRoleTemplateBindingCache(ctrl) + crtbCache.EXPECT().List(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() - validator := clusterroletemplatebinding.NewValidator(resolver, + validator := clusterroletemplatebinding.NewValidator(crtbCache, resolver, roleResolver, - fakeSAR, ) type args struct { oldCRTB func() *apisv3.ClusterRoleTemplateBinding diff --git a/pkg/resources/validation/projectroletemplatebinding/projectrtb_test.go b/pkg/resources/validation/projectroletemplatebinding/projectrtb_test.go index 408eb425a..17fc7752a 100644 --- a/pkg/resources/validation/projectroletemplatebinding/projectrtb_test.go +++ b/pkg/resources/validation/projectroletemplatebinding/projectrtb_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "testing" "github.com/golang/mock/gomock" @@ -16,17 +17,19 @@ import ( "github.com/stretchr/testify/suite" v1 "k8s.io/api/admission/v1" v1authentication "k8s.io/api/authentication/v1" - k8authrizationv1 "k8s.io/api/authorization/v1" rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - k8fake "k8s.io/client-go/kubernetes/typed/authorization/v1/fake" - k8testing "k8s.io/client-go/testing" "k8s.io/kubernetes/pkg/registry/rbac/validation" ) var errExpected = errors.New("expected test error") +const ( + clusterID = "cluster-id" + projectID = "project-id" +) + type ProjectRoleTemplateBindingSuite struct { suite.Suite adminRT *apisv3.RoleTemplate @@ -110,7 +113,8 @@ func (p *ProjectRoleTemplateBindingSuite) Test_PrivilegeEscalation() { const adminUser = "admin-userid" const testUser = "test-userid" const errorUser = "error-userid" - const escalateUser = "escalate-userid" + const prtbUser = "prtb-userid" + const crtbUser = "crtb-userid" roles := []*rbacv1.Role{p.readServiceRole} clusterRoles := []*rbacv1.ClusterRole{p.adminCR, p.writeNodeCR} roleBindings := []*rbacv1.RoleBinding{ @@ -133,30 +137,27 @@ func (p *ProjectRoleTemplateBindingSuite) Test_PrivilegeEscalation() { } resolver, _ := validation.NewTestRuleResolver(roles, roleBindings, clusterRoles, clusterRoleBindings) - k8Fake := &k8testing.Fake{} - fakeSAR := &k8fake.FakeSubjectAccessReviews{Fake: &k8fake.FakeAuthorizationV1{Fake: k8Fake}} - k8Fake.AddReactor("create", "subjectaccessreviews", func(action k8testing.Action) (handled bool, ret runtime.Object, err error) { - createAction := action.(k8testing.CreateActionImpl) - review := createAction.GetObject().(*k8authrizationv1.SubjectAccessReview) - if review.Spec.User == errorUser { - return true, nil, errExpected - } - if review.Spec.User == escalateUser { - review.Status.Allowed = true - } - - return true, review, nil - }) - ctrl := gomock.NewController(p.T()) roleTemplateCache := fakes.NewMockRoleTemplateCache(ctrl) roleTemplateCache.EXPECT().Get(p.adminRT.Name).Return(p.adminRT, nil).AnyTimes() clusterRoleCache := fakes.NewMockClusterRoleCache(ctrl) roleResolver := auth.NewRoleTemplateResolver(roleTemplateCache, clusterRoleCache) - - validator := projectroletemplatebinding.NewValidator(resolver, + prtbCache := fakes.NewMockProjectRoleTemplateBindingCache(ctrl) + prtbCache.EXPECT().List(projectID, gomock.Any()).Return([]*apisv3.ProjectRoleTemplateBinding{ + { + UserName: prtbUser, + RoleTemplateName: p.adminRT.Name, + }, + }, nil).AnyTimes() + crtbCache := fakes.NewMockClusterRoleTemplateBindingCache(ctrl) + crtbCache.EXPECT().List(clusterID, gomock.Any()).Return([]*apisv3.ClusterRoleTemplateBinding{ + { + UserName: crtbUser, + RoleTemplateName: p.adminRT.Name, + }, + }, nil).AnyTimes() + validator := projectroletemplatebinding.NewValidator(prtbCache, crtbCache, resolver, roleResolver, - fakeSAR, ) type args struct { oldPRTB func() *apisv3.ProjectRoleTemplateBinding @@ -185,11 +186,27 @@ func (p *ProjectRoleTemplateBindingSuite) Test_PrivilegeEscalation() { allowed: true, }, - // Users escalating privileges with the escalate verb {PASS}. + // Users privileges are stored in a crtb {PASS}. { - name: "escalate verb test", + name: "CRTB resolver test", args: args{ - username: escalateUser, + username: crtbUser, + newPRTB: func() *apisv3.ProjectRoleTemplateBinding { + basePRTB := newBasePRTB() + basePRTB.UserName = testUser + basePRTB.RoleTemplateName = p.adminRT.Name + return basePRTB + }, + oldPRTB: func() *apisv3.ProjectRoleTemplateBinding { return nil }, + }, + allowed: true, + }, + + // Users privileges are stored in a crtb {PASS}. + { + name: "PRTB resolver test", + args: args{ + username: prtbUser, newPRTB: func() *apisv3.ProjectRoleTemplateBinding { basePRTB := newBasePRTB() basePRTB.UserName = testUser @@ -208,7 +225,7 @@ func (p *ProjectRoleTemplateBindingSuite) Test_PrivilegeEscalation() { username: testUser, newPRTB: func() *apisv3.ProjectRoleTemplateBinding { basePRTB := newBasePRTB() - basePRTB.UserName = escalateUser + basePRTB.UserName = errorUser basePRTB.RoleTemplateName = p.adminRT.Name return basePRTB }, @@ -282,20 +299,17 @@ func (p *ProjectRoleTemplateBindingSuite) Test_UpdateValidation() { } resolver, _ := validation.NewTestRuleResolver(nil, nil, clusterRoles, clusterRoleBindings) - k8Fake := &k8testing.Fake{} - fakeSAR := &k8fake.FakeSubjectAccessReviews{Fake: &k8fake.FakeAuthorizationV1{Fake: k8Fake}} - ctrl := gomock.NewController(p.T()) roleTemplateCache := fakes.NewMockRoleTemplateCache(ctrl) roleTemplateCache.EXPECT().Get(p.adminRT.Name).Return(p.adminRT, nil).AnyTimes() roleTemplateCache.EXPECT().List(gomock.Any()).Return([]*apisv3.RoleTemplate{p.adminRT}, nil).AnyTimes() clusterRoleCache := fakes.NewMockClusterRoleCache(ctrl) roleResolver := auth.NewRoleTemplateResolver(roleTemplateCache, clusterRoleCache) - - validator := projectroletemplatebinding.NewValidator(resolver, - roleResolver, - fakeSAR, - ) + prtbCache := fakes.NewMockProjectRoleTemplateBindingCache(ctrl) + prtbCache.EXPECT().List(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + crtbCache := fakes.NewMockClusterRoleTemplateBindingCache(ctrl) + crtbCache.EXPECT().List(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + validator := projectroletemplatebinding.NewValidator(prtbCache, crtbCache, resolver, roleResolver) type args struct { oldPRTB func() *apisv3.ProjectRoleTemplateBinding newPRTB func() *apisv3.ProjectRoleTemplateBinding @@ -562,9 +576,6 @@ func (p *ProjectRoleTemplateBindingSuite) Test_Create() { } resolver, _ := validation.NewTestRuleResolver(nil, nil, clusterRoles, clusterRoleBindings) - k8Fake := &k8testing.Fake{} - fakeSAR := &k8fake.FakeSubjectAccessReviews{Fake: &k8fake.FakeAuthorizationV1{Fake: k8Fake}} - ctrl := gomock.NewController(p.T()) roleTemplateCache := fakes.NewMockRoleTemplateCache(ctrl) roleTemplateCache.EXPECT().Get(p.adminRT.Name).Return(p.adminRT, nil).AnyTimes() @@ -573,11 +584,12 @@ func (p *ProjectRoleTemplateBindingSuite) Test_Create() { roleTemplateCache.EXPECT().Get("").Return(nil, errExpected).AnyTimes() clusterRoleCache := fakes.NewMockClusterRoleCache(ctrl) roleResolver := auth.NewRoleTemplateResolver(roleTemplateCache, clusterRoleCache) + prtbCache := fakes.NewMockProjectRoleTemplateBindingCache(ctrl) + prtbCache.EXPECT().List(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + crtbCache := fakes.NewMockClusterRoleTemplateBindingCache(ctrl) + crtbCache.EXPECT().List(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() + validator := projectroletemplatebinding.NewValidator(prtbCache, crtbCache, resolver, roleResolver) - validator := projectroletemplatebinding.NewValidator(resolver, - roleResolver, - fakeSAR, - ) type args struct { oldPRTB func() *apisv3.ProjectRoleTemplateBinding newPRTB func() *apisv3.ProjectRoleTemplateBinding @@ -741,8 +753,8 @@ func newBasePRTB() *apisv3.ProjectRoleTemplateBinding { return &apisv3.ProjectRoleTemplateBinding{ TypeMeta: metav1.TypeMeta{Kind: "ProjectRoleTemplateBinding", APIVersion: "management.cattle.io/v3"}, ObjectMeta: metav1.ObjectMeta{ - Name: "crtb-new", - GenerateName: "crtb-", + Name: "PRTB-new", + GenerateName: "PRTB-", Namespace: "p-namespace", SelfLink: "", UID: "6534e4ef-f07b-4c61-b88d-95a92cce4852", @@ -753,5 +765,6 @@ func newBasePRTB() *apisv3.ProjectRoleTemplateBinding { }, UserName: "user1", RoleTemplateName: "admin-role", + ProjectName: fmt.Sprintf("%s:%s", clusterID, projectID), } }