From 3e853a04ebabbeea6d19b2c26979568ac4c15f11 Mon Sep 17 00:00:00 2001 From: jianzhuang Date: Fri, 25 Sep 2020 16:39:58 +0800 Subject: [PATCH] fix(registry): update chart project args --- api/registry/v1/conversion.go | 6 ++++-- pkg/registry/registry/chart/storage/storage.go | 6 ++++-- .../registry/chartgroup/storage/storage.go | 7 +++++-- pkg/registry/util/chart.go | 6 ++++-- pkg/registry/util/chartgroup.go | 15 ++++++++++----- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/api/registry/v1/conversion.go b/api/registry/v1/conversion.go index 1242e3fe0..53f2b76da 100644 --- a/api/registry/v1/conversion.go +++ b/api/registry/v1/conversion.go @@ -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: @@ -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: diff --git a/pkg/registry/registry/chart/storage/storage.go b/pkg/registry/registry/chart/storage/storage.go index 61633343d..b76a034af 100644 --- a/pkg/registry/registry/chart/storage/storage.go +++ b/pkg/registry/registry/chart/storage/storage.go @@ -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: diff --git a/pkg/registry/registry/chartgroup/storage/storage.go b/pkg/registry/registry/chartgroup/storage/storage.go index 1c0cd4fc7..48e4951ac 100644 --- a/pkg/registry/registry/chartgroup/storage/storage.go +++ b/pkg/registry/registry/chartgroup/storage/storage.go @@ -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: diff --git a/pkg/registry/util/chart.go b/pkg/registry/util/chart.go index 4c439b020..78ccd5df7 100644 --- a/pkg/registry/util/chart.go +++ b/pkg/registry/util/chart.go @@ -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 } @@ -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, @@ -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 } diff --git a/pkg/registry/util/chartgroup.go b/pkg/registry/util/chartgroup.go index 3923690b9..6d599fd7e 100644 --- a/pkg/registry/util/chartgroup.go +++ b/pkg/registry/util/chartgroup.go @@ -122,6 +122,8 @@ 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) { @@ -129,7 +131,6 @@ func filterProjectChartGroups(ctx context.Context, 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) @@ -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, @@ -195,12 +197,13 @@ func ListProjectChartGroupsFromStore(ctx context.Context, if len(chartGroupList.Items) == 0 { return ®istryapi.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, @@ -218,7 +221,7 @@ func ListProjectChartGroups(ctx context.Context, if len(chartGroupList.Items) == 0 { return ®istryapi.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 @@ -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, @@ -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 } @@ -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, @@ -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 }