Skip to content

Commit

Permalink
--story=120659016 bcs-monitor overview 监控忽略超级节点 (merge request !2049)
Browse files Browse the repository at this point in the history
Squash merge branch 'fix/lint' into 'master'
fix style

 



TAPD: --story=120659016
  • Loading branch information
adevjoe authored and ifooth committed Nov 12, 2024
1 parent 599f46f commit 8dc3500
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bcs-services/bcs-monitor/pkg/component/k8sclient/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func GetNodeList(ctx context.Context, clusterID string, excludeMasterRole, filte
nodeNameList := make([]string, 0)
for _, item := range nodeList.Items {
// 过滤掉被标记的节点,该 annotation 表示该节点不参与资源调度
// nolint
if v, ok := item.Annotations["io.tencent.bcs.dev/filter-node-resource"]; ok && v == "true" && filter {
continue
}
Expand Down Expand Up @@ -114,7 +115,6 @@ func GetMasterNodeList(ctx context.Context, clusterID string) ([]string, []strin
}

listOptions := metav1.ListOptions{}
listOptions.LabelSelector = "node-role.kubernetes.io/master=true,io.tencent.bcs.dev/filter-node-resource!=true"

nodeList, err := client.CoreV1().Nodes().List(ctx, listOptions)
if err != nil {
Expand All @@ -124,6 +124,20 @@ func GetMasterNodeList(ctx context.Context, clusterID string) ([]string, []strin
nodeIPList := make([]string, 0)
nodeNameList := make([]string, 0)
for _, item := range nodeList.Items {
// 过滤掉被标记的节点,该 annotation 表示该节点不参与资源调度
var (
filter bool
master bool
)
if v, ok := item.Annotations["io.tencent.bcs.dev/filter-node-resource"]; ok && v == "true" {
filter = true
}
if v, ok := item.Labels["node-role.kubernetes.io/master"]; ok && v == "true" {
master = true
}
if !filter && !master {
continue
}
nodeNameList = append(nodeNameList, item.Name)
for _, addr := range item.Status.Addresses {
if addr.Type == v1.NodeInternalIP {
Expand Down
14 changes: 14 additions & 0 deletions bcs-services/cluster-resources/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (crSvc *clusterResourcesService) initMicro() error {
return err
}

// ipv6 support
if crSvc.conf.Server.AddressIPv6 != "" {
ipv6Addr := net.JoinHostPort(crSvc.conf.Server.AddressIPv6, grpcPort)
metadata[types.IPV6] = ipv6Addr
Expand Down Expand Up @@ -184,6 +185,7 @@ func (crSvc *clusterResourcesService) initMicro() error {
return err
}

// init micro service
crSvc.microSvc = micro.NewService(micro.AfterStop(func() error {
audit2.GetAuditClient().Close()
return nil
Expand Down Expand Up @@ -247,6 +249,7 @@ func (crSvc *clusterResourcesService) initRegistry() error {

var etcdTLS *tls.Config
var err error
// etcd cert
if crSvc.conf.Etcd.EtcdCa != "" && crSvc.conf.Etcd.EtcdCert != "" && crSvc.conf.Etcd.EtcdKey != "" {
etcdSecure = true
etcdTLS, err = ssl.ClientTslConfVerity(
Expand All @@ -272,6 +275,7 @@ func (crSvc *clusterResourcesService) initRegistry() error {

// initTLSConfig 初始化 Server 与 client TLS 配置
func (crSvc *clusterResourcesService) initTLSConfig() error {
// server tls config
if crSvc.conf.Server.Cert != "" && crSvc.conf.Server.Key != "" && crSvc.conf.Server.Ca != "" {
tlsConfig, err := ssl.ServerTslConfVerityClient(
crSvc.conf.Server.Ca, crSvc.conf.Server.Cert, crSvc.conf.Server.Key, crSvc.conf.Server.CertPwd,
Expand All @@ -284,6 +288,7 @@ func (crSvc *clusterResourcesService) initTLSConfig() error {
log.Info(crSvc.ctx, "load cluster resources server tls config successfully")
}

// client tls config
if crSvc.conf.Client.Cert != "" && crSvc.conf.Client.Key != "" && crSvc.conf.Client.Ca != "" {
tlsConfig, err := ssl.ClientTslConfVerity(
crSvc.conf.Client.Ca, crSvc.conf.Client.Cert, crSvc.conf.Client.Key, crSvc.conf.Client.CertPwd,
Expand All @@ -305,6 +310,7 @@ func (crSvc *clusterResourcesService) initHTTPService() error {
runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.JSONPb{OrigName: true, EmitDefaults: true}),
)

// grpc dial options
grpcDialOpts := []grpc.DialOption{
grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(conf.MaxGrpcMsgSize),
Expand Down Expand Up @@ -337,6 +343,7 @@ func (crSvc *clusterResourcesService) initHTTPService() error {
}
}

// init route
router := mux.NewRouter()
router.Handle("/{uri:.*}", rmMux)
log.Info(crSvc.ctx, "register grpc service handler to path /")
Expand All @@ -363,6 +370,7 @@ func (crSvc *clusterResourcesService) initHTTPService() error {
),
}

// ipv6 support
dualStackListener := listener.NewDualStackListener()
if err := dualStackListener.AddListenerWithAddr(httpAddr); err != nil {
return err
Expand Down Expand Up @@ -395,6 +403,7 @@ func handlerSwagger(w http.ResponseWriter, r *http.Request) {
httpSwagger.Handler(httpSwagger.URL("cluster-resources.swagger.json")).ServeHTTP(w, r)
}

// run 启动 HTTP 服务
func (crSvc *clusterResourcesService) run(httpAddr string, dualStackListener net.Listener) {
var err error
log.Info(crSvc.ctx, "start http gateway server on address %s", httpAddr)
Expand Down Expand Up @@ -424,6 +433,7 @@ func (crSvc *clusterResourcesService) initMetricService() error {
Handler: metricMux,
}

// ipv6 support
dualStackListener := listener.NewDualStackListener()
if err := dualStackListener.AddListenerWithAddr(metricAddr); err != nil {
return err
Expand All @@ -436,6 +446,7 @@ func (crSvc *clusterResourcesService) initMetricService() error {
log.Info(crSvc.ctx, "metric serve dualStackListener with ipv6: %s", ipv6Addr)
}

// start metric server
go func() {
var err error
log.Info(crSvc.ctx, "start metric server on address %s", metricAddr)
Expand Down Expand Up @@ -476,6 +487,8 @@ func (crSvc *clusterResourcesService) initModel() error {

password = string(realPwd)
}

// init mongo options
mongoOptions := &mongo.Options{
Hosts: strings.Split(crSvc.conf.Mongo.Address, ","),
ConnectTimeoutSeconds: int(crSvc.conf.Mongo.ConnectTimeout),
Expand All @@ -488,6 +501,7 @@ func (crSvc *clusterResourcesService) initModel() error {
Monitor: otelmongo.NewMonitor(),
}

// init mongo db
mongoDB, err := mongo.NewDB(mongoOptions)
if err != nil {
log.Error(crSvc.ctx, "init mongo db failed, err %s", err.Error())
Expand Down

0 comments on commit 8dc3500

Please sign in to comment.