From 2bd6ffd3815af26f33f0336968e545c0643600e0 Mon Sep 17 00:00:00 2001 From: LidolLxf <13660354959@163.com> Date: Fri, 22 May 2026 15:53:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20platform-manager=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=BD=91=E7=BB=9C=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3=E5=8F=8A?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bcs-services/bcs-platform-manager/cmd/api.go | 25 +- bcs-services/bcs-platform-manager/cmd/root.go | 2 +- bcs-services/bcs-platform-manager/go.mod | 9 +- .../bcs-platform-manager/pkg/api/cloud/vpc.go | 279 ++++++++++++++++++ .../bcs-platform-manager/pkg/api/routes.go | 34 ++- .../pkg/component/bcs/bcs.go | 177 ----------- .../cloud.go} | 34 ++- .../component/bcs/clustermanager/cloudvpc.go | 154 ++++++++++ .../component/bcs/clustermanager/cluster.go | 86 ++++++ .../pkg/component/bcs/project.go | 75 ----- .../pkg/component/email/email.go | 98 ++++++ .../pkg/component/sms/sms.go | 66 +++++ .../bcs-platform-manager/pkg/config/base.go | 2 +- .../bcs-platform-manager/pkg/config/config.go | 34 ++- .../bcs-platform-manager/pkg/config/env.go | 14 + .../bcs-platform-manager/pkg/config/sign.go | 38 +++ .../bcs-platform-manager/pkg/config/task.go | 34 +++ .../bcs-platform-manager/pkg/config/tls.go | 36 +++ .../pkg/cron/client/client.go | 63 ++++ .../bcs_test.go => cron/options/constant.go} | 26 +- .../pkg/cron/options/option.go | 52 ++++ .../pkg/cron/server/server.go | 55 ++++ .../pkg/cron/task/bcssubnetresource.go | 143 +++++++++ .../pkg/cron/task/task.go | 50 ++++ .../pkg/discovery/discovery.go | 37 +++ .../bcs-platform-manager/pkg/types/cluster.go | 42 +++ .../pkg/types/createcloudsubnets.go | 61 ++++ .../pkg/types/deletecloudsubnets.go | 35 +++ .../pkg/types/listcloudsubnets.go | 52 ++++ .../pkg/types/listcloudvpccluster.go | 56 ++++ .../pkg/types/listcloudvpcspage.go | 109 +++++++ .../pkg/types/updatecloudsubnets.go | 38 +++ .../pkg/types/updatecloudvpcs.go | 40 +++ install/helm/bcs-platform-manager/Chart.yaml | 4 +- install/helm/bcs-platform-manager/README.md | 12 +- .../templates/deployment.yaml | 8 +- install/helm/bcs-platform-manager/values.yaml | 21 +- 37 files changed, 1796 insertions(+), 305 deletions(-) create mode 100644 bcs-services/bcs-platform-manager/pkg/api/cloud/vpc.go delete mode 100644 bcs-services/bcs-platform-manager/pkg/component/bcs/bcs.go rename bcs-services/bcs-platform-manager/pkg/component/bcs/{project_test.go => clustermanager/cloud.go} (54%) delete mode 100644 bcs-services/bcs-platform-manager/pkg/component/bcs/project.go create mode 100644 bcs-services/bcs-platform-manager/pkg/component/email/email.go create mode 100644 bcs-services/bcs-platform-manager/pkg/component/sms/sms.go create mode 100644 bcs-services/bcs-platform-manager/pkg/config/sign.go create mode 100644 bcs-services/bcs-platform-manager/pkg/config/task.go create mode 100644 bcs-services/bcs-platform-manager/pkg/config/tls.go create mode 100644 bcs-services/bcs-platform-manager/pkg/cron/client/client.go rename bcs-services/bcs-platform-manager/pkg/{component/bcs/bcs_test.go => cron/options/constant.go} (60%) create mode 100644 bcs-services/bcs-platform-manager/pkg/cron/options/option.go create mode 100644 bcs-services/bcs-platform-manager/pkg/cron/server/server.go create mode 100644 bcs-services/bcs-platform-manager/pkg/cron/task/bcssubnetresource.go create mode 100644 bcs-services/bcs-platform-manager/pkg/cron/task/task.go create mode 100644 bcs-services/bcs-platform-manager/pkg/types/createcloudsubnets.go create mode 100644 bcs-services/bcs-platform-manager/pkg/types/deletecloudsubnets.go create mode 100644 bcs-services/bcs-platform-manager/pkg/types/listcloudsubnets.go create mode 100644 bcs-services/bcs-platform-manager/pkg/types/listcloudvpccluster.go create mode 100644 bcs-services/bcs-platform-manager/pkg/types/listcloudvpcspage.go create mode 100644 bcs-services/bcs-platform-manager/pkg/types/updatecloudsubnets.go create mode 100644 bcs-services/bcs-platform-manager/pkg/types/updatecloudvpcs.go diff --git a/bcs-services/bcs-platform-manager/cmd/api.go b/bcs-services/bcs-platform-manager/cmd/api.go index aa2ab0a468..dd1a547a7e 100644 --- a/bcs-services/bcs-platform-manager/cmd/api.go +++ b/bcs-services/bcs-platform-manager/cmd/api.go @@ -26,6 +26,8 @@ import ( "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/component" "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/component/cmdb" "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/config" + cronClient "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/cron/client" + cronServer "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/cron/server" "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/discovery" "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/storage" "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/utils" @@ -63,23 +65,36 @@ func runCmd(cmd *cobra.Command, cmdFunc CommandFunc) { // runAPIServer 启动api服务 func runAPIServer(ctx context.Context, g *run.Group, opt *option) error { addrIPv6 := utils.GetIPv6AddrFromEnv() - server, err := api.NewAPIServer(ctx, config.G.Base.BindAddress, config.G.Base.HttpPort, addrIPv6) - if err != nil { - return errors.Wrap(err, "apiserver") - } - sd, err := discovery.NewServiceDiscovery(ctx, platformManager, version.BcsVersion, config.G.Base.BindAddress, config.G.Base.HttpPort, addrIPv6) if err != nil { return err } + server, err := api.NewAPIServer(ctx, config.G.Base.BindAddress, config.G.Base.HttpPort, addrIPv6, sd.TLSConfig) + if err != nil { + return errors.Wrap(err, "apiserver") + } + InitClient() + // init cron task + scheduler, err := cronClient.NewScheduler() + if err != nil { + return err + } + + // start scheduler + g.Add(func() error { return scheduler.Run() }, func(error) { scheduler.Shutdown() }) // 启动 apiserver g.Add(server.Run, func(err error) { _ = server.Close(); component.GetAuditClient().Close() }) g.Add(sd.Run, func(error) {}) + // start asynq server + err = cronServer.NewAsynqServer() + if err != nil { + return err + } return nil } diff --git a/bcs-services/bcs-platform-manager/cmd/root.go b/bcs-services/bcs-platform-manager/cmd/root.go index ca64c8435f..436728047c 100644 --- a/bcs-services/bcs-platform-manager/cmd/root.go +++ b/bcs-services/bcs-platform-manager/cmd/root.go @@ -35,7 +35,7 @@ var ( // Used for flags. cfgFile string appName = "bcs-platform-manager" - platformManager = "bcsplatformmanager" + platformManager = "platformmanager" rootCmd = &cobra.Command{ Use: appName, diff --git a/bcs-services/bcs-platform-manager/go.mod b/bcs-services/bcs-platform-manager/go.mod index 8355804a68..ca7ebf8d21 100644 --- a/bcs-services/bcs-platform-manager/go.mod +++ b/bcs-services/bcs-platform-manager/go.mod @@ -4,6 +4,7 @@ go 1.23.0 replace ( configcenter => github.com/Tencent/bk-cmdb v0.0.0-20250710063351-e7cb8e8963fa + github.com/Tencent/bk-bcs/bcs-common => github.com/LidolLxf/bk-bcs/bcs-common v0.0.0-20260520092228-899beff9282c k8s.io/client-go => k8s.io/client-go v0.32.2 ) @@ -23,6 +24,7 @@ require ( github.com/golang-jwt/jwt/v4 v4.5.2 github.com/golang/protobuf v1.5.4 github.com/google/uuid v1.6.0 + github.com/hibiken/asynq v0.25.1 github.com/mitchellh/go-homedir v1.1.0 github.com/oklog/run v1.1.0 github.com/parnurzeal/gorequest v0.2.16 @@ -30,8 +32,10 @@ require ( github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.9.1 github.com/spf13/viper v1.20.1 - github.com/stretchr/testify v1.10.0 github.com/swaggo/http-swagger v1.3.4 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.1.49 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.1.0 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.1.49 go-micro.dev/v4 v4.10.2 go.mongodb.org/mongo-driver v1.9.1 go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo v0.33.0 @@ -138,11 +142,12 @@ require ( github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect - github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.19.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.48.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect + github.com/redis/go-redis/v9 v9.7.0 // indirect + github.com/robfig/cron/v3 v3.0.1 // indirect github.com/rs/xid v1.4.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.7.0 // indirect diff --git a/bcs-services/bcs-platform-manager/pkg/api/cloud/vpc.go b/bcs-services/bcs-platform-manager/pkg/api/cloud/vpc.go new file mode 100644 index 0000000000..a2adf13ceb --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/api/cloud/vpc.go @@ -0,0 +1,279 @@ +/* + * 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 cloud cloud operate +package cloud + +import ( + "context" + + cluproto "github.com/Tencent/bk-bcs/bcs-common/pkg/bcsapi/clustermanager" + + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/component/bcs/clustermanager" + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/types" +) + +// ListCloudVpcsPage 获取云VPC分页列表 +// @Summary 获取云VPC分页列表 +// @Tags Cloud +// @Produce json +// @Success 200 {array} types.ListCloudVpcsPageResponse +// @Router /clouds/{cloudID}/vpcs/page [get] +func ListCloudVpcsPage( + c context.Context, req *types.ListCloudVpcsPageRequest) (*types.ListCloudVpcsPageResponse, error) { + sr, err := clustermanager.ListCloudVpcsPage(c, &cluproto.ListCloudVpcsPageRequest{ + CloudID: req.CloudID, + Region: req.Region, + AccountID: req.AccountID, + VpcID: req.VpcID, + ResourceGroupName: req.ResourceGroupName, + VpcName: req.VpcName, + Offset: req.Offset, + Limit: req.Limit, + }) + if err != nil { + return nil, err + } + cloudVpcs := make([]types.CloudVpcs, 0) + for _, vpc := range sr.Data { + cloudVpcs = append(cloudVpcs, types.CloudVpcs{ + VpcName: vpc.VpcName, + VpcID: vpc.VpcID, + Region: vpc.Region, + OverlayCidr: vpc.OverlayCidr, + AvailableOverlayIpNum: vpc.AvailableOverlayIpNum, + AvailableOverlayCidr: vpc.AvailableOverlayCidr, + TotalOverlayIpNum: vpc.TotalOverlayIpNum, + UnderlayCidr: vpc.UnderlayCidr, + AvailableUnderlayIpNum: vpc.AvailableUnderlayIpNum, + AvailableUnderlayCidr: vpc.AvailableUnderlayCidr, + TotalUnderlayIpNum: vpc.TotalUnderlayIpNum, + OverlayIpUsageRate: calculateUsageRate(vpc.AvailableOverlayIpNum, vpc.TotalOverlayIpNum), + UnderlayIpUsageRate: calculateUsageRate(vpc.AvailableUnderlayIpNum, vpc.TotalUnderlayIpNum), + CreateTime: vpc.CreateTime, + OverlayIPCidr: convertOverlayIPCidr(vpc.OverlayIPCidr), + }) + } + return &types.ListCloudVpcsPageResponse{ + Total: sr.Total, + CloudVpcs: cloudVpcs, + }, nil +} + +// calculateUsageRate calculate usage rate +func calculateUsageRate(available, total uint32) float64 { + if total == 0 { + return 0 + } + return 1 - (float64(available) / float64(total)) +} + +// convertOverlayIPCidr convert overlay ip cidr from proto to types +func convertOverlayIPCidr(proto []*cluproto.OverlayIPCidr) []types.OverlayIPCidr { + overlayIPCidr := make([]types.OverlayIPCidr, 0) + for _, ipCidr := range proto { + overlayIPCidr = append(overlayIPCidr, types.OverlayIPCidr{ + Cidr: ipCidr.Cidr, + IpNum: ipCidr.IpNum, + }) + } + return overlayIPCidr +} + +// ListCloudVpcCluster 获取云VPC关联的集群列表 +// @Summary 获取云VPC关联的集群列表 +// @Tags Cloud +// @Produce json +// @Success 200 {array} types.ListCloudVpcClusterResponse +// @Router /clouds/{cloudID}/vpc/{vpcID}/cluster [get] +func ListCloudVpcCluster( + c context.Context, req *types.ListCloudVpcClusterRequest) (*types.ListCloudVpcClusterResponse, error) { + sr, err := clustermanager.ListCloudVpcCluster(c, &cluproto.ListCloudVpcClusterRequest{ + CloudID: req.CloudID, + Region: req.Region, + AccountID: req.AccountID, + VpcID: req.VpcID, + Offset: req.Offset, + Limit: req.Limit, + }) + if err != nil { + return nil, err + } + cloudCluster := make([]types.CloudCluster, 0) + for _, vpc := range sr.Data { + cloudCluster = append(cloudCluster, types.CloudCluster{ + ClusterID: vpc.ClusterID, + OverlayIPCidr: convertOverlayIPCidr(vpc.OverlayIPCidr), + }) + } + return &types.ListCloudVpcClusterResponse{ + Total: sr.Total, + CloudCluster: cloudCluster, + }, nil +} + +// UpdateCloudVpcs 更新云VPC +// @Summary 更新云VPC +// @Tags Cloud +// @Produce json +// @Success 200 {array} types.UpdateCloudVpcsResponse +// @Router /clouds/{cloudID}/vpc/{vpcID} [put] +func UpdateCloudVpcs( + c context.Context, req *types.UpdateCloudVpcsRequest) (*types.UpdateCloudVpcsResponse, error) { + _, err := clustermanager.UpdateCloudVpcs(c, &cluproto.UpdateCloudVpcsRequest{ + CloudID: req.CloudID, + Region: req.Region, + AccountID: req.AccountID, + VpcID: req.VpcID, + ResourceGroupName: req.ResourceGroupName, + VpcName: req.VpcName, + }) + if err != nil { + return nil, err + } + return &types.UpdateCloudVpcsResponse{}, nil +} + +// ListCloudSubnets 获取云子网列表 +// @Summary 获取云子网列表 +// @Tags Cloud +// @Produce json +// @Success 200 {array} types.ListCloudSubnetsResponse +// @Router /clouds/{cloudID}/vpc/{vpcID}/subnets [get] +func ListCloudSubnets( + c context.Context, req *types.ListCloudSubnetsRequest) (*types.ListCloudSubnetsResponse, error) { + cloudSubnets, err := clustermanager.ListCloudSubnets(c, &cluproto.ListCloudSubnetsRequest{ + CloudID: req.CloudID, + Region: req.Region, + AccountID: req.AccountID, + VpcID: req.VpcID, + }) + if err != nil { + return nil, err + } + + cloudSubnetsData := make([]types.ListCloudSubnets, 0) + for _, vpc := range cloudSubnets { + cloudSubnetsData = append(cloudSubnetsData, types.ListCloudSubnets{ + SubnetName: vpc.SubnetName, + SubnetID: vpc.SubnetID, + VpcID: vpc.VpcID, + CidrRange: vpc.CidrRange, + Ipv6CidrRange: vpc.Ipv6CidrRange, + Zone: vpc.Zone, + AvailableIPAddressCount: vpc.AvailableIPAddressCount, + ZoneName: vpc.ZoneName, + Cluster: convertCluster(vpc.Cluster), + HwNeutronSubnetID: vpc.HwNeutronSubnetID, + TotalIpAddressCount: vpc.TotalIpAddressCount, + }) + } + + return &types.ListCloudSubnetsResponse{ + Total: uint32(len(cloudSubnetsData)), + Subnets: cloudSubnetsData, + }, nil +} + +// CreateCloudSubnets 创建云子网 +// @Summary 创建云子网 +// @Tags Cloud +// @Produce json +// @Success 200 {array} types.CreateCloudSubnetsResponse +// @Router /clouds/{cloudID}/vpc/{vpcID}/subnets [post] +func CreateCloudSubnets( + c context.Context, req *types.CreateCloudSubnetsRequest) (*types.CreateCloudSubnetsResponse, error) { + cloudSubnets, err := clustermanager.CreateCloudSubnets(c, &cluproto.CreateCloudSubnetsRequest{ + CloudID: req.CloudID, + Region: req.Region, + AccountID: req.AccountID, + VpcID: req.VpcID, + SubnetName: req.SubnetName, + CidrBlock: req.CidrBlock, + Zone: req.Zone, + }) + if err != nil { + return nil, err + } + + return &types.CreateCloudSubnetsResponse{ + Subnet: types.CloudSubnets{ + SubnetName: cloudSubnets.Data.SubnetName, + SubnetID: cloudSubnets.Data.SubnetID, + VpcID: cloudSubnets.Data.VpcID, + CidrRange: cloudSubnets.Data.CidrRange, + Ipv6CidrRange: cloudSubnets.Data.Ipv6CidrRange, + Zone: cloudSubnets.Data.Zone, + AvailableIPAddressCount: cloudSubnets.Data.AvailableIPAddressCount, + ZoneName: cloudSubnets.Data.ZoneName, + Cluster: convertCluster(cloudSubnets.Data.Cluster), + HwNeutronSubnetID: cloudSubnets.Data.HwNeutronSubnetID, + TotalIpAddressCount: cloudSubnets.Data.TotalIpAddressCount, + }, + }, nil +} + +func convertCluster(proto *cluproto.ClusterInfo) types.ClusterInfo { + if proto != nil { + return types.ClusterInfo{ + ClusterName: proto.ClusterName, + ClusterID: proto.ClusterID, + } + } + return types.ClusterInfo{ + ClusterName: "", + ClusterID: "", + } +} + +// UpdateCloudSubnets 更新云子网 +// @Summary 更新云子网 +// @Tags Cloud +// @Produce json +// @Success 200 {array} types.UpdateCloudSubnetsResponse +// @Router /clouds/{cloudID}/vpc/{vpcID}/subnets [put] +func UpdateCloudSubnets( + c context.Context, req *types.UpdateCloudSubnetsRequest) (*types.UpdateCloudSubnetsResponse, error) { + _, err := clustermanager.UpdateCloudSubnets(c, &cluproto.UpdateCloudSubnetsRequest{ + CloudID: req.CloudID, + Region: req.Region, + AccountID: req.AccountID, + SubnetName: req.SubnetName, + SubnetID: req.SubnetID, + }) + if err != nil { + return nil, err + } + + return &types.UpdateCloudSubnetsResponse{}, nil +} + +// DeleteCloudSubnets 删除云子网 +// @Summary 删除云子网 +// @Tags Cloud +// @Produce json +// @Success 200 {array} types.DeleteCloudSubnetsResponse +// @Router /clouds/{cloudID}/vpc/{vpcID}/subnets [delete] +func DeleteCloudSubnets( + c context.Context, req *types.DeleteCloudSubnetsRequest) (*types.DeleteCloudSubnetsResponse, error) { + _, err := clustermanager.DeleteCloudSubnets(c, &cluproto.DeleteCloudSubnetsRequest{ + CloudID: req.CloudID, + Region: req.Region, + AccountID: req.AccountID, + SubnetID: req.SubnetID, + }) + if err != nil { + return nil, err + } + + return &types.DeleteCloudSubnetsResponse{}, nil +} diff --git a/bcs-services/bcs-platform-manager/pkg/api/routes.go b/bcs-services/bcs-platform-manager/pkg/api/routes.go index d7bcedc3ad..4812627824 100644 --- a/bcs-services/bcs-platform-manager/pkg/api/routes.go +++ b/bcs-services/bcs-platform-manager/pkg/api/routes.go @@ -15,14 +15,15 @@ package api import ( "context" + "crypto/tls" "net/http" - "path" "github.com/Tencent/bk-bcs/bcs-common/common/blog" "github.com/Tencent/bk-bcs/bcs-common/common/tcp/listener" "github.com/go-chi/chi/v5" httpSwagger "github.com/swaggo/http-swagger" + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/api/cloud" "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/cluster" "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/api/cmdb" @@ -49,7 +50,7 @@ type APIServer struct { // nolint } // NewAPIServer : -func NewAPIServer(ctx context.Context, addr, port, addrIPv6 string) (*APIServer, error) { +func NewAPIServer(ctx context.Context, addr, port, addrIPv6 string, tlsConfig *tls.Config) (*APIServer, error) { s := &APIServer{ ctx: ctx, @@ -58,6 +59,9 @@ func NewAPIServer(ctx context.Context, addr, port, addrIPv6 string) (*APIServer, addrIPv6: addrIPv6, } srv := &http.Server{Addr: addr, Handler: s.newRoutes()} + if tlsConfig != nil { + srv.TLSConfig = tlsConfig + } s.srv = srv return s, nil } @@ -79,6 +83,10 @@ func (a *APIServer) Run() error { blog.Infof("api serve dualStackListener with ipv6: %s", v6Addr) } + if a.srv.TLSConfig != nil { + return a.srv.ServeTLS(dualStackListener, config.G.TLSConf.ServerCert, config.G.TLSConf.ServerKey) + } + return a.srv.Serve(dualStackListener) } @@ -104,14 +112,13 @@ func (a *APIServer) newRoutes() http.Handler { // 注册 HTTP 请求 r.Mount("/", registerRoutes()) + r.Mount("/clouds", registerCloudRoutes()) // 注册到网关的地址 routePrefix := config.G.Web.RoutePrefix if routePrefix != "" && routePrefix != "/" { r.Mount(routePrefix+"/", http.StripPrefix(routePrefix, registerRoutes())) } - webApiPrefix := path.Join(config.G.Web.RoutePrefix, config.APIServicePrefix) - r.Mount(webApiPrefix+"/", http.StripPrefix(webApiPrefix, registerRoutes())) return r } @@ -189,6 +196,25 @@ func registerRoutes() http.Handler { return r } +func registerCloudRoutes() http.Handler { + r := chi.NewRouter() + // 日志相关接口 + + r.Route("/{cloudID}", func(route chi.Router) { + route.Use(middleware.AuthenticationRequired) + route.Use(middleware.VisitorsRequired, middleware.Tracing, middleware.Audit) + + route.Get("/vpcs/page", rest.Handle(cloud.ListCloudVpcsPage)) + route.Get("/vpc/{vpcID}/cluster", rest.Handle(cloud.ListCloudVpcCluster)) + route.Put("/vpcs/{vpcID}", rest.Handle(cloud.UpdateCloudVpcs)) + route.Get("/subnets", rest.Handle(cloud.ListCloudSubnets)) + route.Post("/subnets", rest.Handle(cloud.CreateCloudSubnets)) + route.Put("/subnets/{subnetID}", rest.Handle(cloud.UpdateCloudSubnets)) + route.Delete("/subnets/{subnetID}", rest.Handle(cloud.DeleteCloudSubnets)) + }) + return r +} + // HealthyHandler 健康检查 func HealthyHandler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("OK")) diff --git a/bcs-services/bcs-platform-manager/pkg/component/bcs/bcs.go b/bcs-services/bcs-platform-manager/pkg/component/bcs/bcs.go deleted file mode 100644 index 596d7ab633..0000000000 --- a/bcs-services/bcs-platform-manager/pkg/component/bcs/bcs.go +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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 bcs 集群操作 -package bcs - -import ( - "encoding/json" - "errors" - "fmt" - "time" - - "github.com/Tencent/bk-bcs/bcs-common/common/blog" - - "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/component" - "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/config" - "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/storage" -) - -const ( - // VirtualClusterType vcluster - VirtualClusterType = "virtual" -) - -// Cluster 集群信息 -type Cluster struct { - ProjectID string `json:"projectID"` - ClusterID string `json:"clusterID"` - ClusterName string `json:"clusterName"` - BKBizID string `json:"businessID"` - Status string `json:"status"` - IsShared bool `json:"is_shared"` - ClusterType string `json:"clusterType"` - NetworkSettings struct { - MaxNodePodNum int `json:"maxNodePodNum"` - MaxServiceNum int `json:"maxServiceNum"` - } `json:"networkSettings"` - ExtraInfo struct { - NamespaceInfo string `json:"namespaceInfo"` - Provider string `json:"provider"` - VclusterNetwork string `json:"vclusterNetwork"` - } `json:"extraInfo"` - VclusterInfo VclusterInfo `json:"-"` -} - -// VclusterInfo vcluster info, parse from extraInfo.namespaceInfo -type VclusterInfo struct { - Name string `json:"name"` - Quota VclusterQuota `json:"quota"` -} - -// VclusterQuota vcluster quota, parse from extraInfo.namespaceInfo -type VclusterQuota struct { - CPURequests string `json:"cpuRequests"` - CPULimits string `json:"cpuLimits"` - MemoryRequests string `json:"MemoryRequests"` - MemoryLimits string `json:"memoryLimits"` -} - -// String : -func (c *Cluster) String() string { - return fmt.Sprintf("cluster<%s, %s>", c.ClusterName, c.ClusterID) -} - -// IsVirtual check cluster is vcluster -func (c *Cluster) IsVirtual() bool { - return c.ClusterType == VirtualClusterType -} - -// CacheListClusters 定时同步 cluster 列表 -func CacheListClusters() { - go func() { - ListClusters() - for range time.Tick(time.Minute * 1) { - blog.Infof("list clusters running") - ListClusters() - blog.Infof("list clusters end") - } - }() -} - -const listClustersCacheKey = "bcs.ListClusters" - -// ListClusters 获取集群列表 -func ListClusters() { - url := fmt.Sprintf("%s/bcsapi/v4/clustermanager/v1/cluster", config.G.BCS.Host) - - resp, err := component.GetClient().R(). - SetAuthToken(config.G.BCS.Token). - Get(url) - - if err != nil { - blog.Errorf("list clusters error, %s", err.Error()) - return - } - - var result []*Cluster - if err = component.UnmarshalBKResult(resp, &result); err != nil { - blog.Errorf("unmarshal clusters error, %s", err.Error()) - return - } - - clusterMap := map[string]*Cluster{} - for _, cluster := range result { - cls := cluster - if cls.IsVirtual() { - cls.VclusterInfo, err = parseVClusterInfo(cls.ExtraInfo.NamespaceInfo) - if err != nil { - blog.Errorf("parse clusters %s namespaceInfo %s error, %s", cls.ClusterID, cls.ExtraInfo.NamespaceInfo, - err.Error()) - } - } - clusterMap[cluster.ClusterID] = cls - } - - storage.LocalCache.Slot.Set(listClustersCacheKey, clusterMap, -1) -} - -func parseVClusterInfo(s string) (VclusterInfo, error) { - info := VclusterInfo{} - if s == "" { - return info, nil - } - err := json.Unmarshal([]byte(s), &info) - if err != nil { - return info, err - } - return info, nil -} - -// GetClusterMap 获取全部集群数据, map格式 -func GetClusterMap() (map[string]*Cluster, error) { - if cacheResult, ok := storage.LocalCache.Slot.Get(listClustersCacheKey); ok { - return cacheResult.(map[string]*Cluster), nil - } - return nil, errNotFoundCluster -} - -var errNotFoundCluster = errors.New("not found cluster") - -// GetCluster 获取集群详情 -func GetCluster(clusterID string) (*Cluster, error) { - getCluster := func() (*Cluster, error) { - var cacheResult interface{} - var ok bool - if cacheResult, ok = storage.LocalCache.Slot.Get(listClustersCacheKey); !ok { - return nil, errNotFoundCluster - } - if clusterMap, ok := cacheResult.(map[string]*Cluster); ok { - if cls, ok := clusterMap[clusterID]; ok { - return cls, nil - } - return nil, errNotFoundCluster - } - return nil, fmt.Errorf("cluster cache is invalid") - } - - cls, err := getCluster() - if err != nil { - // 新创建的集群,未在缓存中,刷新一下缓存 - if errors.Is(err, errNotFoundCluster) { - ListClusters() - return getCluster() - } - return nil, err - } - return cls, nil -} diff --git a/bcs-services/bcs-platform-manager/pkg/component/bcs/project_test.go b/bcs-services/bcs-platform-manager/pkg/component/bcs/clustermanager/cloud.go similarity index 54% rename from bcs-services/bcs-platform-manager/pkg/component/bcs/project_test.go rename to bcs-services/bcs-platform-manager/pkg/component/bcs/clustermanager/cloud.go index f06066f883..4242b8f0a7 100644 --- a/bcs-services/bcs-platform-manager/pkg/component/bcs/project_test.go +++ b/bcs-services/bcs-platform-manager/pkg/component/bcs/clustermanager/cloud.go @@ -10,22 +10,36 @@ * limitations under the License. */ -package bcs +// Package clustermanager xxx +package clustermanager import ( "context" - "testing" + "fmt" - "github.com/stretchr/testify/assert" + "github.com/Tencent/bk-bcs/bcs-common/pkg/bcsapi/clustermanager" "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/config" - bcstesting "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/testing" ) -func TestGetProject(t *testing.T) { - ctx := context.Background() - - project, err := GetProject(ctx, config.G.BCS, bcstesting.GetTestProjectId()) - assert.NoError(t, err) - assert.Equal(t, project.ProjectId, bcstesting.GetTestProjectId()) +// GetCloud get cloud from cluster manager +func GetCloud(ctx context.Context, + req *clustermanager.GetCloudRequest) (*clustermanager.Cloud, error) { + cli, close, err := clustermanager.GetClient(config.ServiceDomain) + defer func() { + if close != nil { + close() + } + }() + if err != nil { + return nil, err + } + p, err := cli.GetCloud(ctx, req) + if err != nil { + return nil, fmt.Errorf("GetCloud error: %s", err) + } + if p.Code != 0 || p.Data == nil { + return nil, fmt.Errorf("GetCloud error, code: %d, message: %s", p.Code, p.GetMessage()) + } + return p.Data, nil } diff --git a/bcs-services/bcs-platform-manager/pkg/component/bcs/clustermanager/cloudvpc.go b/bcs-services/bcs-platform-manager/pkg/component/bcs/clustermanager/cloudvpc.go index bd5a73d3d1..436075aa6b 100644 --- a/bcs-services/bcs-platform-manager/pkg/component/bcs/clustermanager/cloudvpc.go +++ b/bcs-services/bcs-platform-manager/pkg/component/bcs/clustermanager/cloudvpc.go @@ -107,3 +107,157 @@ func ListCloudSubnets(ctx context.Context, req *clustermanager.ListCloudSubnetsR return p.Data, nil }*/ + +// ListCloudVpc list cloud vpc from cluster manager +func ListCloudVpc(ctx context.Context, + req *clustermanager.ListCloudVPCRequest) (*clustermanager.ListCloudVPCResponse, error) { + cli, close, err := clustermanager.GetClient(config.ServiceDomain) + defer func() { + if close != nil { + close() + } + }() + if err != nil { + return nil, err + } + p, err := cli.ListCloudVPC(ctx, req) + if err != nil { + return nil, fmt.Errorf("ListCloudVpc error: %s", err) + } + if p.Code != 0 { + return nil, fmt.Errorf("ListCloudVpc error, code: %d, message: %s", p.Code, p.GetMessage()) + } + return p, nil +} + +// ListCloudVpcsPage list cloud vpcs page from cluster manager +func ListCloudVpcsPage(ctx context.Context, + req *clustermanager.ListCloudVpcsPageRequest) (*clustermanager.ListCloudVpcsPageResponse, error) { + cli, close, err := clustermanager.GetClient(config.ServiceDomain) + defer func() { + if close != nil { + close() + } + }() + if err != nil { + return nil, err + } + p, err := cli.ListCloudVpcsPage(ctx, req) + if err != nil { + return nil, fmt.Errorf("ListCloudVpcsPage error: %s", err) + } + if p.Code != 0 { + return nil, fmt.Errorf("ListCloudVpcsPage error, code: %d, message: %s", p.Code, p.GetMessage()) + } + return p, nil +} + +// ListCloudVpcCluster list cloud vpcs cluster from cluster manager +func ListCloudVpcCluster(ctx context.Context, + req *clustermanager.ListCloudVpcClusterRequest) (*clustermanager.ListCloudVpcClusterResponse, error) { + cli, close, err := clustermanager.GetClient(config.ServiceDomain) + defer func() { + if close != nil { + close() + } + }() + if err != nil { + return nil, err + } + p, err := cli.ListCloudVpcCluster(ctx, req) + if err != nil { + return nil, fmt.Errorf("ListCloudVpcCluster error: %s", err) + } + if p.Code != 0 { + return nil, fmt.Errorf("ListCloudVpcCluster error, code: %d, message: %s", p.Code, p.GetMessage()) + } + return p, nil +} + +// UpdateCloudVpcs update cloud vpcs cluster from cluster manager +func UpdateCloudVpcs(ctx context.Context, + req *clustermanager.UpdateCloudVpcsRequest) (*clustermanager.UpdateCloudVpcsResponse, error) { + cli, close, err := clustermanager.GetClient(config.ServiceDomain) + defer func() { + if close != nil { + close() + } + }() + if err != nil { + return nil, err + } + p, err := cli.UpdateCloudVpcs(ctx, req) + if err != nil { + return nil, fmt.Errorf("UpdateCloudVpcs error: %s", err) + } + if p.Code != 0 { + return nil, fmt.Errorf("UpdateCloudVpcs error, code: %d, message: %s", p.Code, p.GetMessage()) + } + return p, nil +} + +// CreateCloudSubnets create cloud subnets cluster from cluster manager +func CreateCloudSubnets(ctx context.Context, + req *clustermanager.CreateCloudSubnetsRequest) (*clustermanager.CreateCloudSubnetsResponse, error) { + cli, close, err := clustermanager.GetClient(config.ServiceDomain) + defer func() { + if close != nil { + close() + } + }() + if err != nil { + return nil, err + } + p, err := cli.CreateCloudSubnets(ctx, req) + if err != nil { + return nil, fmt.Errorf("CreateCloudSubnets error: %s", err) + } + if p.Code != 0 || p.Data == nil { + return nil, fmt.Errorf("CreateCloudSubnets error, code: %d, message: %s", p.Code, p.GetMessage()) + } + return p, nil +} + +// UpdateCloudSubnets update cloud subnets cluster from cluster manager +func UpdateCloudSubnets(ctx context.Context, + req *clustermanager.UpdateCloudSubnetsRequest) (*clustermanager.UpdateCloudSubnetsResponse, error) { + cli, close, err := clustermanager.GetClient(config.ServiceDomain) + defer func() { + if close != nil { + close() + } + }() + if err != nil { + return nil, err + } + p, err := cli.UpdateCloudSubnets(ctx, req) + if err != nil { + return nil, fmt.Errorf("UpdateCloudSubnets error: %s", err) + } + if p.Code != 0 { + return nil, fmt.Errorf("UpdateCloudSubnets error, code: %d, message: %s", p.Code, p.GetMessage()) + } + return p, nil +} + +// DeleteCloudSubnets delete cloud subnets cluster from cluster manager +func DeleteCloudSubnets(ctx context.Context, + req *clustermanager.DeleteCloudSubnetsRequest) (*clustermanager.DeleteCloudSubnetsResponse, error) { + cli, close, err := clustermanager.GetClient(config.ServiceDomain) + defer func() { + if close != nil { + close() + } + }() + if err != nil { + return nil, err + } + p, err := cli.DeleteCloudSubnets(ctx, req) + if err != nil { + return nil, fmt.Errorf("DeleteCloudSubnets error: %s", err) + } + if p.Code != 0 { + return nil, fmt.Errorf("DeleteCloudSubnets error, code: %d, message: %s", p.Code, p.GetMessage()) + } + return p, nil +} diff --git a/bcs-services/bcs-platform-manager/pkg/component/bcs/clustermanager/cluster.go b/bcs-services/bcs-platform-manager/pkg/component/bcs/clustermanager/cluster.go index f3566d346c..a400dfbb95 100644 --- a/bcs-services/bcs-platform-manager/pkg/component/bcs/clustermanager/cluster.go +++ b/bcs-services/bcs-platform-manager/pkg/component/bcs/clustermanager/cluster.go @@ -22,6 +22,7 @@ import ( "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/config" "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/storage" + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/types" ) // GetCluster get cluster from cluster manager @@ -148,3 +149,88 @@ func AddSubnetToCluster(ctx context.Context, req *clustermanager.AddSubnetToClus func getClusterCacheKey(clusterID string) string { return fmt.Sprintf("bcs.Cluster.%s", clusterID) } + +// ListCluster list cluster from cluster manager +func ListCluster(ctx context.Context, + req *clustermanager.ListClusterReq) ([]*types.Cluster, error) { + cli, close, err := clustermanager.GetClient(config.ServiceDomain) + defer func() { + if close != nil { + close() + } + }() + if err != nil { + return nil, err + } + p, err := cli.ListCluster(ctx, req) + if err != nil { + return nil, fmt.Errorf("ListCluster error: %s", err) + } + if p.Code != 0 { + return nil, fmt.Errorf("ListCluster error, code: %d, message: %s", p.Code, p.GetMessage()) + } + var clusterList []*types.Cluster + for _, cls := range p.Data { + clusterList = append(clusterList, &types.Cluster{ + ProjectID: cls.ProjectID, + ClusterID: cls.ClusterID, + ClusterName: cls.ClusterName, + BKBizID: cls.BusinessID, + Status: cls.Status, + IsShared: cls.IsShared, + ClusterType: cls.ClusterType, + Provider: cls.Provider, + Region: cls.Region, + VpcID: cls.VpcID, + NetworkSettings: convertNetworkSettings(cls), + }) + } + return clusterList, nil +} + +func convertNetworkSettings(cls *clustermanager.Cluster) *types.NetworkSettings { + if cls.NetworkSettings == nil { + return nil + } + return &types.NetworkSettings{ + EniSubnetIDs: cls.NetworkSettings.EniSubnetIDs, + MaxNodePodNum: int(cls.NetworkSettings.MaxNodePodNum), + MaxServiceNum: int(cls.NetworkSettings.MaxServiceNum), + EnableVPCCni: cls.NetworkSettings.EnableVPCCni, + SubnetSource: convertSubnetSource(cls.NetworkSettings.SubnetSource), + } +} + +func convertSubnetSource(cls *clustermanager.SubnetSource) *types.SubnetSource { + if cls == nil { + return nil + } + return &types.SubnetSource{ + New: convertNewSubnet(cls.New), + Existed: convertExistedSubnetIDs(cls.Existed), + } +} + +func convertNewSubnet(cls []*clustermanager.NewSubnet) []*types.NewSubnet { + if len(cls) == 0 { + return nil + } + var newSubnets []*types.NewSubnet + for _, subnet := range cls { + newSubnets = append(newSubnets, &types.NewSubnet{ + Mask: subnet.Mask, + Zone: subnet.Zone, + IpCnt: subnet.IpCnt, + }) + } + return newSubnets +} + +func convertExistedSubnetIDs(cls *clustermanager.ExistedSubnetIDs) *types.ExistedSubnetIDs { + if cls == nil { + return nil + } + return &types.ExistedSubnetIDs{ + Ids: cls.Ids, + } +} diff --git a/bcs-services/bcs-platform-manager/pkg/component/bcs/project.go b/bcs-services/bcs-platform-manager/pkg/component/bcs/project.go deleted file mode 100644 index cf72de3bac..0000000000 --- a/bcs-services/bcs-platform-manager/pkg/component/bcs/project.go +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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 bcs - -import ( - "context" - "fmt" - "time" - - "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/component" - "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/config" - "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/storage" - "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/utils" -) - -// Project 项目信息 -type Project struct { - Name string `json:"name"` - ProjectId string `json:"projectID"` - Code string `json:"projectCode"` - CcBizID string `json:"businessID"` - Creator string `json:"creator"` - Kind string `json:"kind"` - RawCreateTime string `json:"createTime"` -} - -// String : -func (p *Project) String() string { - var displayCode string - if p.Code == "" { - displayCode = "-" - } else { - displayCode = p.Code - } - return fmt.Sprintf("project<%s, %s|%s|%s>", p.Name, displayCode, p.ProjectId, p.CcBizID) -} - -// GetProject 通过 project_id/code 获取项目信息 -func GetProject(ctx context.Context, bcsConf *config.BCSConf, projectIDOrCode string) (*Project, error) { - cacheKey := fmt.Sprintf("bcs.GetProject:%s", projectIDOrCode) - if cacheResult, ok := storage.LocalCache.Slot.Get(cacheKey); ok { - return cacheResult.(*Project), nil - } - - url := fmt.Sprintf("%s/bcsapi/v4/bcsproject/v1/projects/%s", bcsConf.Host, projectIDOrCode) - resp, err := component.GetClient().R(). - SetContext(ctx). - SetHeaders(utils.GetLaneIDByCtx(ctx)). // 泳道特性 - SetHeader("X-Project-Username", ""). // bcs_project 要求有这个header - SetAuthToken(bcsConf.Token). - Get(url) - - if err != nil { - return nil, err - } - - project := new(Project) - if err := component.UnmarshalBKResult(resp, project); err != nil { - return nil, err - } - - storage.LocalCache.Slot.Set(cacheKey, project, time.Hour*24) - - return project, nil -} diff --git a/bcs-services/bcs-platform-manager/pkg/component/email/email.go b/bcs-services/bcs-platform-manager/pkg/component/email/email.go new file mode 100644 index 0000000000..a5451ec7c9 --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/component/email/email.go @@ -0,0 +1,98 @@ +/* + * 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 sms client +package sms + +import ( + "fmt" + + "github.com/Tencent/bk-bcs/bcs-common/common/blog" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" + ses "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses/v20201002" + + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/config" +) + +// EmailConfig email config +type EmailConfig struct { + // 发件人邮箱地址。不使用别名时请直接填写发件人邮箱地址,例如:noreply@mail.qcloud.com如需填写发件人别名时, + // 请按照如下方式(注意别名与邮箱地址之间必须使用一个空格隔开):别名+一个空格+<邮箱地址>,别名中不能带有冒号(:)。 + FromEmailAddress *string `json:"FromEmailAddress,omitempty" name:"FromEmailAddress"` + + // 收信人邮箱地址,最多支持群发50人。注意:邮件内容会显示所有收件人地址,非群发邮件请多次调用API发送。 + Destination []*string `json:"Destination,omitempty" name:"Destination"` + + // 邮件主题 + Subject *string `json:"Subject,omitempty" name:"Subject"` + + // 邮件的“回复”电子邮件地址。可以填写您能收到邮件的邮箱地址,可以是个人邮箱。如果不填,收件人的回复邮件将会发送失败。 + ReplyToAddresses *string `json:"ReplyToAddresses,omitempty" name:"ReplyToAddresses"` + + // 抄送人邮箱地址,最多支持抄送20人。 + Cc []*string `json:"Cc,omitempty" name:"Cc"` + + // 密送人邮箱地址,最多支持抄送20人,Bcc和Destination不能重复。 + Bcc []*string `json:"Bcc,omitempty" name:"Bcc"` + + // 使用模板发送时,填写模板相关参数。 + // 如您未申请过特殊配置,则该字段为必填 + Template *ses.Template `json:"Template,omitempty" name:"Template"` + + // 需要发送附件时,填写附件相关参数。腾讯云接口请求最大支持 8M 的请求包,附件内容经过 Base64 预期扩大1.5倍, + // 应该控制所有附件的总大小最大在 4M 以内,整体请求超出 8M 时接口会返回错误 + Attachments []*ses.Attachment `json:"Attachments,omitempty" name:"Attachments"` +} + +// NewEmailClient new email client +func NewEmailClient() (*ses.Client, error) { + credential := common.NewCredential( + config.G.Sign.SecretId, + config.G.Sign.SecretKey, + ) + cpf := profile.NewClientProfile() + cpf.HttpProfile.Endpoint = config.G.Sign.EmailEndpoint + // 实例化要请求产品的client对象,clientProfile是可选的 + client, err := ses.NewClient(credential, config.G.Sign.Region, cpf) + if err != nil { + return nil, err + } + return client, nil +} + +// SendEmail send email, 参考地址: https://cloud.tencent.com/document/product/1288/51034 +func SendEmail(emailConfig *EmailConfig) error { + client, err := NewEmailClient() + if err != nil { + return err + } + request := ses.NewSendEmailRequest() + request.FromEmailAddress = emailConfig.FromEmailAddress + request.Destination = emailConfig.Destination + request.Subject = emailConfig.Subject + request.ReplyToAddresses = emailConfig.ReplyToAddresses + request.Cc = emailConfig.Cc + request.Bcc = emailConfig.Bcc + request.Template = emailConfig.Template + request.Attachments = emailConfig.Attachments + emailResp, err := client.SendEmail(request) + if err != nil { + return err + } + if emailResp == nil || emailResp.Response == nil { + return fmt.Errorf("SendEmail resp is nil") + } + blog.Infof("SendEmail resp request id %s", emailResp.Response.RequestId) + + return nil +} diff --git a/bcs-services/bcs-platform-manager/pkg/component/sms/sms.go b/bcs-services/bcs-platform-manager/pkg/component/sms/sms.go new file mode 100644 index 0000000000..4196f6d294 --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/component/sms/sms.go @@ -0,0 +1,66 @@ +/* + * 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 sms client +package sms + +import ( + "fmt" + + "github.com/Tencent/bk-bcs/bcs-common/common/blog" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" + sms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms/v20210111" + + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/config" +) + +// NewSmsClient new sms client +func NewSmsClient() (*sms.Client, error) { + credential := common.NewCredential( + config.G.Sign.SecretId, + config.G.Sign.SecretKey, + ) + cpf := profile.NewClientProfile() + cpf.HttpProfile.Endpoint = config.G.Sign.SmsEndpoint + // 实例化要请求产品的client对象,clientProfile是可选的 + client, err := sms.NewClient(credential, config.G.Sign.Region, cpf) + if err != nil { + return nil, err + } + return client, nil +} + +// SendSms send sms, 参考地址: https://cloud.tencent.com/document/product/382/55981 +func SendSms( + phoneNumbers []*string, templateID *string, templateParams []*string) ([]*sms.SendStatus, error) { + client, err := NewSmsClient() + if err != nil { + return nil, err + } + request := sms.NewSendSmsRequest() + request.SmsSdkAppId = &config.G.Sign.SmsSdkAppId + request.SignName = &config.G.Sign.SmsSignName + request.PhoneNumberSet = phoneNumbers + request.TemplateId = templateID + request.TemplateParamSet = templateParams + smsResp, err := client.SendSms(request) + if err != nil { + return nil, err + } + if smsResp == nil || smsResp.Response == nil { + return nil, fmt.Errorf("SendSms resp is nil") + } + blog.Infof("SendSms resp request id %s", smsResp.Response.RequestId) + + return smsResp.Response.SendStatusSet, nil +} diff --git a/bcs-services/bcs-platform-manager/pkg/config/base.go b/bcs-services/bcs-platform-manager/pkg/config/base.go index 315114a256..8462c77541 100644 --- a/bcs-services/bcs-platform-manager/pkg/config/base.go +++ b/bcs-services/bcs-platform-manager/pkg/config/base.go @@ -21,7 +21,7 @@ const ( // ProdEnv xxx ProdEnv = "prod" // ServiceDomain domain name for service - ServiceDomain = "bcsplatformmanager.bkbcs.tencent.com" + ServiceDomain = "platformmanager.bkbcs.tencent.com" ) // BaseConf : diff --git a/bcs-services/bcs-platform-manager/pkg/config/config.go b/bcs-services/bcs-platform-manager/pkg/config/config.go index b8d482f885..eba3658e92 100644 --- a/bcs-services/bcs-platform-manager/pkg/config/config.go +++ b/bcs-services/bcs-platform-manager/pkg/config/config.go @@ -19,11 +19,6 @@ import ( "gopkg.in/yaml.v3" ) -const ( - // APIServicePrefix API 服务前缀 - APIServicePrefix = "/api" -) - // Configuration 配置 type Configuration struct { Viper *viper.Viper @@ -35,9 +30,12 @@ type Configuration struct { BCS *BCSConf `yaml:"bcs_conf"` IAM *IAMConfig `yaml:"iam_conf"` Web *WebConf `yaml:"web"` + Sign *SignConf `yaml:"sign"` TracingConf *TracingConf `yaml:"tracing_conf"` Cmdb *CmdbConf `yaml:"cmdb"` Notice *NoticeConf `yaml:"notice"` + TLSConf *TLSConf `yaml:"tls_conf"` + TaskConf *TaskConf `yaml:"task_conf"` } // init 初始化 @@ -93,6 +91,9 @@ func newConfiguration() (*Configuration, error) { _ = c.BCS.Init() c.TracingConf = &TracingConf{} + c.Sign = defaultSignConf() + c.TLSConf = defaultTLSConf() + c.TaskConf = defaultTaskConf() return c, nil } @@ -148,6 +149,29 @@ func (c *Configuration) ReadFrom(content []byte) error { c.IAM.GatewayServer = BKIAM_GATEWAY_SERVER } + // sms + if c.Sign.SecretId == "" { + c.Sign.SecretId = SECRET_ID + } + if c.Sign.SecretKey == "" { + c.Sign.SecretKey = SECRET_KEY + } + if c.Sign.EmailEndpoint == "" { + c.Sign.EmailEndpoint = EMAIL_ENDPOINT + } + if c.Sign.SmsEndpoint == "" { + c.Sign.SmsEndpoint = SMS_ENDPOINT + } + if c.Sign.SmsSdkAppId == "" { + c.Sign.SmsSdkAppId = SMS_SDK_APP_ID + } + if c.Sign.SmsSignName == "" { + c.Sign.SmsSignName = SMS_SIGN_NAME + } + if c.Sign.Region == "" { + c.Sign.Region = REGION + } + // mongo if c.Mongo.Address == "" { c.Mongo.Address = MONGO_ADDRESS diff --git a/bcs-services/bcs-platform-manager/pkg/config/env.go b/bcs-services/bcs-platform-manager/pkg/config/env.go index 80cbd0475d..867f6a1f58 100644 --- a/bcs-services/bcs-platform-manager/pkg/config/env.go +++ b/bcs-services/bcs-platform-manager/pkg/config/env.go @@ -51,4 +51,18 @@ var ( BK_CMDB_HOST = os.Getenv("BK_CMDB_HOST") // POD_IP ... POD_IP = os.Getenv("POD_IP") + // SECRET_ID ... + SECRET_ID = os.Getenv("SECRET_ID") + // SECRET_KEY ... + SECRET_KEY = os.Getenv("SECRET_KEY") + // SMS_ENDPOINT ... + SMS_ENDPOINT = os.Getenv("SMS_ENDPOINT") + // EMAIL_ENDPOINT ... + EMAIL_ENDPOINT = os.Getenv("EMAIL_ENDPOINT") + // SMS_SDK_APP_ID ... + SMS_SDK_APP_ID = os.Getenv("SMS_SDK_APP_ID") + // SMS_SIGN_NAME ... + SMS_SIGN_NAME = os.Getenv("SMS_SIGN_NAME") + // REGION ... + REGION = os.Getenv("REGION") ) diff --git a/bcs-services/bcs-platform-manager/pkg/config/sign.go b/bcs-services/bcs-platform-manager/pkg/config/sign.go new file mode 100644 index 0000000000..cb277e844f --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/config/sign.go @@ -0,0 +1,38 @@ +/* + * 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 config + +// SignConf sign config +type SignConf struct { + SecretId string `json:"secret_id"` + SecretKey string `json:"secret_key"` + Region string `json:"region"` + EmailEndpoint string `json:"email_endpoint"` + SmsEndpoint string `json:"sms_endpoint"` + SmsSdkAppId string `json:"sms_sdk_app_id"` + SmsSignName string `json:"sms_sign_name"` +} + +// defaultSignConf 默认配置 +func defaultSignConf() *SignConf { + c := &SignConf{ + SecretId: "", + SecretKey: "", + SmsEndpoint: "sms.tencentcloudapi.com", + EmailEndpoint: "ses.tencentcloudapi.com", + SmsSdkAppId: "", + SmsSignName: "", + Region: "ap-guangzhou", + } + return c +} diff --git a/bcs-services/bcs-platform-manager/pkg/config/task.go b/bcs-services/bcs-platform-manager/pkg/config/task.go new file mode 100644 index 0000000000..86d46df43e --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/config/task.go @@ -0,0 +1,34 @@ +/* + * 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 config + +// TaskConf : config for task +type TaskConf struct { + BcsSubnetResourceCron string `yaml:"bcs_subnet_resource_cron"` + VpcIPMonitorCron string `yaml:"vpc_ip_monitor_cron"` + RemainOverlayIPNum int `json:"remain_overlayip_num" yaml:"remain_overlayip_num"` + RemainUnderlayIPNum int `json:"remain_underlayip_num" yaml:"remain_underlayip_num"` + AllocateSubnetIPCnt int `json:"allocate_subnet_ip_cnt" yaml:"allocate_subnet_ip_cnt"` +} + +// defaultTaskConf : +func defaultTaskConf() *TaskConf { + // only for development + return &TaskConf{ + BcsSubnetResourceCron: "*/60 * * * *", + VpcIPMonitorCron: "*/60 * * * *", + RemainOverlayIPNum: 0, + RemainUnderlayIPNum: 0, + AllocateSubnetIPCnt: 0, + } +} diff --git a/bcs-services/bcs-platform-manager/pkg/config/tls.go b/bcs-services/bcs-platform-manager/pkg/config/tls.go new file mode 100644 index 0000000000..967cf459c5 --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/config/tls.go @@ -0,0 +1,36 @@ +/* + * 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 config + +// TLSConf : config for tls +type TLSConf struct { + ServerCert string `json:"server_cert" yaml:"server_cert"` + ServerKey string `json:"server_key" yaml:"server_key"` + ServerCa string `json:"server_ca" yaml:"server_ca"` + ClientCert string `json:"client_cert" yaml:"client_cert"` + ClientKey string `json:"client_key" yaml:"client_key"` + ClientCa string `json:"client_ca" yaml:"client_ca"` +} + +// defaultTLSConf : +func defaultTLSConf() *TLSConf { + // only for development + return &TLSConf{ + ServerCert: "", + ServerKey: "", + ServerCa: "", + ClientCert: "", + ClientKey: "", + ClientCa: "", + } +} diff --git a/bcs-services/bcs-platform-manager/pkg/cron/client/client.go b/bcs-services/bcs-platform-manager/pkg/cron/client/client.go new file mode 100644 index 0000000000..553396b58b --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/cron/client/client.go @@ -0,0 +1,63 @@ +/* + * 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 client xxx +package client + +import ( + "github.com/Tencent/bk-bcs/bcs-common/common/blog" + "github.com/hibiken/asynq" + + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/cron/options" + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/cron/task" +) + +// NewScheduler creates a new scheduler and runs it. +func NewScheduler() (*asynq.Scheduler, error) { + blog.Info("create schedule task: cron job") + scheduler := asynq.NewScheduler(options.NewRedisConnOpt(), nil) + + cronTasks, err := NewCronTasks() + if err != nil { + return nil, err + } + // You can use cron spec string to specify the schedule. + for _, cronTask := range cronTasks { + var entryID string + entryID, err = scheduler.Register(cronTask.Cron, cronTask.Task, asynq.Queue(cronTask.QueueName)) + if err != nil { + return nil, err + } + blog.Infof("registered an entry: %q\n", entryID) + } + + return scheduler, nil +} + +// NewCronTasks create cron tasks +func NewCronTasks() ([]*task.CronTask, error) { + cronTasks := []*task.CronTask{} + var err error + var cronTask *task.CronTask + cronTask, err = task.NewCronTask(options.TypeBcsSubnetResource, nil) + if err != nil { + return nil, err + } + cronTasks = append(cronTasks, cronTask) + cronTask, err = task.NewCronTask(options.TypeVpcIPMonitor, nil) + if err != nil { + return nil, err + } + cronTasks = append(cronTasks, cronTask) + + return cronTasks, nil +} diff --git a/bcs-services/bcs-platform-manager/pkg/component/bcs/bcs_test.go b/bcs-services/bcs-platform-manager/pkg/cron/options/constant.go similarity index 60% rename from bcs-services/bcs-platform-manager/pkg/component/bcs/bcs_test.go rename to bcs-services/bcs-platform-manager/pkg/cron/options/constant.go index 05530f9f55..c9149bf279 100644 --- a/bcs-services/bcs-platform-manager/pkg/component/bcs/bcs_test.go +++ b/bcs-services/bcs-platform-manager/pkg/cron/options/constant.go @@ -10,18 +10,20 @@ * limitations under the License. */ -package bcs +// Package options xxx +package options -import ( - "testing" - - "github.com/stretchr/testify/assert" - - bcstesting "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/testing" +const ( + // BcsSubnetResourceQueueName Bcs子网资源任务队列名称 + BcsSubnetResourceQueueName = "bcssubnetresource" + // VpcIPMonitorQueueName VPC IP监测任务队列名称 + VpcIPMonitorQueueName = "vpcipmonitor" ) -func TestGetCluster(t *testing.T) { - cluster, err := GetCluster(bcstesting.GetTestClusterId()) - assert.NoError(t, err) - assert.Equal(t, cluster.ProjectID, bcstesting.GetTestProjectId()) -} +// A list of task types. +const ( + // TypeBcsSubnetResource Bcs子网资源任务类型 + TypeBcsSubnetResource = "bcssubnet:resource" + // TypeVpcIPMonitor VPC IP监测任务类型 + TypeVpcIPMonitor = "vpcip:monitor" +) diff --git a/bcs-services/bcs-platform-manager/pkg/cron/options/option.go b/bcs-services/bcs-platform-manager/pkg/cron/options/option.go new file mode 100644 index 0000000000..e3139ec8bf --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/cron/options/option.go @@ -0,0 +1,52 @@ +/* + * 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 options xxx +package options + +import ( + "fmt" + "time" + + "github.com/hibiken/asynq" + + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/config" +) + +// NewRedisConnOpt : create redis connection option +func NewRedisConnOpt() asynq.RedisConnOpt { + redisConf := config.G.Redis + + if redisConf.IsSentinelType() { + // 哨兵模式 + return asynq.RedisFailoverClientOpt{ + MasterName: redisConf.MasterName, + SentinelAddrs: redisConf.SentinelAddrs, + SentinelPassword: redisConf.SentinelPassword, + Username: "", + Password: redisConf.Password, + DB: redisConf.DB, + DialTimeout: time.Duration(redisConf.MaxConnTimeout) * time.Second, + ReadTimeout: time.Duration(redisConf.ReadTimeout) * time.Second, + PoolSize: redisConf.MaxPoolSize, + } + } + // 单例模式 + return asynq.RedisClientOpt{ + Addr: fmt.Sprintf("%v:%v", redisConf.Host, redisConf.Port), + Password: redisConf.Password, + DB: redisConf.DB, + DialTimeout: time.Duration(redisConf.MaxConnTimeout) * time.Second, + ReadTimeout: time.Duration(redisConf.ReadTimeout) * time.Second, + PoolSize: redisConf.MaxPoolSize, + } +} diff --git a/bcs-services/bcs-platform-manager/pkg/cron/server/server.go b/bcs-services/bcs-platform-manager/pkg/cron/server/server.go new file mode 100644 index 0000000000..a1ddfd5cae --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/cron/server/server.go @@ -0,0 +1,55 @@ +/* + * 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 client xxx +package client + +import ( + "github.com/Tencent/bk-bcs/bcs-common/common/blog" + "github.com/hibiken/asynq" + + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/cron/options" + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/cron/task" +) + +// NewAsynqServer creates a new server and runs it. +func NewAsynqServer() error { + blog.Info("start a asynq server") + srv := asynq.NewServer( + options.NewRedisConnOpt(), + asynq.Config{ + // Specify how many concurrent workers to use + Concurrency: 10, + // Optionally specify multiple queues with different priority. + Queues: map[string]int{ + options.BcsSubnetResourceQueueName: 1, + options.VpcIPMonitorQueueName: 1, + }, + // See the godoc for other configuration options + }, + ) + + // mux maps a type to a handler + mux := asynq.NewServeMux() + mux.HandleFunc(options.TypeBcsSubnetResource, task.HandleBcsSubnetResourceTask) + mux.HandleFunc(options.TypeVpcIPMonitor, task.HandleVpcIPMonitorTask) + // ...register other handlers... + + go func() { + err := srv.Run(mux) + if err != nil { + panic("run asynq server failed: " + err.Error()) + } + }() + + return nil +} diff --git a/bcs-services/bcs-platform-manager/pkg/cron/task/bcssubnetresource.go b/bcs-services/bcs-platform-manager/pkg/cron/task/bcssubnetresource.go new file mode 100644 index 0000000000..1808c58577 --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/cron/task/bcssubnetresource.go @@ -0,0 +1,143 @@ +/* + * 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 task xxx +package task + +import ( + "context" + + "github.com/Tencent/bk-bcs/bcs-common/common/blog" + cluproto "github.com/Tencent/bk-bcs/bcs-common/pkg/bcsapi/clustermanager" + "github.com/hibiken/asynq" + + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/component/bcs/clustermanager" + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/config" +) + +// HandleBcsSubnetResourceTask : handle bcs subnet resource task +func HandleBcsSubnetResourceTask(ctx context.Context, t *asynq.Task) error { + blog.Infof("handle bcs subnet resource task: %s", t.Payload()) + clusters, err := clustermanager.ListCluster(ctx, &cluproto.ListClusterReq{}) + if err != nil { + blog.Errorf("handle bcs subnet resource task: list cluster failed: %v", err) + return err + } + for _, cluster := range clusters { + // 查询子网使用率下限 + cloud, err := clustermanager.GetCloud(ctx, &cluproto.GetCloudRequest{ + CloudID: cluster.Provider, + }) + if err != nil { + blog.Errorf("handle bcs subnet resource task: get cloud failed: %v", err) + return err + } + if cloud.NetworkInfo == nil || cloud.NetworkInfo.UnderlayRatio == 0 { + continue + } + + if cluster.NetworkSettings == nil { + continue + } + if !cluster.NetworkSettings.EnableVPCCni { + continue + } + var availableIPAddressCount uint64 + var totalIPAddressCount uint64 + var zone string + for _, v := range cluster.NetworkSettings.EniSubnetIDs { + // 查询需要扩容的集群及子网 + subnets, errr := clustermanager.ListCloudSubnets(ctx, &cluproto.ListCloudSubnetsRequest{ + CloudID: cluster.Provider, + Region: cluster.Region, + SubnetID: v, + VpcID: cluster.VpcID, + }) + if errr != nil { + blog.Errorf("handle bcs subnet resource task: list cloud subnets failed: %v", errr) + return errr + } + if len(subnets) == 0 { + continue + } + availableIPAddressCount += subnets[0].AvailableIPAddressCount + totalIPAddressCount += subnets[0].TotalIpAddressCount + zone = subnets[0].Zone + } + + var usageRatio float64 + if totalIPAddressCount != 0 { + usageRatio = float64(totalIPAddressCount-availableIPAddressCount) / float64(totalIPAddressCount) * 100 + } + if usageRatio > float64(cloud.NetworkInfo.UnderlayRatio) { + // 分配子网资源 + _, err = clustermanager.AddSubnetToCluster(ctx, &cluproto.AddSubnetToClusterReq{ + ClusterID: cluster.ClusterID, + Subnet: &cluproto.SubnetSource{ + New: []*cluproto.NewSubnet{{ + Zone: zone, + IpCnt: uint32(config.G.TaskConf.AllocateSubnetIPCnt), + }}, + }, + Operator: "", + }) + if err != nil { + blog.Errorf("handle bcs subnet resource task: add subnet to cluster failed: %v", err) + return err + } + } + + } + // Email delivery code ... + return nil +} + +// HandleVpcIPMonitorTask : handle vpc ip monitor task +func HandleVpcIPMonitorTask(ctx context.Context, t *asynq.Task) error { + blog.Infof("handle vpc ip monitor task: %s", t.Payload()) + underlaySubnets, err := clustermanager.ListCloudVpc(ctx, &cluproto.ListCloudVPCRequest{ + NetworkType: "underlay", + }) + if err != nil { + blog.Errorf("handle vpc ip monitor task: list cloud vpc error: %s", err) + return err + } + for _, subnet := range underlaySubnets.Data { + if subnet.Underlay != nil { + if subnet.Underlay.AvailableIPNum < uint32(config.G.TaskConf.RemainUnderlayIPNum) { + // 发送告警邮件 + blog.Infof("handle vpc ip monitor task: vpcid: %s, "+ + "underlay ip available ip num: %d lt remain underlay ip num: %d", subnet.VpcID, + subnet.Underlay.AvailableIPNum, config.G.TaskConf.RemainUnderlayIPNum) + } + } + } + overlaySubnets, err := clustermanager.ListCloudVpc(ctx, &cluproto.ListCloudVPCRequest{ + NetworkType: "overlay", + }) + if err != nil { + blog.Errorf("handle vpc ip monitor task: list cloud vpc error: %s", err) + return err + } + for _, subnet := range overlaySubnets.Data { + if subnet.Overlay != nil { + if subnet.Overlay.AvailableIPNum < uint32(config.G.TaskConf.RemainOverlayIPNum) { + // 发送告警邮件 + // 发送通知 + blog.Infof("handle vpc ip monitor task: vpcid: %s, "+ + "overlay ip available ip num: %d lt remain overlay ip num: %d", subnet.VpcID, + subnet.Overlay.AvailableIPNum, config.G.TaskConf.RemainOverlayIPNum) + } + } + } + return nil +} diff --git a/bcs-services/bcs-platform-manager/pkg/cron/task/task.go b/bcs-services/bcs-platform-manager/pkg/cron/task/task.go new file mode 100644 index 0000000000..7dbc2f30a8 --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/cron/task/task.go @@ -0,0 +1,50 @@ +/* + * 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 task xxx +package task + +import ( + "fmt" + "time" + + "github.com/hibiken/asynq" + + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/config" + "github.com/Tencent/bk-bcs/bcs-services/bcs-platform-manager/pkg/cron/options" +) + +// CronTask : cron task +type CronTask struct { + Task *asynq.Task + Cron string + QueueName string +} + +// NewCronTask : create cron task +func NewCronTask(taskType string, payload []byte) (*CronTask, error) { + cronTask := &CronTask{} + switch taskType { + case options.TypeBcsSubnetResource: + cronTask.Task = asynq.NewTask(options.TypeBcsSubnetResource, payload, asynq.Unique(60*time.Minute)) + cronTask.Cron = config.G.TaskConf.BcsSubnetResourceCron + cronTask.QueueName = options.BcsSubnetResourceQueueName + return cronTask, nil + case options.TypeVpcIPMonitor: + cronTask.Task = asynq.NewTask(options.TypeVpcIPMonitor, payload, asynq.Unique(60*time.Minute)) + cronTask.Cron = config.G.TaskConf.VpcIPMonitorCron + cronTask.QueueName = options.VpcIPMonitorQueueName + return cronTask, nil + default: + return nil, fmt.Errorf("unknown task type: %s", taskType) + } +} diff --git a/bcs-services/bcs-platform-manager/pkg/discovery/discovery.go b/bcs-services/bcs-platform-manager/pkg/discovery/discovery.go index 6a0bdf5a08..acd161e0ff 100644 --- a/bcs-services/bcs-platform-manager/pkg/discovery/discovery.go +++ b/bcs-services/bcs-platform-manager/pkg/discovery/discovery.go @@ -18,7 +18,9 @@ import ( "crypto/tls" "strings" + "github.com/Tencent/bk-bcs/bcs-common/common/blog" "github.com/Tencent/bk-bcs/bcs-common/common/ssl" + "github.com/Tencent/bk-bcs/bcs-common/common/static" "github.com/Tencent/bk-bcs/bcs-common/common/types" etcd "github.com/go-micro/plugins/v4/registry/etcd" "go-micro.dev/v4" @@ -39,6 +41,7 @@ type ServiceDiscovery struct { srv micro.Service microRgt registry.Registry clientTLSConfig *tls.Config + TLSConfig *tls.Config } // NewServiceDiscovery : @@ -72,6 +75,11 @@ func (s *ServiceDiscovery) Run() error { } func (s *ServiceDiscovery) init() error { + // initTLSConfig client TLS 配置 + if err := s.initTLSConfig(); err != nil { + return err + } + // etcd 服务发现注册 etcdRegistry, err := s.initEtcdRegistry() if err != nil { @@ -89,6 +97,35 @@ func (s *ServiceDiscovery) init() error { return nil } +// initTLSConfig xxx +// init server and client tls config +func (s *ServiceDiscovery) initTLSConfig() error { + if len(config.G.TLSConf.ServerCert) != 0 && len(config.G.TLSConf.ServerKey) != 0 && + len(config.G.TLSConf.ServerCa) != 0 { + tlsConfig, err := ssl.ServerTslConfVerityClient(config.G.TLSConf.ServerCa, config.G.TLSConf.ServerCert, + config.G.TLSConf.ServerKey, static.ServerCertPwd) + if err != nil { + blog.Errorf("load platform manager server tls config failed, err %s", err.Error()) + return err + } + s.TLSConfig = tlsConfig + blog.Info("load platform manager server tls config successfully") + } + + if len(config.G.TLSConf.ClientCert) != 0 && len(config.G.TLSConf.ClientKey) != 0 && + len(config.G.TLSConf.ClientCa) != 0 { + tlsConfig, err := ssl.ClientTslConfVerity(config.G.TLSConf.ClientCa, config.G.TLSConf.ClientCert, + config.G.TLSConf.ClientKey, static.ClientCertPwd) + if err != nil { + blog.Errorf("load platform manager client tls config failed, err %s", err.Error()) + return err + } + s.clientTLSConfig = tlsConfig + blog.Info("load platform manager client tls config successfully") + } + return nil +} + // initEtcdRegistry etcd 服务注册 func (s *ServiceDiscovery) initEtcdRegistry() (registry.Registry, error) { endpoints := config.G.Viper.GetString("etcd.endpoints") diff --git a/bcs-services/bcs-platform-manager/pkg/types/cluster.go b/bcs-services/bcs-platform-manager/pkg/types/cluster.go index 463474f4ce..831bdff61c 100644 --- a/bcs-services/bcs-platform-manager/pkg/types/cluster.go +++ b/bcs-services/bcs-platform-manager/pkg/types/cluster.go @@ -360,3 +360,45 @@ type SubnetSource struct { type ExistedSubnetIDs struct { Ids []string `json:"ids"` } + +// Cluster 集群信息 +type Cluster struct { + ProjectID string `json:"projectID"` + ClusterID string `json:"clusterID"` + ClusterName string `json:"clusterName"` + Provider string `json:"provider"` + Region string `json:"region"` + BKBizID string `json:"businessID"` + Status string `json:"status"` + IsShared bool `json:"is_shared"` + ClusterType string `json:"clusterType"` + VpcID string `json:"vpcID"` + NetworkSettings *NetworkSettings `json:"networkSettings"` + ExtraInfo *ExtraInfo `json:"extraInfo"` +} + +// NetworkSettings 网络设置 +type NetworkSettings struct { + MaxNodePodNum int `json:"maxNodePodNum"` + MaxServiceNum int `json:"maxServiceNum"` + EnableVPCCni bool `json:"enableVPCCni"` + EniSubnetIDs []string `json:"eniSubnetIDs"` + SubnetSource *SubnetSource `json:"subnetSource"` +} + +// ExtraInfo 额外信息 +type ExtraInfo struct { + NamespaceInfo string `json:"namespaceInfo"` + Provider string `json:"provider"` + VclusterNetwork string `json:"vclusterNetwork"` +} + +const ( + // VirtualClusterType vcluster + VirtualClusterType = "virtual" +) + +// IsVirtual check cluster is vcluster +func (c *Cluster) IsVirtual() bool { + return c.ClusterType == VirtualClusterType +} diff --git a/bcs-services/bcs-platform-manager/pkg/types/createcloudsubnets.go b/bcs-services/bcs-platform-manager/pkg/types/createcloudsubnets.go new file mode 100644 index 0000000000..536eaf47d3 --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/types/createcloudsubnets.go @@ -0,0 +1,61 @@ +/* + * 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 types pod types +package types + +// CreateCloudSubnetsRequest create cloud subnets cluster request +type CreateCloudSubnetsRequest struct { + // CloudID 云信息 + // 最小长度:2 + CloudID string `json:"cloudID" in:"path=cloudID" validate:"min=2"` + + // VpcID vpcID信息 + // 最小长度:2 | 最大长度:100 | 格式:仅包含数字、字母、短横线(-) + VpcID string `json:"vpcID" validate:"min=2,max=100"` + + // Region 云地域信息 + Region string `json:"region" validate:"omitempty"` + + // AccountID 云凭证ID + AccountID string `json:"accountID" validate:"omitempty"` + + // SubnetName 子网名称 + SubnetName string `json:"subnetName" validate:"omitempty"` + + // CidrBlock 子网CIDR + CidrBlock string `json:"cidrBlock" validate:"omitempty"` + + // Zone 可用区 + Zone string `json:"zone" validate:"omitempty"` +} + +// CreateCloudSubnetsResponse create cloud subnets cluster response +type CreateCloudSubnetsResponse struct { + Subnet CloudSubnets `json:"subnet"` +} + +// CloudSubnets VPC信息 +// @Description vpc信息 +type CloudSubnets struct { + VpcID string `json:"vpcID"` + SubnetID string `json:"subnetID"` + SubnetName string `json:"subnetName"` + CidrRange string `json:"cidrRange"` + Ipv6CidrRange string `json:"ipv6CidrRange"` + Zone string `json:"zone"` + AvailableIPAddressCount uint64 `json:"availableIPAddressCount"` + ZoneName string `json:"zoneName"` + Cluster ClusterInfo `json:"cluster"` + HwNeutronSubnetID string `json:"hwNeutronSubnetID"` + TotalIpAddressCount uint64 `json:"totalIpAddressCount"` +} diff --git a/bcs-services/bcs-platform-manager/pkg/types/deletecloudsubnets.go b/bcs-services/bcs-platform-manager/pkg/types/deletecloudsubnets.go new file mode 100644 index 0000000000..955c7e7ad2 --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/types/deletecloudsubnets.go @@ -0,0 +1,35 @@ +/* + * 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 types pod types +package types + +// DeleteCloudSubnetsRequest delete cloud subnets cluster request +type DeleteCloudSubnetsRequest struct { + // CloudID 云信息 + // 最小长度:2 + CloudID string `json:"cloudID" in:"path=cloudID" validate:"min=2"` + + // Region 云地域信息 + Region string `json:"region" in:"query=region" validate:"omitempty"` + + // AccountID 云凭证ID + AccountID string `json:"accountID" in:"query=accountID" validate:"omitempty"` + + // SubnetID 子网ID + // 最小长度:1(必填且非空) + SubnetID string `json:"subnetID" in:"path=subnetID" validate:"min=1"` +} + +// DeleteCloudSubnetsResponse delete cloud subnets cluster response +type DeleteCloudSubnetsResponse struct { +} diff --git a/bcs-services/bcs-platform-manager/pkg/types/listcloudsubnets.go b/bcs-services/bcs-platform-manager/pkg/types/listcloudsubnets.go new file mode 100644 index 0000000000..70c30f5002 --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/types/listcloudsubnets.go @@ -0,0 +1,52 @@ +/* + * 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 types pod types +package types + +// ListCloudSubnetsRequest list cloud subnets page request +type ListCloudSubnetsRequest struct { + // CloudID 云信息 + // 最小长度:2 + CloudID string `json:"cloudID" in:"path=cloudID" validate:"min=2"` + + // Region 云地域信息 + Region string `json:"region" in:"query=region" validate:"omitempty"` + + // AccountID 云凭证ID + AccountID string `json:"accountID" in:"query=accountID" validate:"omitempty"` + + // VpcID 过滤查询指定vpc的信息 + VpcID string `json:"vpcID" in:"query=vpcID" validate:"omitempty"` +} + +// ListCloudSubnetsResponse list cloud subnets page response +type ListCloudSubnetsResponse struct { + Total uint32 `json:"total"` + Subnets []ListCloudSubnets `json:"subnets"` +} + +// ListCloudSubnets VPC信息 +// @Description vpc信息 +type ListCloudSubnets struct { + VpcID string `json:"vpcID"` + SubnetID string `json:"subnetID"` + SubnetName string `json:"subnetName"` + CidrRange string `json:"cidrRange"` + Ipv6CidrRange string `json:"ipv6CidrRange"` + Zone string `json:"zone"` + AvailableIPAddressCount uint64 `json:"availableIPAddressCount"` + ZoneName string `json:"zoneName"` + Cluster ClusterInfo `json:"cluster"` + HwNeutronSubnetID string `json:"hwNeutronSubnetID"` + TotalIpAddressCount uint64 `json:"totalIpAddressCount"` +} diff --git a/bcs-services/bcs-platform-manager/pkg/types/listcloudvpccluster.go b/bcs-services/bcs-platform-manager/pkg/types/listcloudvpccluster.go new file mode 100644 index 0000000000..3547724d8f --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/types/listcloudvpccluster.go @@ -0,0 +1,56 @@ +/* + * 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 types pod types +package types + +// ListCloudVpcClusterRequest list cloud vpc cluster request +type ListCloudVpcClusterRequest struct { + // CloudID 云信息 + // 最小长度:2 + CloudID string `json:"cloudID" in:"path=cloudID" validate:"min=2"` + + // Region 云地域信息 + // 最小长度:2 + Region string `json:"region" in:"query=region" validate:"min=2"` + + // AccountID 云凭证ID + AccountID string `json:"accountID" in:"query=accountID" validate:"omitempty"` + + // VpcID 过滤查询指定vpc的信息 + // 最小长度:2 | 最大长度:100 | 格式:仅包含数字、字母、短横线(-) + VpcID string `json:"vpcID" in:"path=vpcID" validate:"min=2,max=100"` + + // Offset 查询偏移量 + // 最小值:0 + Offset uint32 `json:"offset" in:"query=offset" validate:"gte=0"` + + // Limit 查询限制数量 + // 最大值:5000 + Limit uint32 `json:"limit" in:"query=limit" validate:"lte=5000"` +} + +// ListCloudVpcClusterResponse list cloud vpc cluster response +type ListCloudVpcClusterResponse struct { + Total uint32 `json:"total"` + CloudCluster []CloudCluster `json:"cloudCluster"` +} + +// CloudCluster VPC信息 +// @Description vpc信息 +type CloudCluster struct { + // ClusterID 集群ID + ClusterID string `json:"clusterID"` + + // OverlayIPCidr Overlay IP CIDR列表(嵌套结构体) + OverlayIPCidr []OverlayIPCidr `json:"overlayIPCidr"` +} diff --git a/bcs-services/bcs-platform-manager/pkg/types/listcloudvpcspage.go b/bcs-services/bcs-platform-manager/pkg/types/listcloudvpcspage.go new file mode 100644 index 0000000000..d4d47f25db --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/types/listcloudvpcspage.go @@ -0,0 +1,109 @@ +/* + * 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 types pod types +package types + +// ListCloudVpcsPageRequest list cloud vpcs page request +type ListCloudVpcsPageRequest struct { + // CloudID 云信息 + // 最小长度:2 + CloudID string `json:"cloudID" in:"path=cloudID" validate:"min=2"` + + // Region 云地域信息 + Region string `json:"region" in:"query=region" validate:"omitempty"` + + // AccountID 云凭证ID + AccountID string `json:"accountID" in:"query=accountID" validate:"omitempty"` + + // VpcID 过滤查询指定vpc的信息 + VpcID string `json:"vpcID" in:"query=vpcID" validate:"omitempty"` + + // ResourceGroupName Azure Cloud中Vpc所属的resource group名称 + ResourceGroupName string `json:"resourceGroupName" in:"query=resourceGroupName" validate:"omitempty"` + + // VpcName vpc名称 + VpcName string `json:"vpcName" in:"query=vpcName" validate:"omitempty"` + + // Offset 查询偏移量 + // 最小值:0 + Offset uint32 `json:"offset" in:"query=offset" validate:"gte=0"` + + // Limit 查询限制数量 + // 最大值:5000 + Limit uint32 `json:"limit" in:"query=limit" validate:"lte=5000"` +} + +// ListCloudVpcsPageResponse list cloud vpcs page response +type ListCloudVpcsPageResponse struct { + Total uint32 `json:"total"` + CloudVpcs []CloudVpcs `json:"cloudVpcs"` +} + +// CloudVpcs VPC信息 +// @Description vpc信息 +type CloudVpcs struct { + // VpcName vpc名称 + VpcName string `json:"vpcName"` + + // VpcID vpcID + VpcID string `json:"vpcID"` + + // Region 云地域信息 + Region string `json:"region"` + + // OverlayCidr Overlay CIDR列表 + OverlayCidr []string `json:"overlayCidr"` + + // AvailableOverlayIpNum 可用Overlay IP数量 + AvailableOverlayIpNum uint32 `json:"availableOverlayIpNum"` + + // AvailableOverlayCidr 可用Overlay CIDR列表 + AvailableOverlayCidr []string `json:"availableOverlayCidr"` + + // TotalOverlayIpNum Overlay IP总数 + TotalOverlayIpNum uint32 `json:"totalOverlayIpNum"` + + // OverlayIpUsageRate Overlay IP使用率 + OverlayIpUsageRate float64 `json:"overlayIpUsageRate"` + + // UnderlayCidr underlay CIDR列表 + UnderlayCidr []string `json:"underlayCidr"` + + // AvailableUnderlayIpNum 可用Underlay IP数量 + AvailableUnderlayIpNum uint32 `json:"availableUnderlayIpNum"` + + // AvailableUnderlayCidr 可用Underlay CIDR列表 + AvailableUnderlayCidr []string `json:"availableUnderlayCidr"` + + // TotalUnderlayIpNum Underlay IP总数 + TotalUnderlayIpNum uint32 `json:"totalUnderlayIpNum"` + + // UnderlayIpUsageRate Underlay IP使用率 + UnderlayIpUsageRate float64 `json:"underlayIpUsageRate"` + + // CreateTime 创建时间 + CreateTime string `json:"createTime"` + + // OverlayIPCidr Overlay IP CIDR列表(嵌套结构体) + OverlayIPCidr []OverlayIPCidr `json:"overlayIPCidr"` +} + +// OverlayIPCidr Overlay IP CIDR 信息 +// @Description Overlay IP CIDR 详情 +type OverlayIPCidr struct { + // Cidr Overlay IP CIDR + Cidr string `json:"cidr"` + + // IpNum Overlay IP数量 + IpNum uint32 `json:"ipNum"` +} diff --git a/bcs-services/bcs-platform-manager/pkg/types/updatecloudsubnets.go b/bcs-services/bcs-platform-manager/pkg/types/updatecloudsubnets.go new file mode 100644 index 0000000000..82c325fc91 --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/types/updatecloudsubnets.go @@ -0,0 +1,38 @@ +/* + * 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 types pod types +package types + +// UpdateCloudSubnetsRequest update cloud subnets cluster request +type UpdateCloudSubnetsRequest struct { + // CloudID 云信息 + // 最小长度:2 + CloudID string `json:"cloudID" in:"path=cloudID" validate:"min=2"` + + // Region 云地域信息 + Region string `json:"region" validate:"omitempty"` + + // AccountID 云凭证ID + AccountID string `json:"accountID" validate:"omitempty"` + + // SubnetID 子网ID + // 最小长度:1(必填且非空) + SubnetID string `json:"subnetID" in:"query=subnetID" validate:"min=1"` + + // SubnetName 更新子网名称 + SubnetName string `json:"subnetName" validate:"omitempty"` +} + +// UpdateCloudSubnetsResponse update cloud subnets cluster response +type UpdateCloudSubnetsResponse struct { +} diff --git a/bcs-services/bcs-platform-manager/pkg/types/updatecloudvpcs.go b/bcs-services/bcs-platform-manager/pkg/types/updatecloudvpcs.go new file mode 100644 index 0000000000..f31b72fe42 --- /dev/null +++ b/bcs-services/bcs-platform-manager/pkg/types/updatecloudvpcs.go @@ -0,0 +1,40 @@ +/* + * 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 types pod types +package types + +// UpdateCloudVpcsRequest update cloud vpcs cluster request +type UpdateCloudVpcsRequest struct { + // CloudID 云信息 + // 最小长度:2 + CloudID string `json:"cloudID" in:"path=cloudID" validate:"min=2"` + + // Region 云地域信息 + Region string `json:"region" validate:"omitempty"` + + // AccountID 云凭证ID + AccountID string `json:"accountID" validate:"omitempty"` + + // VpcID 过滤查询指定vpc的信息 + VpcID string `json:"vpcID" in:"path=vpcID" validate:"omitempty"` + + // ResourceGroupName Azure Cloud中Vpc所属的resource group名称 + ResourceGroupName string `json:"resourceGroupName" validate:"omitempty"` + + // VpcName vpc名称 + VpcName string `json:"vpcName" validate:"omitempty"` +} + +// UpdateCloudVpcsResponse update cloud vpcs cluster response +type UpdateCloudVpcsResponse struct { +} diff --git a/install/helm/bcs-platform-manager/Chart.yaml b/install/helm/bcs-platform-manager/Chart.yaml index 79b06c9a64..4e306303df 100644 --- a/install/helm/bcs-platform-manager/Chart.yaml +++ b/install/helm/bcs-platform-manager/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: bcs-platform-manager description: 蓝鲸容器服务 bcs-services/bcs-platform-manager 模块 type: application -version: v1.29.12 -appVersion: v1.29.12 +version: v1.29.13 +appVersion: v1.29.13 dependencies: - name: common repository: https://charts.bitnami.com/bitnami diff --git a/install/helm/bcs-platform-manager/README.md b/install/helm/bcs-platform-manager/README.md index 9548d8fa19..3ab3d206c3 100644 --- a/install/helm/bcs-platform-manager/README.md +++ b/install/helm/bcs-platform-manager/README.md @@ -54,7 +54,8 @@ image: ```yaml svcConf: redis: - address: "127.0.0.1:6379" + host: "bcs-redis-master" + port: 6379 db: 0 ## 为空则从环境变量获取 password: "your_redis_password" @@ -150,6 +151,15 @@ svcConf: enabled: false endpoint: "" token: "" + + ## tls 配置 + tls_conf: + server_cert: "/data/bcs/cert/bcs/bcs-server.crt" + server_key: "/data/bcs/cert/bcs/bcs-server.key" + server_ca: "/data/bcs/cert/bcs/bcs-ca.crt" + client_cert: "/data/bcs/cert/bcs/bcs-client.crt" + client_key: "/data/bcs/cert/bcs/bcs-client.key" + client_ca: "/data/bcs/cert/bcs/bcs-ca.crt" ``` ### 部署 Chart diff --git a/install/helm/bcs-platform-manager/templates/deployment.yaml b/install/helm/bcs-platform-manager/templates/deployment.yaml index 3736bcf170..8871354178 100644 --- a/install/helm/bcs-platform-manager/templates/deployment.yaml +++ b/install/helm/bcs-platform-manager/templates/deployment.yaml @@ -45,13 +45,9 @@ spec: env: {{- include "bcs-platform-manager.envs" . | trim | nindent 12 }} livenessProbe: - httpGet: - path: /-/healthy - port: http + {{- toYaml .Values.probe.liveness | nindent 12 }} readinessProbe: - httpGet: - path: /-/ready - port: http + {{- toYaml .Values.probe.readiness | nindent 12 }} resources: {{- toYaml .Values.resources | nindent 12 }} volumeMounts: diff --git a/install/helm/bcs-platform-manager/values.yaml b/install/helm/bcs-platform-manager/values.yaml index 56fce7abb3..2d81b90b4b 100644 --- a/install/helm/bcs-platform-manager/values.yaml +++ b/install/helm/bcs-platform-manager/values.yaml @@ -61,6 +61,11 @@ resources: cpu: 2 memory: 1Gi +## 健康检查 +probe: + liveness: + readiness: + ## 环境变量 envs: {} @@ -77,7 +82,7 @@ svcConf: ## 基础相关配置 base_conf: - http_port: 8099 + http_port: 8080 bind_address: "" app_code: "" app_secret: "" @@ -102,7 +107,8 @@ svcConf: ## Redis 配置信息 redis: - address: "bcs-redis-master:6379" + host: "bcs-redis-master" + port: 6379 db: 2 password: "" ## 以下项非必须可不启用 @@ -128,6 +134,13 @@ svcConf: endpoint: "" token: "" + tls_conf: + server_cert: "/data/bcs/cert/bcs/bcs-server.crt" + server_key: "/data/bcs/cert/bcs/bcs-server.key" + server_ca: "/data/bcs/cert/bcs/bcs-ca.crt" + client_cert: "/data/bcs/cert/bcs/bcs-client.crt" + client_key: "/data/bcs/cert/bcs/bcs-client.key" + client_ca: "/data/bcs/cert/bcs/bcs-ca.crt" ## 挂载的 server. etcd cert 和 jwt key 对应的 secret 名称 secret: bcsServerCerts: bcs-server-certs @@ -179,8 +192,8 @@ service: type: ClusterIP ports: - name: http - port: 8099 - targetPort: 8099 + port: 8080 + targetPort: 8080 protocol: TCP ## 权限控制类