From bfb8924eb3c5d5316e67861970bbfd5fc3417dd5 Mon Sep 17 00:00:00 2001 From: hongming Date: Fri, 27 Sep 2019 14:44:21 +0800 Subject: [PATCH] refactor: openpitrix module Signed-off-by: hongming --- pkg/apiserver/openpitrix/categories.go | 2 +- pkg/controller/namespace/namespace_controller.go | 1 + pkg/models/openpitrix/apps.go | 12 +++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/apiserver/openpitrix/categories.go b/pkg/apiserver/openpitrix/categories.go index 4bd89ae83..2723f900e 100644 --- a/pkg/apiserver/openpitrix/categories.go +++ b/pkg/apiserver/openpitrix/categories.go @@ -156,7 +156,7 @@ func ListCategories(req *restful.Request, resp *restful.Response) { if statistics { for _, item := range result.Items { if category, ok := item.(*openpitrix.Category); ok { - statisticsResult, err := openpitrix.ListApps(¶ms.Conditions{Match: map[string]string{"category_id": category.CategoryID, "status": "active"}}, "", false, 0, 0) + statisticsResult, err := openpitrix.ListApps(¶ms.Conditions{Match: map[string]string{"category_id": category.CategoryID, "status": openpitrix.StatusActive, "repo": openpitrix.BuiltinRepoId}}, "", false, 0, 0) if err != nil { klog.Errorln(err) resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err)) diff --git a/pkg/controller/namespace/namespace_controller.go b/pkg/controller/namespace/namespace_controller.go index 2dc1a6eaf..73001a255 100644 --- a/pkg/controller/namespace/namespace_controller.go +++ b/pkg/controller/namespace/namespace_controller.go @@ -405,6 +405,7 @@ func (r *ReconcileNamespace) checkAndCreateRuntime(namespace *corev1.Namespace) kubesphereRuntimeCredentialId = resp.GetRuntimeCredentialId().GetValue() } + // TODO runtime id is invalid when recreate runtime runtimeId, err := openPitrixClient.Runtime().CreateRuntime(openpitrix.SystemContext(), &pb.CreateRuntimeRequest{ Name: &wrappers.StringValue{Value: namespace.Name}, RuntimeCredentialId: &wrappers.StringValue{Value: kubesphereRuntimeCredentialId}, diff --git a/pkg/models/openpitrix/apps.go b/pkg/models/openpitrix/apps.go index e6110350e..2f366d022 100644 --- a/pkg/models/openpitrix/apps.go +++ b/pkg/models/openpitrix/apps.go @@ -32,6 +32,11 @@ import ( "strings" ) +const ( + BuiltinRepoId = "repo-helm" + StatusActive = "active" +) + func ListApps(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) { client, err := cs.ClientSets().OpenPitrix() if err != nil { @@ -53,7 +58,12 @@ func ListApps(conditions *params.Conditions, orderBy string, reverse bool, limit describeAppsRequest.CategoryId = strings.Split(categoryId, "|") } if repoId := conditions.Match["repo"]; repoId != "" { - describeAppsRequest.RepoId = strings.Split(repoId, "|") + // hard code, app template in built-in repo has no repo_id attribute + if repoId == BuiltinRepoId { + describeAppsRequest.RepoId = []string{"\u0000"} + } else { + describeAppsRequest.RepoId = strings.Split(repoId, "|") + } } if status := conditions.Match["status"]; status != "" { describeAppsRequest.Status = strings.Split(status, "|")