Skip to content

Commit d910e42

Browse files
committed
feat(k8s-dbs): addoncluster 模板元数据管理 #11232
1 parent a2e94b7 commit d910e42

17 files changed

+794
-9
lines changed

dbm-services/k8s-dbs/metadata/api/controller/addon_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020
package controller
2121

2222
import (
23-
entity2 "k8s-dbs/common/entity"
23+
commentity "k8s-dbs/common/entity"
2424
"k8s-dbs/core/entity"
2525
"k8s-dbs/core/errors"
2626
"k8s-dbs/metadata/api/vo/req"
@@ -54,7 +54,7 @@ func (a *AddonController) ListAddons(ctx *gin.Context) {
5454
fetchSize = metaconst.DefaultFetchSize // 如果转换失败,使用默认值
5555
}
5656
fetchSize = min(fetchSize, metaconst.MaxFetchSize)
57-
pagination := entity2.Pagination{Limit: fetchSize}
57+
pagination := commentity.Pagination{Limit: fetchSize}
5858
addons, err := a.addonProvider.ListStorageAddons(pagination)
5959
if err != nil {
6060
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.GetMetaDataErr, err))
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
TencentBlueKing is pleased to support the open source community by making
3+
蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
5+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
6+
7+
Licensed under the MIT License (the "License");
8+
you may not use this file except in compliance with the License.
9+
10+
You may obtain a copy of the License at
11+
https://opensource.org/licenses/MIT
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package controller
21+
22+
import (
23+
commentity "k8s-dbs/common/entity"
24+
"k8s-dbs/core/entity"
25+
"k8s-dbs/core/errors"
26+
"k8s-dbs/metadata/api/vo/req"
27+
"k8s-dbs/metadata/api/vo/resp"
28+
metaconst "k8s-dbs/metadata/constant"
29+
"k8s-dbs/metadata/provider"
30+
entitys "k8s-dbs/metadata/provider/entity"
31+
"strconv"
32+
33+
"github.com/gin-gonic/gin"
34+
"github.com/jinzhu/copier"
35+
36+
commconst "k8s-dbs/common/api/constant"
37+
)
38+
39+
// AddonClusterVersionController manages metadata for addons.
40+
type AddonClusterVersionController struct {
41+
acVersionProvider provider.AddonClusterVersionProvider
42+
}
43+
44+
// NewAddonClusterVersionController creates a new instance of AddonClusterVersionController.
45+
func NewAddonClusterVersionController(
46+
acVersionProvider provider.AddonClusterVersionProvider,
47+
) *AddonClusterVersionController {
48+
return &AddonClusterVersionController{acVersionProvider}
49+
}
50+
51+
// ListAcVersions 获取 addon cluster version 列表
52+
func (a *AddonClusterVersionController) ListAcVersions(ctx *gin.Context) {
53+
sizeStr := ctx.DefaultQuery("size", metaconst.DefaultFetchSizeStr)
54+
fetchSize, err := strconv.Atoi(sizeStr)
55+
if err != nil {
56+
fetchSize = metaconst.DefaultFetchSize // 如果转换失败,使用默认值
57+
}
58+
fetchSize = min(fetchSize, metaconst.MaxFetchSize)
59+
pagination := commentity.Pagination{Limit: fetchSize}
60+
acVersions, err := a.acVersionProvider.ListAcVersion(pagination)
61+
if err != nil {
62+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.GetMetaDataErr, err))
63+
return
64+
}
65+
var data []resp.AddonClusterVersionRespVo
66+
if err := copier.Copy(&data, acVersions); err != nil {
67+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.GetMetaDataErr, err))
68+
return
69+
}
70+
entity.SuccessResponse(ctx, data, commconst.Success)
71+
}
72+
73+
// GetAcVersion 根据 ID 查找 addon cluster version
74+
func (a *AddonClusterVersionController) GetAcVersion(ctx *gin.Context) {
75+
idParam := ctx.Param("id")
76+
id, err := strconv.ParseUint(idParam, 10, 64)
77+
if err != nil {
78+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.GetMetaDataErr, err))
79+
return
80+
}
81+
addon, err := a.acVersionProvider.FindAcVersionByID(id)
82+
if err != nil {
83+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.GetMetaDataErr, err))
84+
return
85+
}
86+
var data resp.AddonClusterVersionRespVo
87+
if err := copier.Copy(&data, addon); err != nil {
88+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.GetMetaDataErr, err))
89+
return
90+
}
91+
entity.SuccessResponse(ctx, data, commconst.Success)
92+
}
93+
94+
// CreateAcVersion 创建 addon cluster version
95+
func (a *AddonClusterVersionController) CreateAcVersion(ctx *gin.Context) {
96+
var acVersionVo req.AddonClusterVersionReqVo
97+
if err := ctx.ShouldBindJSON(&acVersionVo); err != nil {
98+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.CreateMetaDataErr, err))
99+
return
100+
}
101+
var acVersionEntity entitys.AddonClusterVersionEntity
102+
if err := copier.Copy(&acVersionEntity, &acVersionVo); err != nil {
103+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.CreateMetaDataErr, err))
104+
return
105+
}
106+
added, err := a.acVersionProvider.CreateAcVersion(&acVersionEntity)
107+
if err != nil {
108+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.CreateMetaDataErr, err))
109+
return
110+
}
111+
var data resp.AddonClusterVersionRespVo
112+
if err := copier.Copy(&data, added); err != nil {
113+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.CreateMetaDataErr, err))
114+
return
115+
}
116+
entity.SuccessResponse(ctx, data, commconst.Success)
117+
}
118+
119+
// UpdateAcVersion 更新 addon cluster version.
120+
func (a *AddonClusterVersionController) UpdateAcVersion(ctx *gin.Context) {
121+
idParam := ctx.Param("id")
122+
id, err := strconv.ParseUint(idParam, 10, 64)
123+
if err != nil {
124+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.UpdateMetaDataErr, err))
125+
return
126+
}
127+
var acVersionVo req.AddonClusterVersionReqVo
128+
if err := ctx.ShouldBindJSON(&acVersionVo); err != nil {
129+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.UpdateMetaDataErr, err))
130+
return
131+
}
132+
var acVersionEntity entitys.AddonClusterVersionEntity
133+
if err := copier.Copy(&acVersionEntity, acVersionVo); err != nil {
134+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.UpdateMetaDataErr, err))
135+
return
136+
}
137+
acVersionEntity.ID = id
138+
rows, err := a.acVersionProvider.UpdateAcVersion(&acVersionEntity)
139+
if err != nil {
140+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.UpdateMetaDataErr, err))
141+
return
142+
}
143+
entity.SuccessResponse(ctx, map[string]uint64{"rows": rows}, commconst.Success)
144+
}
145+
146+
// DeleteAcVersion 删除 addon cluster version.
147+
func (a *AddonClusterVersionController) DeleteAcVersion(ctx *gin.Context) {
148+
idParam := ctx.Param("id")
149+
id, err := strconv.ParseUint(idParam, 10, 64)
150+
if err != nil {
151+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.DeleteMetaDataErr, err))
152+
return
153+
}
154+
rows, err := a.acVersionProvider.DeleteAcVersionByID(id)
155+
if err != nil {
156+
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.DeleteMetaDataErr, err))
157+
return
158+
}
159+
entity.SuccessResponse(ctx, map[string]uint64{"rows": rows}, commconst.Success)
160+
}

