Skip to content

Commit

Permalink
fix(registry): update chart project args
Browse files Browse the repository at this point in the history
  • Loading branch information
jianzhuang authored and tke-robot committed Sep 25, 2020
1 parent e18a50d commit 3e853a0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
6 changes: 4 additions & 2 deletions api/registry/v1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ func AddFieldLabelConversionsForChartGroup(scheme *runtime.Scheme) error {
"spec.name",
"spec.type",
"spec.visibility",
"repoType", //custom label
"repoType", //custom label
"projectID", //custom label
"metadata.name":
return label, value, nil
default:
Expand All @@ -105,7 +106,8 @@ func AddFieldLabelConversionsForChart(scheme *runtime.Scheme) error {
case "spec.tenantID",
"spec.name",
"spec.chartGroupName",
"repoType", //custom label
"repoType", //custom label
"projectID", //custom label
"metadata.name":
return label, value, nil
default:
Expand Down
6 changes: 4 additions & 2 deletions pkg/registry/registry/chart/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,21 @@ func (r *REST) List(ctx context.Context, options *metainternal.ListOptions) (run
// repoType is custom label, which not exist in chart
repoType := ""
defaultType := "__internal"
targetProjectID := ""
wrappedOptions, repoType = apiserverutil.InterceptCustomSelectorFromListOptions(wrappedOptions, "repoType", defaultType)
wrappedOptions, targetProjectID = apiserverutil.InterceptCustomSelectorFromListOptions(options, "projectID", "")

switch registryapi.RepoType(repoType) {
case registryapi.RepoTypePersonal:
obj, err = registryutil.ListPersonalChartsFromStore(ctx, wrappedOptions, r.businessClient, r.registryClient, r.privilegedUsername, r.Store)
case registryapi.RepoTypeProject:
obj, err = registryutil.ListProjectChartsFromStore(ctx, wrappedOptions, r.businessClient, r.authClient, r.registryClient, r.privilegedUsername, r.Store)
obj, err = registryutil.ListProjectChartsFromStore(ctx, wrappedOptions, targetProjectID, r.businessClient, r.authClient, r.registryClient, r.privilegedUsername, r.Store)
case registryapi.RepoTypeSystem:
obj, err = registryutil.ListSystemChartsFromStore(ctx, wrappedOptions, r.businessClient, r.registryClient, r.privilegedUsername, r.Store)
case registryapi.RepoTypePublic:
obj, err = registryutil.ListPublicChartsFromStore(ctx, wrappedOptions, r.businessClient, r.registryClient, r.privilegedUsername, r.Store)
case registryapi.RepoTypeAll:
obj, err = registryutil.ListAllChartsFromStore(ctx, wrappedOptions, r.businessClient, r.authClient, r.registryClient, r.privilegedUsername, r.Store)
obj, err = registryutil.ListAllChartsFromStore(ctx, wrappedOptions, targetProjectID, r.businessClient, r.authClient, r.registryClient, r.privilegedUsername, r.Store)
case registryapi.RepoType(defaultType):
obj, err = r.Store.List(ctx, wrappedOptions)
default:
Expand Down
7 changes: 5 additions & 2 deletions pkg/registry/registry/chartgroup/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,21 @@ func (r *GenericREST) List(ctx context.Context, options *metainternal.ListOption
// repoType is custom label, which not exist in chartgroup
repoType := ""
defaultType := "__internal"
targetProjectID := ""
wrappedOptions, repoType = apiserverutil.InterceptCustomSelectorFromListOptions(wrappedOptions, "repoType", defaultType)
wrappedOptions, targetProjectID = apiserverutil.InterceptCustomSelectorFromListOptions(options, "projectID", "")

switch registryapi.RepoType(repoType) {
case registryapi.RepoTypePersonal:
obj, err = registryutil.ListPersonalChartGroupsFromStore(ctx, wrappedOptions, r.businessClient, r.privilegedUsername, r.Store)
case registryapi.RepoTypeProject:
obj, err = registryutil.ListProjectChartGroupsFromStore(ctx, wrappedOptions, r.businessClient, r.authClient, r.privilegedUsername, r.Store)
obj, err = registryutil.ListProjectChartGroupsFromStore(ctx, wrappedOptions, targetProjectID, r.businessClient, r.authClient, r.privilegedUsername, r.Store)
case registryapi.RepoTypeSystem:
obj, err = registryutil.ListSystemChartGroupsFromStore(ctx, wrappedOptions, r.businessClient, r.privilegedUsername, r.Store)
case registryapi.RepoTypePublic:
obj, err = registryutil.ListPublicChartGroupsFromStore(ctx, wrappedOptions, r.businessClient, r.privilegedUsername, r.Store)
case registryapi.RepoTypeAll:
obj, err = registryutil.ListAllChartGroupsFromStore(ctx, wrappedOptions, r.businessClient, r.authClient, r.privilegedUsername, r.Store)
obj, err = registryutil.ListAllChartGroupsFromStore(ctx, wrappedOptions, targetProjectID, r.businessClient, r.authClient, r.privilegedUsername, r.Store)
case registryapi.RepoType(defaultType):
obj, err = r.Store.List(ctx, wrappedOptions)
default:
Expand Down
6 changes: 4 additions & 2 deletions pkg/registry/util/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ func ListPersonalChartsFromStore(ctx context.Context,
// ListProjectChartsFromStore list all charts that belongs to project chartgroup
func ListProjectChartsFromStore(ctx context.Context,
options *metainternal.ListOptions,
targetProjectID string,
businessClient businessversionedclient.BusinessV1Interface,
authClient authversionedclient.AuthV1Interface,
registryClient *registryinternalclient.RegistryClient,
privilegedUsername string,
store *registry.Store) (runtime.Object, error) {
obj, err := ListProjectChartGroups(ctx, options.DeepCopy(), businessClient, authClient, registryClient, privilegedUsername)
obj, err := ListProjectChartGroups(ctx, options.DeepCopy(), targetProjectID, businessClient, authClient, registryClient, privilegedUsername)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -130,6 +131,7 @@ func mergeCharts(cgs ...runtime.Object) *registryapi.ChartList {
// ListAllChartsFromStore list all charts
func ListAllChartsFromStore(ctx context.Context,
options *metainternal.ListOptions,
targetProjectID string,
businessClient businessversionedclient.BusinessV1Interface,
authClient authversionedclient.AuthV1Interface,
registryClient *registryinternalclient.RegistryClient,
Expand All @@ -139,7 +141,7 @@ func ListAllChartsFromStore(ctx context.Context,
if err != nil {
return nil, err
}
project, err := ListProjectChartsFromStore(ctx, options.DeepCopy(), businessClient, authClient, registryClient, privilegedUsername, store)
project, err := ListProjectChartsFromStore(ctx, options.DeepCopy(), targetProjectID, businessClient, authClient, registryClient, privilegedUsername, store)
if err != nil {
return nil, err
}
Expand Down
15 changes: 10 additions & 5 deletions pkg/registry/util/chartgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@ func prepareListProjectChartGroups(ctx context.Context,

// filterProjectChartGroups filter all charts that belongs to project
func filterProjectChartGroups(ctx context.Context,
options *metainternal.ListOptions,
targetProjectID string,
authClient authversionedclient.AuthV1Interface,
chartGroupList *registryapi.ChartGroupList,
filterFromProjectBelongs bool) (runtime.Object, error) {

targetPrj := func(prjs []string, prj string) bool {
return prj == "" || util.InStringSlice(prjs, prj)
}
targetProjectID := filter.ProjectIDFrom(ctx)

if filterFromProjectBelongs && authClient != nil {
uid := authentication.GetUID(ctx)
Expand Down Expand Up @@ -179,6 +180,7 @@ func filterProjectChartGroups(ctx context.Context,
// ListProjectChartGroupsFromStore list all charts that belongs to project
func ListProjectChartGroupsFromStore(ctx context.Context,
options *metainternal.ListOptions,
targetProjectID string,
businessClient businessversionedclient.BusinessV1Interface,
authClient authversionedclient.AuthV1Interface,
privilegedUsername string,
Expand All @@ -195,12 +197,13 @@ func ListProjectChartGroupsFromStore(ctx context.Context,
if len(chartGroupList.Items) == 0 {
return &registryapi.ChartGroupList{}, nil
}
return filterProjectChartGroups(ctx, authClient, chartGroupList, (!admin && !platformAdmin))
return filterProjectChartGroups(ctx, options, targetProjectID, authClient, chartGroupList, (!admin && !platformAdmin))
}

// ListProjectChartGroups list all charts that belongs to project
func ListProjectChartGroups(ctx context.Context,
options *metainternal.ListOptions,
targetProjectID string,
businessClient businessversionedclient.BusinessV1Interface,
authClient authversionedclient.AuthV1Interface,
registryClient *registryinternalclient.RegistryClient,
Expand All @@ -218,7 +221,7 @@ func ListProjectChartGroups(ctx context.Context,
if len(chartGroupList.Items) == 0 {
return &registryapi.ChartGroupList{}, nil
}
return filterProjectChartGroups(ctx, authClient, chartGroupList, (!admin && !platformAdmin))
return filterProjectChartGroups(ctx, options, targetProjectID, authClient, chartGroupList, (!admin && !platformAdmin))
}

// prepareListSystemChartGroups list all charts that belongs to system
Expand Down Expand Up @@ -333,6 +336,7 @@ func mergeChartgroups(cgs ...runtime.Object) *registryapi.ChartGroupList {
// ListAllChartGroupsFromStore list all chartgroups
func ListAllChartGroupsFromStore(ctx context.Context,
options *metainternal.ListOptions,
targetProjectID string,
businessClient businessversionedclient.BusinessV1Interface,
authClient authversionedclient.AuthV1Interface,
privilegedUsername string,
Expand All @@ -341,7 +345,7 @@ func ListAllChartGroupsFromStore(ctx context.Context,
if err != nil {
return nil, err
}
project, err := ListProjectChartGroupsFromStore(ctx, options.DeepCopy(), businessClient, authClient, privilegedUsername, store)
project, err := ListProjectChartGroupsFromStore(ctx, options.DeepCopy(), targetProjectID, businessClient, authClient, privilegedUsername, store)
if err != nil {
return nil, err
}
Expand All @@ -356,6 +360,7 @@ func ListAllChartGroupsFromStore(ctx context.Context,
// ListAllChartGroups list all chartgroups
func ListAllChartGroups(ctx context.Context,
options *metainternal.ListOptions,
targetProjectID string,
businessClient businessversionedclient.BusinessV1Interface,
authClient authversionedclient.AuthV1Interface,
registryClient *registryinternalclient.RegistryClient,
Expand All @@ -364,7 +369,7 @@ func ListAllChartGroups(ctx context.Context,
if err != nil {
return nil, err
}
project, err := ListProjectChartGroups(ctx, options.DeepCopy(), businessClient, authClient, registryClient, privilegedUsername)
project, err := ListProjectChartGroups(ctx, options.DeepCopy(), targetProjectID, businessClient, authClient, registryClient, privilegedUsername)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 3e853a0

Please sign in to comment.