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:
  feat: 支持配置文件恢复以及撤回 (#2960)
  feat: get tmpl rev with signature --task=74871191 (#2983)
  fix #2967 (#2978)
  fix: 修复导入kv时针对转义的json字符串做处理 (#2982)
  • Loading branch information
wenxinlee2015 committed Feb 28, 2024
2 parents 9fca74f + fcd1d2b commit 776de1d
Show file tree
Hide file tree
Showing 24 changed files with 9,532 additions and 8,041 deletions.
2 changes: 1 addition & 1 deletion bcs-ops/sops/bcs_bk_sops_common.dat
100755 → 100644

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions bcs-ops/system/get_lan_ip
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ version() {
echo "$PROGRAM version $VERSION"
}

error() {
local color_code="\033[031;1m"
echo -e "${color_code}$*\033[0m" >&2
}

#######################################
# get ip by cloud_api
# Return:
Expand Down Expand Up @@ -68,22 +73,22 @@ _on_cloud() {
}

_on_baremetal() {
if ! ip route show | grep "default via"; then
echo "fail to obtain LAN_IP, default route missing"
if ! ip route show | grep -q "default via"; then
error "fail to obtain LAN_IP, default route missing"
exit 2
fi
LAN_IP=$(ip -4 -o route get 10/8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p')
if [[ -n $LAN_IP ]]; then
echo "$LAN_IP"
return 0
fi
echo "fail to obtain LAN_IP"
error "fail to obtain LAN_IP"
exit 1
}

_on_baremetal_v6() {
if ! ip -6 route show | grep "default via"; then
echo "fail to obtain LAN_IPv6, default route missing"
if ! ip -6 route show | grep -q "default via"; then
error "fail to obtain LAN_IPv6, default route missing"
exit 2
fi
LAN_IPv6=$(ip -6 -o route get fd00::/8 | grep -Po '(?<=src) \K[^ ]+')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ paths:
matchSubpath: false
backend:
type: HTTP
method: post
method: get
path: /api/v1/config/list/app/app/biz_id/{biz_id}
matchSubpath: false
timeout: 0
Expand Down Expand Up @@ -1400,6 +1400,30 @@ paths:
authConfig:
userVerifiedRequired: true
disabledStages: [ ]
/api/v1/config/biz/{biz_id}/template_revisions/list_names_by_template_ids:
post:
operationId: list_template_revision_name_by_template_id
description: 批量查询模版的版本名称
tags:
- 模版版本
responses:
default:
description: ''
x-bk-apigateway-resource:
isPublic: true
allowApplyPermission: true
matchSubpath: false
backend:
type: HTTP
method: post
path: /api/v1/config/biz/{biz_id}/template_revisions/list_names_by_template_ids
matchSubpath: false
timeout: 0
upstreams: { }
transformHeaders: { }
authConfig:
userVerifiedRequired: true
disabledStages: [ ]
/api/v1/config/biz/{biz_id}/template_spaces/{template_space_id}/template_sets:
post:
operationId: create_template_set
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
### 描述

该接口提供版本:v1.0.0+

批量查询模版的版本名称

### 输入参数

| 参数名称 | 参数类型 | 必选 | 描述 |
| ------------ | -------- | ---- | --------------------- |
| biz_id | uint32 || 业务ID |
| template_ids | []uint32 || 模版ID列表,最多200个 |

### 调用示例

```json
{
"template_ids": [
1,
2
]
}
```

### 响应示例

```json
{
"data": {
"details": [
[
{
"template_id": 1,
"template_name": "template001",
"latest_template_revision_id": 2,
"latest_signature": "11e3a57c479ebfae641c5821ee70bf61dca74b8e6596b78950526c397a3b1234",
"latest_byte_size": "2067",
"template_revisions": [
{
"template_revision_id": 1,
"template_revision_name": "v20230815120105",
"template_revision_memo": "my revision for test1"
},
{
"template_revision_id": 2,
"template_revision_name": "v20230815130206",
"template_revision_memo": "my revision for test2"
}
]
},
{
"template_id": 2,
"template_name": "template002",
"latest_template_revision_id": 4,
"latest_signature": "22e3a57c479ebfae641c5821ee70bf61dca74b8e6596b78950526c397a3b1253",
"latest_byte_size": "1023",
"template_revisions": [
{
"template_revision_id": 3,
"template_revision_name": "v20230815140307",
"template_revision_memo": "my revision for test3"
},
{
"template_revision_id": 4,
"template_revision_name": "v20230815150408",
"template_revision_memo": "my revision for test2"
}
]
}
]
]
}
}
```

### 响应参数说明

| 参数名称 | 参数类型 | 描述 |
| -------- | -------- | -------- |
| data | object | 响应数据 |

#### data

| 参数名称 | 参数类型 | 描述 |
| -------- | -------- | -------------- |
| detail | array | 查询返回的数据 |

#### data.detail[n]

| 参数名称 | 参数类型 | 描述 |
| --------------------------- | -------- | -------------------------- |
| template_id | uint32 | 模版ID |
| template_name | string | 模版名称 |
| latest_template_revision_id | uint32 | 最新模版版本ID |
| latest_sinature | string | 最新模版版本内容的sha256 |
| latest_byte_size | uint64 | 最新模版版本内容的字节大小 |
| template_revisions | object | 模版版本信息 |

#### template_revisions

| 参数名称 | 参数类型 | 描述 |
| ---------------------- | -------- | ------------ |
| template_revision_id | uint32 | 模版版本ID |
| template_revision_name | string | 模版版本名称 |
| template_revision_memo | string | 模版版本描述 |
11 changes: 10 additions & 1 deletion bcs-services/bcs-bscp/cmd/api-server/service/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,16 @@ func handleKv(result map[string]interface{}) ([]*pbcs.BatchUpsertKvsReq_Kv, erro
if err != nil {
return nil, fmt.Errorf("key: %s json marshal error", key)
}
val = string(mv)
// 需要处理转义符
var data interface{}
err = json.Unmarshal(mv, &data)
if err != nil {
return nil, fmt.Errorf("key: %s json unmarshal error", key)
}
val, ok = data.(string)
if !ok {
return nil, fmt.Errorf("key: %s format error", key)
}
} else if kvType == string(table.KvYAML) {
_, ok := kvValue.(string)
if !ok {
Expand Down
19 changes: 2 additions & 17 deletions bcs-services/bcs-bscp/cmd/api-server/service/released_kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"errors"
"fmt"
"net/http"
"reflect"
"strconv"

"github.com/go-chi/chi/v5"
Expand Down Expand Up @@ -201,16 +200,9 @@ func rkvsToOutData(details []*pbrkv.ReleasedKv) map[string]interface{} {
for _, rkv := range details {
var value interface{}
value = rkv.Spec.Value
switch rkv.Spec.KvType {
case string(table.KvNumber):
if rkv.Spec.KvType == string(table.KvNumber) {
i, _ := strconv.Atoi(rkv.Spec.Value)
value = i
case string(table.KvJson):
_ = json.Unmarshal([]byte(rkv.Spec.Value), &value)
if reflect.TypeOf(value).Kind() != reflect.String {
jm, _ := json.Marshal(value)
value = string(jm)
}
}
d[rkv.Spec.Key] = map[string]interface{}{
"kv_type": rkv.Spec.KvType,
Expand All @@ -226,16 +218,9 @@ func kvsToOutData(details []*pbkv.Kv) map[string]interface{} {
for _, rkv := range details {
var value interface{}
value = rkv.Spec.Value
switch rkv.Spec.KvType {
case string(table.KvNumber):
if rkv.Spec.KvType == string(table.KvNumber) {
i, _ := strconv.Atoi(rkv.Spec.Value)
value = i
case string(table.KvJson):
_ = json.Unmarshal([]byte(rkv.Spec.Value), &value)
if reflect.TypeOf(value).Kind() != reflect.String {
jm, _ := json.Marshal(value)
value = string(jm)
}
}
d[rkv.Spec.Key] = map[string]interface{}{
"kv_type": rkv.Spec.KvType,
Expand Down
55 changes: 55 additions & 0 deletions bcs-services/bcs-bscp/cmd/config-server/service/config_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,58 @@ func (s *Service) ListConfigItemByTuple(ctx context.Context, req *pbcs.ListConfi
resp := &pbcs.ListConfigItemByTupleResp{Details: tuple.GetConfigItems()}
return resp, nil
}

// UnDeleteConfigItem 配置项未命名版本恢复
func (s *Service) UnDeleteConfigItem(ctx context.Context, req *pbcs.UnDeleteConfigItemReq) (
*pbcs.UnDeleteConfigItemResp, error) {
grpcKit := kit.FromGrpcContext(ctx)

res := []*meta.ResourceAttribute{
{Basic: meta.Basic{Type: meta.Biz, Action: meta.FindBusinessResource}, BizID: req.BizId},
{Basic: meta.Basic{Type: meta.App, Action: meta.Update, ResourceID: req.AppId}, BizID: req.BizId},
}
err := s.authorizer.Authorize(grpcKit, res...)
if err != nil {
return nil, err
}

_, err = s.client.DS.UnDeleteConfigItem(grpcKit.RpcCtx(), &pbds.UnDeleteConfigItemReq{
Id: req.Id,
Attachment: &pbci.ConfigItemAttachment{
BizId: req.BizId,
AppId: req.AppId,
},
})
if err != nil {
return nil, err
}

return &pbcs.UnDeleteConfigItemResp{}, nil
}

// UndoConfigItem 撤消配置项
func (s *Service) UndoConfigItem(ctx context.Context, req *pbcs.UndoConfigItemReq) (*pbcs.UndoConfigItemResp, error) {
grpcKit := kit.FromGrpcContext(ctx)

res := []*meta.ResourceAttribute{
{Basic: meta.Basic{Type: meta.Biz, Action: meta.FindBusinessResource}, BizID: req.BizId},
{Basic: meta.Basic{Type: meta.App, Action: meta.Update, ResourceID: req.AppId}, BizID: req.BizId},
}

err := s.authorizer.Authorize(grpcKit, res...)
if err != nil {
return nil, err
}

_, err = s.client.DS.UndoConfigItem(grpcKit.Ctx, &pbds.UndoConfigItemReq{
Id: req.Id,
Attachment: &pbci.ConfigItemAttachment{
BizId: req.BizId,
AppId: req.AppId,
},
})
if err != nil {
return nil, err
}
return &pbcs.UndoConfigItemResp{}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (s *Service) ListAppBoundTmplRevisions(ctx context.Context,
tmplRevisionMap[t.ID] = t
}

/// combine resp details
// combine resp details
details := make([]*pbatb.AppBoundTmplRevision, 0)
for _, b := range atb[0].Spec.Bindings {
for _, r := range b.TemplateRevisions {
Expand Down Expand Up @@ -606,12 +606,12 @@ func (s *Service) getPBSForCascade(kt *kit.Kit, tx *gen.QueryTx, bindings []*tab
logs.Errorf("list template revision names by template ids failed, err: %v, rid: %s", err, kt.Rid)
return nil, err
}
// template id => the latest template revision id
// template id => the latest template revision
latestRevisionMap := getLatestTmplRevisions(latestTmplRevisions)

for tID, rID := range latestRevisionMap {
pbs.TemplateRevisionIDs = append(pbs.TemplateRevisionIDs, rID)
allTmplRevisionMap[tID] = rID
for tID, r := range latestRevisionMap {
pbs.TemplateRevisionIDs = append(pbs.TemplateRevisionIDs, r.ID)
allTmplRevisionMap[tID] = r.ID
}

for tsID, tmpls := range allTmplMap {
Expand Down
Loading

0 comments on commit 776de1d

Please sign in to comment.