dbm-services/k8s-dbs/metadata/api/controller/cluster_operation_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ package controller
2121

2222
import (
2323
commconst "k8s-dbs/common/api/constant"
24-
entity2 "k8s-dbs/common/entity"
24+
commentity "k8s-dbs/common/entity"
2525
"k8s-dbs/core/entity"
2626
"k8s-dbs/core/errors"
2727
"k8s-dbs/metadata/api/vo/req"
@@ -53,7 +53,7 @@ func (c *ClusterOperationController) ListClusterOperations(ctx *gin.Context) {
5353
fetchSize = metaconst.DefaultFetchSize // 如果转换失败,使用默认值
5454
}
5555
fetchSize = min(fetchSize, metaconst.MaxFetchSize)
56-
pagination := entity2.Pagination{Limit: fetchSize}
56+
pagination := commentity.Pagination{Limit: fetchSize}
5757
clusterOps, err := c.provider.ListClusterOperations(pagination)
5858
if err != nil {
5959
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.GetMetaDataErr, err))

dbm-services/k8s-dbs/metadata/api/controller/component_operation_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ package controller
2121

2222
import (
2323
commconst "k8s-dbs/common/api/constant"
24-
entity2 "k8s-dbs/common/entity"
24+
commentity "k8s-dbs/common/entity"
2525
"k8s-dbs/core/entity"
2626
"k8s-dbs/core/errors"
2727
"k8s-dbs/metadata/api/vo/req"
@@ -53,7 +53,7 @@ func (c *ComponentOperationController) ListComponentOperations(ctx *gin.Context)
5353
fetchSize = metaconst.DefaultFetchSize // 如果转换失败,使用默认值
5454
}
5555
fetchSize = min(fetchSize, metaconst.MaxFetchSize)
56-
pagination := entity2.Pagination{Limit: fetchSize}
56+
pagination := commentity.Pagination{Limit: fetchSize}
5757
clusterOps, err := c.provider.ListComponentOperations(pagination)
5858
if err != nil {
5959
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.GetMetaDataErr, err))

