Skip to content
Open
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
95 changes: 95 additions & 0 deletions bcs-services/bcs-platform-manager/pkg/api/cloudvpc/cloudvpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

// Package cloudvpc cloudvpc operate
package cloudvpc

import (
"context"

"github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/component/bcs"
)

// ListCloudVPCReq list cloud vpc request
type ListCloudVPCReq struct {
CloudID string `json:"cloudID" in:"query=cloudID"`
Region string `json:"region" in:"query=region"`
VpcID string `json:"vpcID" in:"query=vpcID"`
NetworkType string `json:"networkType" in:"query=networkType"`
BusinessID string `json:"businessID" in:"query=businessID"`
}

// DeleteCloudVPCReq delete cloud vpc request
type DeleteCloudVPCReq struct {
CloudID string `json:"cloudID" in:"query=cloudID"`
VpcID string `json:"vpcID" in:"query=vpcID"`
}

// ListCloudVPC 获取VPC列表
// @Summary 获取VPC列表
// @Tags Logs
// @Produce json
// @Success 200 {array} k8sclient.Container
// @Router /cloudvpc [get]
func ListCloudVPC(c context.Context, req *ListCloudVPCReq) (*[]*bcs.CloudVPC, error) {
vpcs, err := bcs.ListCloudVPC(req.CloudID, req.Region, req.VpcID, req.NetworkType, req.BusinessID)
if err != nil {
return nil, err
}

return &vpcs, nil
}

// CreateCloudVPC 创建VPC
// @Summary 创建VPC
// @Tags Logs
// @Produce json
// @Success 200 {array} k8sclient.Container
// @Router /cloudvpc [post]
func CreateCloudVPC(c context.Context, req *bcs.CreateCloudVPCReq) (*bool, error) {
result, err := bcs.CreateCloudVPC(req)
if err != nil {
return nil, err
}

return &result, nil
}

// UpdateCloudVPC 更新VPC
// @Summary 更新VPC
// @Tags Logs
// @Produce json
// @Success 200 {array} k8sclient.Container
// @Router /cloudvpc [put]
func UpdateCloudVPC(c context.Context, req *bcs.UpdateCloudVPCReq) (*bcs.CloudVPC, error) {
vpc, err := bcs.UpdateCloudVPC(req)
if err != nil {
return nil, err
}

return vpc, nil
}

// DeleteCloudVPC 删除VPC
// @Summary 更新VPC
// @Tags Logs
// @Produce json
// @Success 200 {array} k8sclient.Container
// @Router /cloudvpc [delete]
func DeleteCloudVPC(c context.Context, req *DeleteCloudVPCReq) (*bcs.CloudVPC, error) {
result, err := bcs.DeleteCloudVPC(req.CloudID, req.VpcID)
if err != nil {
return nil, err
}

return result, nil
}
19 changes: 18 additions & 1 deletion bcs-services/bcs-platform-manager/pkg/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
"github.com/go-chi/chi/v5"
httpSwagger "github.com/swaggo/http-swagger"

"github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/api/cloudvpc"
"github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/api/pod"
"github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/api/templateconfig"
"github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/config"
"github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/rest"
"github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/rest/middleware"
Expand Down Expand Up @@ -110,14 +112,29 @@ func (a *APIServer) newRoutes() http.Handler {
func registerRoutes() http.Handler {
r := chi.NewRouter()
// 日志相关接口

r.Route("/projects/{projectId}/clusters/{clusterId}", func(route chi.Router) {
route.Use(middleware.AuthenticationRequired, middleware.ProjectParse, middleware.ClusterAuthorization)
route.Use(middleware.Tracing, middleware.Audit)

route.Get("/containers", rest.Handle(pod.GetPodContainers))
route.Post("/containers", rest.Handle(pod.CreateContainers))
})

// vpc 相关接口
r.Route("/cloudvpc", func(route chi.Router) {
route.Use(middleware.AuthenticationRequired, middleware.Tracing, middleware.Audit)

route.Post("/", rest.Handle(cloudvpc.CreateCloudVPC))
route.Put("/", rest.Handle(cloudvpc.UpdateCloudVPC))
})

// templateconfig 相关接口
r.Route("/templateconfigs", func(route chi.Router) {
route.Use(middleware.AuthenticationRequired, middleware.Tracing, middleware.Audit)

route.Post("/", rest.Handle(templateconfig.CreateTemplateConfig))
route.Delete("/{templateConfigID}", rest.Handle(templateconfig.DeleteTemplateConfig))
})
return r
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

// Package templateconfig templateconfig operate
package templateconfig

import (
"context"

"github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/component/bcs"
)

// DeleteTemplateConfigReq delete template config request
type DeleteTemplateConfigReq struct {
TemplateConfigID string `json:"cloudID" in:"path=templateConfigID"`
BusinessID string `json:"businessID" in:"query=businessID"`
ProjectID string `json:"projectID" in:"query=projectID"`
}

// ListTemplateConfigReq list template config request
type ListTemplateConfigReq struct {
BusinessID string `json:"businessID" in:"query=businessID"`
ProjectID string `json:"projectID" in:"query=projectID"`
ClusterID string `json:"clusterID" in:"query=clusterID"`
Provider string `json:"provider" in:"query=provider"`
ConfigType string `json:"configType" in:"query=configType"`
}

// CreateTemplateConfig 创建TemplateConfig
// @Summary 创建TemplateConfig
// @Tags Logs
// @Produce json
// @Success 200 {array} k8sclient.Container
// @Router /templateConfig [post]
func CreateTemplateConfig(c context.Context, req *bcs.CreateTemplateConfigReq) (*bool, error) {
result, err := bcs.CreateTemplateConfig(req)
if err != nil {
return nil, err
}

return &result, nil
}

// DeleteTemplateConfig 删除TemplateConfig
// @Summary 删除TemplateConfig
// @Tags Logs
// @Produce json
// @Success 200 {array} k8sclient.Container
// @Router /templateConfig/{templateConfigID} [delete]
func DeleteTemplateConfig(c context.Context, req *DeleteTemplateConfigReq) (*bool, error) {
result, err := bcs.DeleteTemplateConfig(req.TemplateConfigID, req.BusinessID, req.ProjectID)
if err != nil {
return nil, err
}

return &result, nil
}

// ListTemplateConfig 获取TemplateConfig列表
// @Summary 获取TemplateConfig列表
// @Tags Logs
// @Produce json
// @Success 200 {array} k8sclient.Container
// @Router /templateConfig/{templateConfigID} [get]
func ListTemplateConfig(c context.Context, req *ListTemplateConfigReq) (*[]*bcs.TemplateConfigInfo, error) {
result, err := bcs.ListTemplateConfig(req.BusinessID, req.ProjectID, req.ClusterID, req.Provider, req.ConfigType)
if err != nil {
return nil, err
}

return &result, nil
}
2 changes: 1 addition & 1 deletion bcs-services/bcs-platform-manager/pkg/component/bcs/bcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func ListClusters() {
}

var result []*Cluster
if err = component.UnmarshalBKResult(resp, &result); err != nil {
if err = component.UnmarshalBKData(resp, &result); err != nil {
blog.Errorf("unmarshal clusters error, %s", err.Error())
return
}
Expand Down
Loading
Loading