Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xdonggao committed May 24, 2021
1 parent 9a46937 commit 1ae9a84
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
14 changes: 9 additions & 5 deletions pkg/platform/registry/clusterauthentications/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import (
"tkestack.io/tke/pkg/util/log"
)

// Storage includes storage for namespace set and all sub resources.
// Storage includes storage for clusterauthentication and all sub resources.
type Storage struct {
ClusterAuthentication *REST
}

// NewStorage returns a Storage object that will work against namespace sets.
func NewStorage(optsGetter genericregistry.RESTOptionsGetter, platformClient platforminternalclient.PlatformInterface, privilegedUsername string) *Storage {
func NewStorage(optsGetter genericregistry.RESTOptionsGetter, platformClient platforminternalclient.PlatformInterface) *Storage {
strategy := clusterauthentications.NewStrategy(platformClient)
store := &registry.Store{
NewFunc: func() runtime.Object { return &platform.ClusterAuthentication{} },
Expand All @@ -62,21 +62,20 @@ func NewStorage(optsGetter genericregistry.RESTOptionsGetter, platformClient pla
}

return &Storage{
ClusterAuthentication: &REST{store, privilegedUsername},
ClusterAuthentication: &REST{store},
}
}

// REST implements a RESTStorage for namespace sets against etcd.
type REST struct {
*registry.Store
privilegedUsername string
}

var _ rest.ShortNamesProvider = &REST{}

// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
return []string{"clsauth"}
return []string{"clusterauth"}
}

func (r *REST) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
Expand All @@ -93,6 +92,11 @@ func (r *REST) Get(ctx context.Context, name string, options *metav1.GetOptions)
return r.Store.Get(ctx, name, options)
}

// Export an object. Fields that are not user specified are stripped out
func (r *REST) Export(ctx context.Context, name string, options *metav1.ExportOptions) (runtime.Object, error) {
return r.Store.Export(ctx, name, *options)
}

// Update finds a resource in the storage and updates it.
func (r *REST) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
return r.Store.Update(ctx, name, objInfo, createValidation, updateValidation, false, options)
Expand Down
10 changes: 9 additions & 1 deletion pkg/platform/registry/clusterauthentications/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ func MatchClusterAuthentication(label labels.Selector, field fields.Selector) st
Field: field,
GetAttrs: GetAttrs,
IndexFields: []string{
"tenantID",
"clusterName",
"ownerUIN",
"subAccountUIN",
"authenticationInfo.commonName",
},
}
}
Expand All @@ -124,7 +128,11 @@ func MatchClusterAuthentication(label labels.Selector, field fields.Selector) st
func ToSelectableFields(clusterAuthentication *platform.ClusterAuthentication) fields.Set {
objectMetaFieldsSet := generic.ObjectMetaFieldsSet(&clusterAuthentication.ObjectMeta, false)
specificFieldsSet := fields.Set{
"clusterName": clusterAuthentication.ClusterName,
"tenantID": clusterAuthentication.TenantID,
"clusterName": clusterAuthentication.ClusterName,
"ownerUIN": clusterAuthentication.OwnerUIN,
"subAccountUIN": clusterAuthentication.SubAccountUIN,
"authenticationInfo.commonName": clusterAuthentication.AuthenticationInfo.CommonName,
}
return generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet)
}
2 changes: 1 addition & 1 deletion pkg/platform/registry/clusterauthentications/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var ValidateName = apiMachineryValidation.ValidateNamespaceName

// ValidateClusterAuthentication tests if required fields in the cluster are set.
func ValidateClusterAuthentication(clusterAuthentication *platform.ClusterAuthentication) field.ErrorList {
allErrs := apiMachineryValidation.ValidateObjectMeta(&clusterAuthentication.ObjectMeta, false, ValidateName, field.NewPath("metadata"))
allErrs := apiMachineryValidation.ValidateObjectMeta(&clusterAuthentication.ObjectMeta, true, ValidateName, field.NewPath("metadata"))

if len(clusterAuthentication.ClusterName) == 0 {
allErrs = append(allErrs, field.Required(field.NewPath("spec", "clusterName"), "must specify a cluster name"))
Expand Down
4 changes: 2 additions & 2 deletions pkg/platform/registry/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (
"tkestack.io/tke/pkg/apiserver/storage"
clusterstorage "tkestack.io/tke/pkg/platform/registry/cluster/storage"
clusteraddontypestorage "tkestack.io/tke/pkg/platform/registry/clusteraddontype/storage"
clusterAuthenticationstorage "tkestack.io/tke/pkg/platform/registry/clusterauthentications/storage"
clustercredentialstorage "tkestack.io/tke/pkg/platform/registry/clustercredential/storage"
configmapstorage "tkestack.io/tke/pkg/platform/registry/configmap/storage"
clusterAuthenticationstorage "tkestack.io/tke/pkg/platform/registry/clusterauthentications/storage"
cronhpastorage "tkestack.io/tke/pkg/platform/registry/cronhpa/storage"
csioperatorstorage "tkestack.io/tke/pkg/platform/registry/csioperator/storage"
helmstorage "tkestack.io/tke/pkg/platform/registry/helm/storage"
Expand Down Expand Up @@ -108,7 +108,7 @@ func (s *StorageProvider) v1Storage(apiResourceConfigSource serverstorage.APIRes
clusterCredentialREST := clustercredentialstorage.NewStorage(restOptionsGetter, platformClient, s.PrivilegedUsername)
storageMap["clustercredentials"] = clusterCredentialREST.ClusterCredential

clusterAuthenticationREST := clusterAuthenticationstorage.NewStorage(restOptionsGetter, platformClient, s.PrivilegedUsername)
clusterAuthenticationREST := clusterAuthenticationstorage.NewStorage(restOptionsGetter, platformClient)
storageMap["clusterauthentications"] = clusterAuthenticationREST.ClusterAuthentication

clusterAddonTypeREST := clusteraddontypestorage.NewStorage(restOptionsGetter)
Expand Down

0 comments on commit 1ae9a84

Please sign in to comment.