未验证 提交 a7cbc6f8 编写于 作者: K KubeSphere CI Bot 提交者: GitHub

Merge pull request #3651 from xyz-li/app-fix

Fix: fix app repo and helm app bugs
...@@ -87,6 +87,9 @@ func (r *ReconcileHelmApplication) Reconcile(request reconcile.Request) (reconci ...@@ -87,6 +87,9 @@ func (r *ReconcileHelmApplication) Reconcile(request reconcile.Request) (reconci
return reconcile.Result{}, nil 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 { } else {
// delete app copy in appStore // delete app copy in appStore
if !inAppStore(app) { if !inAppStore(app) {
...@@ -164,11 +167,6 @@ func (r *ReconcileHelmApplication) createAppCopyInAppStore(ctx context.Context, ...@@ -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 return nil
} }
......
...@@ -218,7 +218,11 @@ func (h *openpitrixHandler) DescribeRepo(req *restful.Request, resp *restful.Res ...@@ -218,7 +218,11 @@ func (h *openpitrixHandler) DescribeRepo(req *restful.Request, resp *restful.Res
if err != nil { if err != nil {
klog.Errorln(err) klog.Errorln(err)
handleOpenpitrixError(resp, err) if apierrors.IsNotFound(err) {
api.HandleNotFound(resp, nil, err)
return
}
api.HandleInternalError(resp, nil, err)
return return
} }
......
...@@ -242,6 +242,7 @@ func (c *applicationOperator) CreateApp(req *CreateAppRequest) (*CreateAppRespon ...@@ -242,6 +242,7 @@ func (c *applicationOperator) CreateApp(req *CreateAppRequest) (*CreateAppRespon
Spec: v1alpha1.HelmApplicationSpec{ Spec: v1alpha1.HelmApplicationSpec{
Name: req.Name, Name: req.Name,
Description: stringutils.ShortenString(chrt.GetDescription(), v1alpha1.MsgLen), Description: stringutils.ShortenString(chrt.GetDescription(), v1alpha1.MsgLen),
Icon: stringutils.ShortenString(chrt.GetIcon(), v1alpha1.MsgLen),
}, },
} }
app, err := c.createApp(helmApp, req.Icon) app, err := c.createApp(helmApp, req.Icon)
......
...@@ -230,7 +230,11 @@ func (c *applicationOperator) ListAppVersionReviews(conditions *params.Condition ...@@ -230,7 +230,11 @@ func (c *applicationOperator) ListAppVersionReviews(conditions *params.Condition
items := make([]interface{}, 0, len(filtered)) items := make([]interface{}, 0, len(filtered))
for i, j := offset, 0; i < len(filtered) && j < limit; i, j = i+1, j+1 { 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) items = append(items, review)
} }
......
...@@ -20,7 +20,6 @@ import ( ...@@ -20,7 +20,6 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/go-openapi/strfmt"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
...@@ -160,7 +159,8 @@ func (c *repoOperator) ModifyRepo(id string, request *ModifyRepoRequest) error { ...@@ -160,7 +159,8 @@ func (c *repoOperator) ModifyRepo(id string, request *ModifyRepoRequest) error {
repoCopy.Spec.Description = stringutils.ShortenString(*request.Description, DescriptionLen) 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()})) items, err := c.repoLister.List(labels.SelectorFromSet(map[string]string{constants.WorkspaceLabelKey: repo.GetWorkspace()}))
if err != nil && !apierrors.IsNotFound(err) { if err != nil && !apierrors.IsNotFound(err) {
klog.Errorf("list helm repo failed: %s", err) klog.Errorf("list helm repo failed: %s", err)
...@@ -207,10 +207,12 @@ func (c *repoOperator) ModifyRepo(id string, request *ModifyRepoRequest) error { ...@@ -207,10 +207,12 @@ func (c *repoOperator) ModifyRepo(id string, request *ModifyRepoRequest) error {
repoCopy.Spec.Credential = *cred repoCopy.Spec.Credential = *cred
repoCopy.Spec.Url = parsedUrl.String() repoCopy.Spec.Url = parsedUrl.String()
// change repo name and description won't change version
repoCopy.Spec.Version += 1
} }
patch := client.MergeFrom(repo) patch := client.MergeFrom(repo)
repoCopy.Spec.Version += 1
data, err := patch.Data(repoCopy) data, err := patch.Data(repoCopy)
if err != nil { if err != nil {
klog.Error("create patch failed", err) klog.Error("create patch failed", err)
...@@ -238,16 +240,8 @@ func (c *repoOperator) DescribeRepo(id string) (*Repo, error) { ...@@ -238,16 +240,8 @@ func (c *repoOperator) DescribeRepo(id string) (*Repo, error) {
return nil, err return nil, err
} }
var desRepo Repo retRepo := convertRepo(repo)
return retRepo, nil
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
} }
func (c *repoOperator) ListRepos(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) { func (c *repoOperator) ListRepos(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
......
...@@ -690,8 +690,8 @@ type Repo struct { ...@@ -690,8 +690,8 @@ type Repo struct {
// repository name // repository name
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
// owner // creator
Owner string `json:"owner,omitempty"` Creator string `json:"creator,omitempty"`
// runtime provider eg.[qingcloud|aliyun|aws|kubernetes] // runtime provider eg.[qingcloud|aliyun|aws|kubernetes]
Providers []string `json:"providers"` Providers []string `json:"providers"`
......
...@@ -17,6 +17,7 @@ limitations under the License. ...@@ -17,6 +17,7 @@ limitations under the License.
package openpitrix package openpitrix
import ( import (
"encoding/json"
"fmt" "fmt"
"path" "path"
"regexp" "regexp"
...@@ -406,6 +407,10 @@ func convertRepo(in *v1alpha1.HelmRepo) *Repo { ...@@ -406,6 +407,10 @@ func convertRepo(in *v1alpha1.HelmRepo) *Repo {
out.CreateTime = &date out.CreateTime = &date
out.Description = in.Spec.Description out.Description = in.Spec.Description
out.Creator = in.GetCreator()
cred, _ := json.Marshal(in.Spec.Credential)
out.Credential = string(cred)
out.URL = in.Spec.Url out.URL = in.Spec.Url
return &out return &out
...@@ -754,7 +759,7 @@ func attachmentKeyInStorage(ws, id string) string { ...@@ -754,7 +759,7 @@ func attachmentKeyInStorage(ws, id string) string {
return path.Join(ws, id) return path.Join(ws, id)
} }
func convertAppVersionReview(appVersion *v1alpha1.HelmApplicationVersion) *AppVersionReview { func convertAppVersionReview(app *v1alpha1.HelmApplication, appVersion *v1alpha1.HelmApplicationVersion) *AppVersionReview {
review := &AppVersionReview{} review := &AppVersionReview{}
status := appVersion.Status status := appVersion.Status
review.Reviewer = status.Audit[0].Operator review.Reviewer = status.Audit[0].Operator
...@@ -766,7 +771,7 @@ func convertAppVersionReview(appVersion *v1alpha1.HelmApplicationVersion) *AppVe ...@@ -766,7 +771,7 @@ func convertAppVersionReview(appVersion *v1alpha1.HelmApplicationVersion) *AppVe
review.VersionName = appVersion.GetVersionName() review.VersionName = appVersion.GetVersionName()
review.StatusTime = strfmt.DateTime(status.Audit[0].Time.Time) review.StatusTime = strfmt.DateTime(status.Audit[0].Time.Time)
review.AppName = appVersion.GetTrueName() review.AppName = app.GetTrueName()
return review return review
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册