diff --git a/pkg/controller/openpitrix/helmapplication/helm_application_controller.go b/pkg/controller/openpitrix/helmapplication/helm_application_controller.go index 6548a0b8999bb0a734d1917cedff20f2b911ae3c..f1cd4d61ee4964ada8408e0bdf6aa0c46015afca 100644 --- a/pkg/controller/openpitrix/helmapplication/helm_application_controller.go +++ b/pkg/controller/openpitrix/helmapplication/helm_application_controller.go @@ -87,6 +87,9 @@ func (r *ReconcileHelmApplication) Reconcile(request reconcile.Request) (reconci return reconcile.Result{}, nil } } + + // app has changed, update app status + return reconcile.Result{}, updateHelmApplicationStatus(r.Client, strings.TrimSuffix(app.Name, v1alpha1.HelmApplicationAppStoreSuffix), inAppStore(app)) } else { // delete app copy in appStore if !inAppStore(app) { @@ -164,11 +167,6 @@ func (r *ReconcileHelmApplication) createAppCopyInAppStore(ctx context.Context, } } - if app.Status.State == "" { - // update status if needed - return updateHelmApplicationStatus(r.Client, originApp.Name, true) - } - return nil } diff --git a/pkg/kapis/openpitrix/v1/handler.go b/pkg/kapis/openpitrix/v1/handler.go index 12dd4611534ce12d474ea43bb254661ec003d8a3..9ac9c49805e8d65843e41bf51c1956c5e64f6a57 100644 --- a/pkg/kapis/openpitrix/v1/handler.go +++ b/pkg/kapis/openpitrix/v1/handler.go @@ -218,7 +218,11 @@ func (h *openpitrixHandler) DescribeRepo(req *restful.Request, resp *restful.Res if err != nil { klog.Errorln(err) - handleOpenpitrixError(resp, err) + if apierrors.IsNotFound(err) { + api.HandleNotFound(resp, nil, err) + return + } + api.HandleInternalError(resp, nil, err) return } diff --git a/pkg/models/openpitrix/applications.go b/pkg/models/openpitrix/applications.go index 7df552b54d81fe9ac20ff4696e647593d86aa443..dcb1e3203a1f34494493013f34952de268ba6cdf 100644 --- a/pkg/models/openpitrix/applications.go +++ b/pkg/models/openpitrix/applications.go @@ -242,6 +242,7 @@ func (c *applicationOperator) CreateApp(req *CreateAppRequest) (*CreateAppRespon Spec: v1alpha1.HelmApplicationSpec{ Name: req.Name, Description: stringutils.ShortenString(chrt.GetDescription(), v1alpha1.MsgLen), + Icon: stringutils.ShortenString(chrt.GetIcon(), v1alpha1.MsgLen), }, } app, err := c.createApp(helmApp, req.Icon) diff --git a/pkg/models/openpitrix/applicationversions.go b/pkg/models/openpitrix/applicationversions.go index 1fa4229d0d21f1a92db8db3b715844d15f4964f9..c134d4a6ea2fa70a92aece5ca1f92005cf4fbf9f 100644 --- a/pkg/models/openpitrix/applicationversions.go +++ b/pkg/models/openpitrix/applicationversions.go @@ -230,7 +230,11 @@ func (c *applicationOperator) ListAppVersionReviews(conditions *params.Condition items := make([]interface{}, 0, len(filtered)) for i, j := offset, 0; i < len(filtered) && j < limit; i, j = i+1, j+1 { - review := convertAppVersionReview(filtered[i]) + app, err := c.appLister.Get(filtered[i].GetHelmApplicationId()) + if err != nil { + return nil, err + } + review := convertAppVersionReview(app, filtered[i]) items = append(items, review) } diff --git a/pkg/models/openpitrix/repos.go b/pkg/models/openpitrix/repos.go index 9f7b4b97e518977aeb5b39315331110abe90c5da..884238d29e4d7170e62e617eb526786d22aef993 100644 --- a/pkg/models/openpitrix/repos.go +++ b/pkg/models/openpitrix/repos.go @@ -20,7 +20,6 @@ import ( "sort" "strings" - "github.com/go-openapi/strfmt" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -160,7 +159,8 @@ func (c *repoOperator) ModifyRepo(id string, request *ModifyRepoRequest) error { repoCopy.Spec.Description = stringutils.ShortenString(*request.Description, DescriptionLen) } - if request.Name != nil && len(*request.Name) > 0 && *request.Name != repoCopy.Name { + // modify name of the repo + if request.Name != nil && len(*request.Name) > 0 && *request.Name != repoCopy.Spec.Name { items, err := c.repoLister.List(labels.SelectorFromSet(map[string]string{constants.WorkspaceLabelKey: repo.GetWorkspace()})) if err != nil && !apierrors.IsNotFound(err) { klog.Errorf("list helm repo failed: %s", err) @@ -207,10 +207,12 @@ func (c *repoOperator) ModifyRepo(id string, request *ModifyRepoRequest) error { repoCopy.Spec.Credential = *cred repoCopy.Spec.Url = parsedUrl.String() + + // change repo name and description won't change version + repoCopy.Spec.Version += 1 } patch := client.MergeFrom(repo) - repoCopy.Spec.Version += 1 data, err := patch.Data(repoCopy) if err != nil { klog.Error("create patch failed", err) @@ -238,16 +240,8 @@ func (c *repoOperator) DescribeRepo(id string) (*Repo, error) { return nil, err } - var desRepo Repo - - desRepo.URL = repo.Spec.Url - desRepo.Description = repo.Spec.Description - desRepo.Name = repo.GetTrueName() - desRepo.RepoId = repo.Name - dt, _ := strfmt.ParseDateTime(repo.CreationTimestamp.String()) - desRepo.CreateTime = &dt - - return &desRepo, nil + retRepo := convertRepo(repo) + return retRepo, nil } func (c *repoOperator) ListRepos(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) { diff --git a/pkg/models/openpitrix/types.go b/pkg/models/openpitrix/types.go index 3e4c7cd4a45d3b425cf21c32e878a55182ff74a6..169c23b62f767ffafab66ef92426c0d823d98a4f 100644 --- a/pkg/models/openpitrix/types.go +++ b/pkg/models/openpitrix/types.go @@ -690,8 +690,8 @@ type Repo struct { // repository name Name string `json:"name,omitempty"` - // owner - Owner string `json:"owner,omitempty"` + // creator + Creator string `json:"creator,omitempty"` // runtime provider eg.[qingcloud|aliyun|aws|kubernetes] Providers []string `json:"providers"` diff --git a/pkg/models/openpitrix/utils.go b/pkg/models/openpitrix/utils.go index 3abe7bea4f2864190f04080e409a451f3ea1d949..1b4d63753945d7d8be5af00f6b19e2f28c210462 100644 --- a/pkg/models/openpitrix/utils.go +++ b/pkg/models/openpitrix/utils.go @@ -17,6 +17,7 @@ limitations under the License. package openpitrix import ( + "encoding/json" "fmt" "path" "regexp" @@ -406,6 +407,10 @@ func convertRepo(in *v1alpha1.HelmRepo) *Repo { out.CreateTime = &date out.Description = in.Spec.Description + out.Creator = in.GetCreator() + + cred, _ := json.Marshal(in.Spec.Credential) + out.Credential = string(cred) out.URL = in.Spec.Url return &out @@ -754,7 +759,7 @@ func attachmentKeyInStorage(ws, id string) string { return path.Join(ws, id) } -func convertAppVersionReview(appVersion *v1alpha1.HelmApplicationVersion) *AppVersionReview { +func convertAppVersionReview(app *v1alpha1.HelmApplication, appVersion *v1alpha1.HelmApplicationVersion) *AppVersionReview { review := &AppVersionReview{} status := appVersion.Status review.Reviewer = status.Audit[0].Operator @@ -766,7 +771,7 @@ func convertAppVersionReview(appVersion *v1alpha1.HelmApplicationVersion) *AppVe review.VersionName = appVersion.GetVersionName() review.StatusTime = strfmt.DateTime(status.Audit[0].Time.Time) - review.AppName = appVersion.GetTrueName() + review.AppName = app.GetTrueName() return review }