Skip to content

Commit

Permalink
fix(auth): compatible with version 1.18 lister function declaration m…
Browse files Browse the repository at this point in the history
…odification
  • Loading branch information
choujimmy committed May 13, 2020
1 parent a3c4dc4 commit 86219f4
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 5 deletions.
7 changes: 4 additions & 3 deletions pkg/auth/controller/group/group_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"

"tkestack.io/tke/api/auth"
v1 "tkestack.io/tke/api/auth/v1"
clientset "tkestack.io/tke/api/client/clientset/versioned"
authv1informer "tkestack.io/tke/api/client/informers/externalversions/auth/v1"
Expand Down Expand Up @@ -315,10 +314,12 @@ func (c *Controller) resyncGroups(ctx context.Context) {
for _, idp := range idpList.Items {
tenantSelector := fields.AndSelectors(
fields.OneTermEqualSelector("spec.tenantID", idp.Name),
fields.OneTermEqualSelector(auth.LimitQueryTag, "0"),
)

groups, err := c.client.AuthV1().Groups().List(ctx, metav1.ListOptions{FieldSelector: tenantSelector.String()})
groups, err := c.client.AuthV1().Groups().List(ctx, metav1.ListOptions{
FieldSelector: tenantSelector.String(),
Limit: 0,
})
if err != nil {
log.Error("List groups for tenant failed", log.String("tenant", idp.Name), log.Err(err))
continue
Expand Down
7 changes: 7 additions & 0 deletions pkg/auth/registry/apikey/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ type REST struct {
}

var _ rest.ShortNamesProvider = &REST{}
var _ rest.Lister = &REST{}
var _ rest.Updater = &REST{}
var _ rest.Getter = &REST{}
var _ rest.CollectionDeleter = &REST{}
var _ rest.Exporter = &REST{}
var _ rest.GracefulDeleter = &REST{}
var _ rest.Scoper = &REST{}

// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
Expand Down
11 changes: 11 additions & 0 deletions pkg/auth/registry/client/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func (r *REST) NamespaceScoped() bool {
var _ rest.ShortNamesProvider = &REST{}
var _ rest.Creater = &REST{}
var _ rest.Scoper = &REST{}
var _ rest.Lister = &REST{}
var _ rest.GracefulDeleter = &REST{}
var _ rest.Getter = &REST{}

// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
Expand All @@ -73,6 +76,14 @@ func (r *REST) NewList() runtime.Object {
return &auth.ClientList{}
}

// ConvertToTable converts objects to metav1.Table objects using default table
// convertor.
func (r *REST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
// TODO: convert role list to table
tableConvertor := rest.NewDefaultTableConvertor(auth.Resource("clients"))
return tableConvertor.ConvertToTable(ctx, object, tableOptions)
}

// Create creates a new version of a resource.
func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
idp := obj.(*auth.Client)
Expand Down
2 changes: 2 additions & 0 deletions pkg/auth/registry/configmap/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package storage

import (
"context"

metainternal "k8s.io/apimachinery/pkg/apis/meta/internalversion"
"k8s.io/apimachinery/pkg/runtime"
genericregistry "k8s.io/apiserver/pkg/registry/generic"
Expand Down Expand Up @@ -69,6 +70,7 @@ type REST struct {
}

var _ rest.ShortNamesProvider = &REST{}
var _ rest.Lister = &REST{}

// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
Expand Down
9 changes: 9 additions & 0 deletions pkg/auth/registry/group/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (r *REST) NamespaceScoped() bool {
var _ rest.ShortNamesProvider = &REST{}
var _ rest.Creater = &REST{}
var _ rest.Scoper = &REST{}
var _ rest.Lister = &REST{}

// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
Expand All @@ -82,6 +83,14 @@ func (r *REST) NewList() runtime.Object {
return &auth.GroupList{}
}

// ConvertToTable converts objects to metav1.Table objects using default table
// convertor.
func (r *REST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
// TODO: convert role list to table
tableConvertor := rest.NewDefaultTableConvertor(auth.Resource("groups"))
return tableConvertor.ConvertToTable(ctx, object, tableOptions)
}

// Create creates a new version of a resource.
func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
return &auth.Group{}, nil
Expand Down
9 changes: 9 additions & 0 deletions pkg/auth/registry/localgroup/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ type REST struct {
privilegedUsername string
}

var _ rest.Creater = &REST{}
var _ rest.ShortNamesProvider = &REST{}
var _ rest.Lister = &REST{}
var _ rest.Getter = &REST{}
var _ rest.Updater = &REST{}
var _ rest.CollectionDeleter = &REST{}
var _ rest.GracefulDeleter = &REST{}
var _ rest.Exporter = &REST{}

// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
return []string{"grp"}
Expand Down
7 changes: 7 additions & 0 deletions pkg/auth/registry/localidentity/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ type REST struct {
}

var _ rest.ShortNamesProvider = &REST{}
var _ rest.Creater = &REST{}
var _ rest.Lister = &REST{}
var _ rest.Getter = &REST{}
var _ rest.Updater = &REST{}
var _ rest.CollectionDeleter = &REST{}
var _ rest.GracefulDeleter = &REST{}
var _ rest.Exporter = &REST{}

// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
Expand Down
12 changes: 12 additions & 0 deletions pkg/auth/registry/policy/storage/projectgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package storage
import (
"context"

"k8s.io/apiserver/pkg/registry/rest"

"tkestack.io/tke/pkg/apiserver/filter"
"tkestack.io/tke/pkg/auth/util"

Expand All @@ -43,6 +45,8 @@ type ProjectGroupREST struct {
authClient authinternalclient.AuthInterface
}

var _ rest.Lister = &ProjectGroupREST{}

// New returns an empty object that can be used with Create after request data
// has been put into it.
func (r *ProjectGroupREST) New() runtime.Object {
Expand All @@ -54,6 +58,14 @@ func (r *ProjectGroupREST) NewList() runtime.Object {
return &auth.GroupList{}
}

// ConvertToTable converts objects to metav1.Table objects using default table
// convertor.
func (r *ProjectGroupREST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
// TODO: convert role list to table
tableConvertor := rest.NewDefaultTableConvertor(auth.Resource("projectgroups"))
return tableConvertor.ConvertToTable(ctx, object, tableOptions)
}

// List selects resources in the storage which match to the selector. 'options' can be nil.
func (r *ProjectGroupREST) List(ctx context.Context, options *metainternal.ListOptions) (runtime.Object, error) {
requestInfo, ok := request.RequestInfoFrom(ctx)
Expand Down
12 changes: 12 additions & 0 deletions pkg/auth/registry/policy/storage/projectuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package storage
import (
"context"

"k8s.io/apiserver/pkg/registry/rest"

"tkestack.io/tke/pkg/apiserver/filter"
"tkestack.io/tke/pkg/auth/util"

Expand All @@ -43,6 +45,8 @@ type ProjectUserREST struct {
authClient authinternalclient.AuthInterface
}

var _ rest.Lister = &ProjectUserREST{}

// New returns an empty object that can be used with Create after request data
// has been put into it.
func (r *ProjectUserREST) New() runtime.Object {
Expand All @@ -54,6 +58,14 @@ func (r *ProjectUserREST) NewList() runtime.Object {
return &auth.UserList{}
}

// ConvertToTable converts objects to metav1.Table objects using default table
// convertor.
func (r *ProjectUserREST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
// TODO: convert role list to table
tableConvertor := rest.NewDefaultTableConvertor(auth.Resource("projectusers"))
return tableConvertor.ConvertToTable(ctx, object, tableOptions)
}

// List selects resources in the storage which match to the selector. 'options' can be nil.
func (r *ProjectUserREST) List(ctx context.Context, options *metainternal.ListOptions) (runtime.Object, error) {
requestInfo, ok := request.RequestInfoFrom(ctx)
Expand Down
9 changes: 9 additions & 0 deletions pkg/auth/registry/policy/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ type REST struct {
privilegedUsername string
}

var _ rest.Creater = &REST{}
var _ rest.ShortNamesProvider = &REST{}
var _ rest.Lister = &REST{}
var _ rest.Getter = &REST{}
var _ rest.Updater = &REST{}
var _ rest.CollectionDeleter = &REST{}
var _ rest.GracefulDeleter = &REST{}
var _ rest.Exporter = &REST{}

// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
return []string{"pol"}
Expand Down
11 changes: 11 additions & 0 deletions pkg/auth/registry/project/storage/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type GroupREST struct {
authClient authinternalclient.AuthInterface
}

var _ rest.Creater = &GroupREST{}
var _ rest.Lister = &GroupREST{}

// New returns an empty object that can be used with Create after request data
// has been put into it.
func (r *GroupREST) New() runtime.Object {
Expand All @@ -61,6 +64,14 @@ func (r *GroupREST) NewList() runtime.Object {
return &auth.GroupList{}
}

// ConvertToTable converts objects to metav1.Table objects using default table
// convertor.
func (r *GroupREST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
// TODO: convert role list to table
tableConvertor := rest.NewDefaultTableConvertor(auth.Resource("groups"))
return tableConvertor.ConvertToTable(ctx, object, tableOptions)
}

// List selects resources in the storage which match to the selector. 'options' can be nil.
func (r *GroupREST) List(ctx context.Context, options *metainternal.ListOptions) (runtime.Object, error) {
requestInfo, ok := request.RequestInfoFrom(ctx)
Expand Down
10 changes: 10 additions & 0 deletions pkg/auth/registry/project/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func (r *REST) NamespaceScoped() bool {
}

var _ rest.Scoper = &REST{}
var _ rest.Lister = &REST{}
var _ rest.Getter = &REST{}

// New returns an empty object that can be used with Create and Update after request data has been put into it.
func (r *REST) New() runtime.Object {
Expand All @@ -87,6 +89,14 @@ func (r *REST) NewList() runtime.Object {
return &auth.ProjectList{}
}

// ConvertToTable converts objects to metav1.Table objects using default table
// convertor.
func (r *REST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
// TODO: convert role list to table
tableConvertor := rest.NewDefaultTableConvertor(auth.Resource("projects"))
return tableConvertor.ConvertToTable(ctx, object, tableOptions)
}

// Get finds a resource in the storage by name and returns it.
func (r *REST) Get(ctx context.Context, projectName string, options *metav1.GetOptions) (runtime.Object, error) {
requestInfo, ok := request.RequestInfoFrom(ctx)
Expand Down
11 changes: 11 additions & 0 deletions pkg/auth/registry/project/storage/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type UserREST struct {
authClient authinternalclient.AuthInterface
}

var _ rest.Creater = &UserREST{}
var _ rest.Lister = &UserREST{}

// New returns an empty object that can be used with Create after request data
// has been put into it.
func (r *UserREST) New() runtime.Object {
Expand All @@ -62,6 +65,14 @@ func (r *UserREST) NewList() runtime.Object {
return &auth.UserList{}
}

// ConvertToTable converts objects to metav1.Table objects using default table
// convertor.
func (r *UserREST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
// TODO: convert role list to table
tableConvertor := rest.NewDefaultTableConvertor(auth.Resource("users"))
return tableConvertor.ConvertToTable(ctx, object, tableOptions)
}

// List selects resources in the storage which match to the selector. 'options' can be nil.
func (r *UserREST) List(ctx context.Context, options *metainternal.ListOptions) (runtime.Object, error) {
keyword := genericfilter.FuzzyResourceFrom(ctx)
Expand Down
9 changes: 9 additions & 0 deletions pkg/auth/registry/projectpolicybinding/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ type REST struct {
privilegedUsername string
}

var _ rest.Creater = &REST{}
var _ rest.ShortNamesProvider = &REST{}
var _ rest.Lister = &REST{}
var _ rest.Getter = &REST{}
var _ rest.Updater = &REST{}
var _ rest.CollectionDeleter = &REST{}
var _ rest.GracefulDeleter = &REST{}
var _ rest.Exporter = &REST{}

// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
return []string{"ppb"}
Expand Down
9 changes: 9 additions & 0 deletions pkg/auth/registry/role/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ type REST struct {
privilegedUsername string
}

var _ rest.Creater = &REST{}
var _ rest.ShortNamesProvider = &REST{}
var _ rest.Lister = &REST{}
var _ rest.Getter = &REST{}
var _ rest.Updater = &REST{}
var _ rest.CollectionDeleter = &REST{}
var _ rest.GracefulDeleter = &REST{}
var _ rest.Exporter = &REST{}

// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
return []string{"rol"}
Expand Down
10 changes: 10 additions & 0 deletions pkg/auth/registry/rule/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
apiserverutil "tkestack.io/tke/pkg/apiserver/util"

"tkestack.io/tke/api/auth"
Expand Down Expand Up @@ -69,6 +70,15 @@ type REST struct {
*registry.Store
}

var _ rest.Creater = &REST{}
var _ rest.ShortNamesProvider = &REST{}
var _ rest.Lister = &REST{}
var _ rest.Getter = &REST{}
var _ rest.Updater = &REST{}
var _ rest.CollectionDeleter = &REST{}
var _ rest.GracefulDeleter = &REST{}
var _ rest.Exporter = &REST{}

// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
return []string{"rul"}
Expand Down
13 changes: 11 additions & 2 deletions pkg/auth/registry/user/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ func (r *REST) NamespaceScoped() bool {
return false
}

var _ rest.ShortNamesProvider = &REST{}
var _ rest.Creater = &REST{}
var _ rest.Scoper = &REST{}
var _ rest.ShortNamesProvider = &REST{}
var _ rest.Lister = &REST{}
var _ rest.Getter = &REST{}

// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
Expand Down Expand Up @@ -115,6 +116,14 @@ func (r *REST) Get(ctx context.Context, name string, options *metav1.GetOptions)
return userLister.GetUser(ctx, name, options)
}

// ConvertToTable converts objects to metav1.Table objects using default table
// convertor.
func (r *REST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
// TODO: convert role list to table
tableConvertor := rest.NewDefaultTableConvertor(auth.Resource("users"))
return tableConvertor.ConvertToTable(ctx, object, tableOptions)
}

// List selects resources in the storage which match to the selector. 'options' can be nil.
func (r *REST) List(ctx context.Context, options *metainternal.ListOptions) (runtime.Object, error) {
_, tenantID := authentication.GetUsernameAndTenantID(ctx)
Expand Down

0 comments on commit 86219f4

Please sign in to comment.