dbm-services/k8s-dbs/metadata/api/controller/operation_definition_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ package controller
2121

2222
import (
2323
commconst "k8s-dbs/common/api/constant"
24-
entity2 "k8s-dbs/common/entity"
24+
commentity "k8s-dbs/common/entity"
2525
"k8s-dbs/core/entity"
2626
"k8s-dbs/core/errors"
2727
"k8s-dbs/metadata/api/vo/req"
@@ -53,7 +53,7 @@ func (o *OperationDefinitionController) ListOperationDefinitions(ctx *gin.Contex
5353
fetchSize = metaconst.DefaultFetchSize // 如果转换失败,使用默认值
5454
}
5555
fetchSize = min(fetchSize, metaconst.MaxFetchSize)
56-
pagination := entity2.Pagination{Limit: fetchSize}
56+
pagination := commentity.Pagination{Limit: fetchSize}
5757
opDefs, err := o.provider.ListOperationDefinitions(pagination)
5858
if err != nil {
5959
entity.ErrorResponse(ctx, errors.NewGlobalError(errors.GetMetaDataErr, err))
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
TencentBlueKing is pleased to support the open source community by making
3+
蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
5+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
6+
7+
Licensed under the MIT License (the "License");
8+
you may not use this file except in compliance with the License.
9+
10+
You may obtain a copy of the License at
11+
https://opensource.org/licenses/MIT
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package req
21+
22+
import "time"
23+
24+
// AddonClusterVersionReqVo request vo 定义
25+
type AddonClusterVersionReqVo struct {
26+
AddonID uint64 `json:"addonId" binding:"required"`
27+
Version string `json:"version" binding:"required"`
28+
AddonClusterName string `json:"addonClusterName" binding:"required"`
29+
Active bool `json:"active"`
30+
Description string `json:"description" binding:"required"`
31+
CreatedBy string `json:"createdBy"`
32+
CreatedAt time.Time `json:"createdAt"`
33+
UpdatedBy string `json:"updatedBy"`
34+
UpdatedAt time.Time `json:"updatedAt"`
35+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
TencentBlueKing is pleased to support the open source community by making
3+
蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
5+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
6+
7+
Licensed under the MIT License (the "License");
8+
you may not use this file except in compliance with the License.
9+
10+
You may obtain a copy of the License at
11+
https://opensource.org/licenses/MIT
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package resp
21+
22+
import "time"
23+
24+
// AddonClusterVersionRespVo response vo 定义
25+
type AddonClusterVersionRespVo struct {
26+
ID uint64 `json:"id"`
27+
AddonID uint64 `json:"addonId"`
28+
Version string `json:"version"`
29+
AddonClusterName string `json:"addonClusterName"`
30+
Active bool `json:"active"`
31+
Description string `json:"description"`
32+
CreatedBy string `json:"createdBy"`
33+
CreatedAt time.Time `json:"createdAt"`
34+
UpdatedBy string `json:"updatedBy"`
35+
UpdatedAt time.Time `json:"updatedAt"`
36+
}

dbm-services/k8s-dbs/metadata/constant/meta_const.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ const (
3939
TbAddonClusterHelmRepo = "tb_addoncluster_helm_repository"
4040
TbAddonHelmRepo = "tb_addon_helm_repository"
4141
TbK8sClusterAddons = "tb_k8s_cluster_addons"
42+
TbAddonClusterVersion = "tb_addoncluster_version"
4243
)

0 commit comments

Comments
 (0)