Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复配置模版文件没有按照预期效果排序 #3311

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,6 @@ func (s *Service) getPBSForCascade(kt *kit.Kit, tx *gen.QueryTx, bindings []*tab
}
}
}
if e := s.validateTmplForATBWithTx(kt, tx, pbs.TemplateIDs); e != nil {
logs.Errorf("validate template for app template binding failed, err: %v, rid: %s", e, kt.Rid)
return nil, e
}

// get all latest revisions of latest templates
latestTmplRevisions, err := s.dao.TemplateRevision().ListByTemplateIDsWithTx(kt, tx, kt.BizID,
Expand Down Expand Up @@ -631,44 +627,6 @@ func (s *Service) getPBSForCascade(kt *kit.Kit, tx *gen.QueryTx, bindings []*tab
return pbs, nil
}

// validateTmplForATBWithTx validate template with transaction to avoid same templates are bound to one app
func (s *Service) validateTmplForATBWithTx(kt *kit.Kit, tx *gen.QueryTx, tmplIDs []uint32) error {
if len(tmplIDs) == 0 {
return nil
}

if repeated := tools.SliceRepeatedElements(tmplIDs); len(repeated) > 0 {
// get template details
tmpls, err := s.dao.Template().ListByIDsWithTx(kt, tx, repeated)
if err != nil {
logs.Errorf("list template by ids failed, err: %v, rid: %s", err, kt.Rid)
return err
}
type tmplT struct {
ID uint32 `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
}
details := make([]tmplT, len(tmpls))
for idx, t := range tmpls {
details[idx] = tmplT{
ID: t.ID,
Name: t.Spec.Name,
Path: t.Spec.Path,
}
}
detailsJs, err := json.Marshal(details)
if err != nil {
logs.Errorf("marshal template details failed, err: %v, rid: %s", err, kt.Rid)
return err
}
return fmt.Errorf("same template id in %v can't be bound to the same app, template details: %s",
repeated, detailsJs)
}

return nil
}

// genFinalATB generate the final app template binding.
func (s *Service) genFinalATB(kt *kit.Kit, atb *table.AppTemplateBinding) error {
pbs := parseBindings(atb.Spec.Bindings)
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-bscp/cmd/data-service/service/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ func (s *Service) ListTemplatesNotBound(ctx context.Context, req *pbds.ListTempl

// ListTmplsOfTmplSet list templates of template set.
// 获取到该套餐的template_ids字段,根据这批ID获取对应的详情,做逻辑分页和搜索
func (s *Service) ListTmplsOfTmplSet(ctx context.Context, req *pbds.ListTmplsOfTmplSetReq) ( // nolint
func (s *Service) ListTmplsOfTmplSet(ctx context.Context, req *pbds.ListTmplsOfTmplSetReq) (
*pbds.ListTmplsOfTmplSetResp, error) {
kt := kit.FromGrpcContext(ctx)

Expand Down
10 changes: 5 additions & 5 deletions bcs-services/bcs-bscp/pkg/dal/dao/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ func (dao *templateDao) List(kit *kit.Kit, bizID, templateSpaceID uint32, s sear
d := q.Where(m.BizID.Eq(bizID), m.TemplateSpaceID.Eq(templateSpaceID)).Where(conds...)
if len(topIds) != 0 {
d = d.Order(utils.NewCustomExpr("CASE WHEN id IN (?) THEN 0 ELSE 1 END,"+
"CASE WHEN RIGHT(path, 1) = '/' THEN CONCAT(path,'name') ELSE CONCAT_WS('/', path, 'name') END",
"CASE WHEN RIGHT(path, 1) = '/' THEN CONCAT(path,`name`) ELSE CONCAT_WS('/', path, `name`) END",
[]interface{}{topIds}))
} else {
d = d.Order(utils.NewCustomExpr("CASE WHEN RIGHT(path, 1) = '/' THEN CONCAT(path,'name') ELSE "+
"CONCAT_WS('/', path, 'name') END", nil))
d = d.Order(utils.NewCustomExpr("CASE WHEN RIGHT(path, 1) = '/' THEN CONCAT(path,`name`) ELSE "+
"CONCAT_WS('/', path, `name`) END", nil))
}

if opt.All {
Expand Down Expand Up @@ -347,8 +347,8 @@ func (dao *templateDao) ListByIDs(kit *kit.Kit, ids []uint32) ([]*table.Template
m := dao.genQ.Template
q := dao.genQ.Template.WithContext(kit.Ctx)
result, err := q.Where(m.ID.In(ids...)).
Order(utils.NewCustomExpr("CASE WHEN RIGHT(path, 1) = '/' THEN CONCAT(path,'name') "+
"ELSE CONCAT_WS('/', path, 'name') END", nil)).Find()
Order(utils.NewCustomExpr("CASE WHEN RIGHT(path, 1) = '/' THEN CONCAT(path,`name`) "+
"ELSE CONCAT_WS('/', path, `name`) END", nil)).Find()
if err != nil {
return nil, err
}
Expand Down
Loading