Skip to content

Commit

Permalink
Merge remote-tracking branch 'github-bk-bcs/master'
Browse files Browse the repository at this point in the history
* github-bk-bcs/master:
  feature: 完善导入AKS集群及集群扩缩容功能 (#2942)
  feat: 未命名版本有修改的配置文件与配置项顶置+支持筛选 (#2940)
  • Loading branch information
wenxinlee2015 committed Feb 5, 2024
2 parents dbf272d + f794b4c commit 5f588e3
Show file tree
Hide file tree
Showing 70 changed files with 31,861 additions and 7,904 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ func (s *Service) ListConfigItems(ctx context.Context, req *pbcs.ListConfigItems
All: req.All,
Ids: req.Ids,
WithStatus: req.WithStatus,
Status: req.Status,
}
rp, err := s.client.DS.ListConfigItems(grpcKit.RpcCtx(), r)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions bcs-services/bcs-bscp/cmd/config-server/service/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (s *Service) ListKvs(ctx context.Context, req *pbcs.ListKvsReq) (*pbcs.List
Sort: req.Sort,
Order: req.Order,
TopIds: req.TopIds,
Status: req.Status,
}
if !req.All {
if req.Limit == 0 {
Expand Down
15 changes: 5 additions & 10 deletions bcs-services/bcs-bscp/cmd/data-service/service/config_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,7 @@ func (s *Service) ListConfigItems(ctx context.Context, req *pbds.ListConfigItems
logs.Errorf("get commit, err: %v, rid: %s", err, grpcKit.Rid)
return nil, err
}

configItems = pbrci.PbConfigItemState(details, fileReleased, commits)
configItems = pbrci.PbConfigItemState(details, fileReleased, commits, req.Status)
} else {
for _, ci := range details {
configItems = append(configItems, pbci.PbConfigItem(ci, ""))
Expand Down Expand Up @@ -623,18 +622,14 @@ func (s *Service) ListConfigItems(ctx context.Context, req *pbds.ListConfigItems
end = uint32(len(configItems))
}
}

// 如果有topID则按照topID排最前面
topId, _ := tools.StrToUint32Slice(req.Ids)
sort.SliceStable(configItems, func(i, j int) bool {
// 检测模板id是否在topId中
iInTopID := tools.Contains(topId, configItems[i].Id)
jInTopID := tools.Contains(topId, configItems[j].Id)
// 两者都在则先path排再name排
// 不管topID有没有都要先path排再name排
if iInTopID && jInTopID || len(topId) == 0 {
if configItems[i].GetSpec().GetPath() != configItems[j].GetSpec().GetPath() {
return configItems[i].GetSpec().GetPath() < configItems[j].GetSpec().GetPath()
}
return configItems[i].GetSpec().GetName() < configItems[j].GetSpec().GetName()
if iInTopID && jInTopID {
return i < j
}
if iInTopID {
return true
Expand Down
1 change: 1 addition & 0 deletions bcs-services/bcs-bscp/cmd/data-service/service/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func (s *Service) ListKvs(ctx context.Context, req *pbds.ListKvsReq) (*pbds.List
Page: page,
KvType: req.KvType,
TopIDs: topIds,
Status: req.Status,
}
po := &types.PageOption{
EnableUnlimitedLimit: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ package service

import (
"context"
"path"
"sort"

"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/kit"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/logs"
Expand Down Expand Up @@ -60,7 +62,12 @@ func (s *Service) ListReleasedConfigItems(ctx context.Context,
logs.Errorf("list released app bound templates revisions failed, err: %v, rid: %s", err, kt.Rid)
return nil, err
}

// 先按照path+name排序好
sort.SliceStable(details, func(i, j int) bool {
iPath := path.Join(details[i].ConfigItemSpec.Path, details[i].ConfigItemSpec.Name)
jPath := path.Join(details[j].ConfigItemSpec.Path, details[j].ConfigItemSpec.Name)
return iPath < jPath
})
resp := &pbds.ListReleasedConfigItemsResp{
Count: uint32(count),
Details: pbrci.PbReleasedConfigItems(details),
Expand Down
9 changes: 2 additions & 7 deletions bcs-services/bcs-bscp/cmd/data-service/service/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,15 +661,10 @@ func (s *Service) ListTmplsOfTmplSet(ctx context.Context, req *pbds.ListTmplsOfT
}
topId, _ := tools.StrToUint32Slice(req.Ids)
sort.SliceStable(details, func(i, j int) bool {
// 检测模板id是否在topId中
iInTopID := tools.Contains(topId, details[i].Id)
jInTopID := tools.Contains(topId, details[j].Id)
// 两者都在则按照path+name排序
if iInTopID && jInTopID || len(topId) == 0 {
if details[i].GetSpec().GetPath() != details[j].GetSpec().GetPath() {
return details[i].GetSpec().GetPath() < details[j].GetSpec().GetPath()
}
return details[i].GetSpec().GetName() < details[j].GetSpec().GetName()
if iInTopID && jInTopID {
return i < j
}
if iInTopID {
return true
Expand Down
20 changes: 18 additions & 2 deletions bcs-services/bcs-bscp/pkg/dal/dao/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package dao
import (
"errors"
"fmt"
"strings"

"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/criteria/errf"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/gen"
Expand Down Expand Up @@ -147,19 +148,34 @@ func (dao *kvDao) List(kit *kit.Kit, opt *types.ListKvOption) ([]*table.Kv, int6
if !ok {
return nil, 0, errors.New("user doesn't contains orderColStr")
}

orderStr := "CASE WHEN kv_state = 'ADD' THEN 1 WHEN kv_state = 'REVISE' THEN 2 " +
"WHEN kv_state = 'DELETE' THEN 3 WHEN kv_state = 'UNCHANGE' THEN 4 END,`key` asc"

if opt.Page.Order == types.Descending {
q = q.Order(orderCol.Desc())
} else if len(opt.TopIDs) != 0 {
q = q.Order(utils.NewCustomExpr("CASE WHEN id IN (?) THEN 0 ELSE 1 END,`key` asc", []interface{}{opt.TopIDs}))
q = q.Order(utils.NewCustomExpr("CASE WHEN id IN (?) THEN 0 ELSE 1 END, "+orderStr, []interface{}{opt.TopIDs}))
} else {
q = q.Order(orderCol)
q = q.Order(utils.NewCustomExpr(orderStr, nil))
}

if opt.SearchKey != "" {
searchKey := "%" + opt.SearchKey + "%"
q = q.Where(q.Where(q.Or(m.Key.Like(searchKey)).Or(m.Creator.Like(searchKey)).Or(m.Reviser.Like(searchKey))))
}

switch strings.ToUpper(opt.Status) {
case string(table.KvStateAdd):
q = q.Where(m.KvState.Eq(string(table.KvStateAdd)))
case string(table.KvStateDelete):
q = q.Where(m.KvState.Eq(string(table.KvStateDelete)))
case string(table.KvStateRevise):
q = q.Where(m.KvState.Eq(string(table.KvStateRevise)))
case string(table.KvStateUnchange):
q = q.Where(m.KvState.Eq(string(table.KvStateUnchange)))
}

q = q.Where(m.BizID.Eq(opt.BizID)).Where(m.AppID.Eq(opt.AppID))

if len(opt.KvType) > 0 {
Expand Down
8 changes: 6 additions & 2 deletions bcs-services/bcs-bscp/pkg/dal/dao/released_app_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/criteria/errf"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/gen"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/table"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/dal/utils"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/kit"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/search"
"github.com/TencentBlueKing/bk-bcs/bcs-services/bcs-bscp/pkg/types"
Expand Down Expand Up @@ -140,9 +141,12 @@ func (dao *releasedAppTemplateDao) GetReleasedLately(kit *kit.Kit, bizID, appId
[]*table.ReleasedAppTemplate, error) {
m := dao.genQ.ReleasedAppTemplate
q := dao.genQ.ReleasedAppTemplate.WithContext(kit.Ctx)

query := q.Where(m.BizID.Eq(bizID), m.AppID.Eq(appId))
subQuery := q.Where(m.BizID.Eq(bizID), m.AppID.Eq(appId)).Order(m.ReleaseID.Desc()).Limit(1).Select(m.ReleaseID)
subQuery := q.Where(m.BizID.Eq(bizID), m.AppID.Eq(appId)).
Order(m.ReleaseID.Desc(), utils.NewCustomExpr("CASE WHEN RIGHT(path, 1) = '/' THEN CONCAT(path,'name') ELSE "+
"CONCAT_WS('/', path, 'name') END", nil)).
Limit(1).
Select(m.ReleaseID)
return query.Where(q.Columns(m.ReleaseID).Eq(subQuery)).Find()
}

Expand Down
11 changes: 8 additions & 3 deletions bcs-services/bcs-bscp/pkg/dal/dao/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,12 @@ 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,path,name ASC`, []interface{}{topIds}))
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",
[]interface{}{topIds}))
} else {
d = d.Order(m.Path, m.Name)
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 @@ -343,7 +346,9 @@ func (dao *templateDao) GetByID(kit *kit.Kit, bizID, templateID uint32) (*table.
func (dao *templateDao) ListByIDs(kit *kit.Kit, ids []uint32) ([]*table.Template, error) {
m := dao.genQ.Template
q := dao.genQ.Template.WithContext(kit.Ctx)
result, err := q.Where(m.ID.In(ids...)).Find()
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()
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 5f588e3

Please sign in to comment.