From 8a6f00aa2419acd449580dbee30492cb1b3768cf Mon Sep 17 00:00:00 2001 From: yuyudeqiu <52580280+yuyudeqiu@users.noreply.github.com> Date: Mon, 10 Nov 2025 15:24:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=A6=81=E7=94=A8?= =?UTF-8?q?ipv6=E5=AF=BC=E8=87=B4=E6=9C=8D=E5=8A=A1=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bcs-cluster-manager/internal/app/app.go | 2 +- bcs-services/bcs-cluster-manager/main.go | 4 +++- bcs-services/bcs-project-manager/cmd/init.go | 8 +++++--- bcs-services/bcs-storage/app/server.go | 8 ++++++-- bcs-services/bcs-storage/pkg/server/server.go | 13 +++++++++---- bcs-services/bcs-storage/storage/storage.go | 5 ++++- bcs-services/bcs-user-manager/app/app.go | 10 +++++++++- 7 files changed, 37 insertions(+), 13 deletions(-) diff --git a/bcs-services/bcs-cluster-manager/internal/app/app.go b/bcs-services/bcs-cluster-manager/internal/app/app.go index 008b500a7d..afa43f0eae 100644 --- a/bcs-services/bcs-cluster-manager/internal/app/app.go +++ b/bcs-services/bcs-cluster-manager/internal/app/app.go @@ -1067,7 +1067,7 @@ func (cm *ClusterManager) initMicro() error { // nolint if err := dualStackListener.AddListener(ipv4, port); err != nil { // 添加主地址监听 return err } - if ipv6 != ipv4 { + if ipv6 != "" && ipv6 != ipv4 { err := dualStackListener.AddListener(ipv6, port) // 添加副地址监听 if err != nil { return err diff --git a/bcs-services/bcs-cluster-manager/main.go b/bcs-services/bcs-cluster-manager/main.go index 475a253d41..9ff7026042 100644 --- a/bcs-services/bcs-cluster-manager/main.go +++ b/bcs-services/bcs-cluster-manager/main.go @@ -138,7 +138,9 @@ func main() { // nolint } // init serverConfig Ipv6Address - opt.ServerConfig.Ipv6Address = util.InitIPv6Address(opt.ServerConfig.Ipv6Address) + if opt.ServerConfig.Ipv6Address != "" && opt.Address != opt.ServerConfig.Ipv6Address { + opt.ServerConfig.Ipv6Address = util.InitIPv6Address(opt.ServerConfig.Ipv6Address) + } blog.Infof("service ipv6 server address: %s", opt.ServerConfig.Ipv6Address) clusterManager := app.NewClusterManager(opt) diff --git a/bcs-services/bcs-project-manager/cmd/init.go b/bcs-services/bcs-project-manager/cmd/init.go index 84447f9d82..c2c46e94ef 100644 --- a/bcs-services/bcs-project-manager/cmd/init.go +++ b/bcs-services/bcs-project-manager/cmd/init.go @@ -285,7 +285,7 @@ func (p *ProjectService) initPermClient() error { } // initMicro init micro service -// NOCC:golint/fnsize(设计如此) +// nolint:funlen //(设计如此) func (p *ProjectService) initMicro() error { // server listen ip @@ -359,8 +359,10 @@ func (p *ProjectService) initMicro() error { if err := dualStackListener.AddListener(ipv4, port); err != nil { return err } - if err := dualStackListener.AddListener(ipv6, port); err != nil { - return err + if ipv6 == "" && ipv4 != ipv6 { + if err := dualStackListener.AddListener(ipv6, port); err != nil { + return err + } } // get grpc server grpcServer := svc.Server() diff --git a/bcs-services/bcs-storage/app/server.go b/bcs-services/bcs-storage/app/server.go index 5334d2078f..62859776c8 100644 --- a/bcs-services/bcs-storage/app/server.go +++ b/bcs-services/bcs-storage/app/server.go @@ -146,6 +146,10 @@ func initCert(op *options.StorageOptions) { op.ClientCert.IsSSL = true } - // 初始化IPv6Address字段 - op.ServiceConfig.InitIPv6AddressFiled() + if op.IPv6Address == "" { + blog.Infof("op.IPv6Address is empty") + } else { + // 初始化IPv6Address字段 + op.ServiceConfig.InitIPv6AddressFiled() + } } diff --git a/bcs-services/bcs-storage/pkg/server/server.go b/bcs-services/bcs-storage/pkg/server/server.go index b301e9b034..d392fdb2da 100644 --- a/bcs-services/bcs-storage/pkg/server/server.go +++ b/bcs-services/bcs-storage/pkg/server/server.go @@ -87,8 +87,11 @@ func (m *MicroServer) initHTTPServer() error { strconv.FormatUint(m.op.GRPCPort, 10)), grpcDialOpts); err != nil { return errors.Wrapf(err, "register http gateway failed") } - - m.httpServer = ipv6server.NewTlsIPv6Server([]string{m.op.Address, m.op.IPv6Address}, + addresses := []string{m.op.Address} + if m.op.IPv6Address != "" && m.op.Address != m.op.IPv6Address { + addresses = append(addresses, m.op.Address) + } + m.httpServer = ipv6server.NewTlsIPv6Server(addresses, strconv.FormatUint(m.op.HttpPort, 10), "tcp", m.serverTLSConfig, gMux, ) @@ -120,8 +123,10 @@ func (m *MicroServer) initGrpcServer() (err error) { if err = dualStackListener.AddListener(ipv4, port); err != nil { // 添加IPv4地址监听 return errors.Wrapf(err, "add IPv4 address failed") } - if err = dualStackListener.AddListener(ipv6, port); err != nil { // 添加IPv6地址监听 - return errors.Wrapf(err, "add IPv6 address failed") + if ipv6 != "" && ipv6 != ipv4 { + if err = dualStackListener.AddListener(ipv6, port); err != nil { // 添加IPv6地址监听 + return errors.Wrapf(err, "add IPv6 address failed") + } } // 创建go-micro服务 diff --git a/bcs-services/bcs-storage/storage/storage.go b/bcs-services/bcs-storage/storage/storage.go index 8efa860758..823ed176b6 100644 --- a/bcs-services/bcs-storage/storage/storage.go +++ b/bcs-services/bcs-storage/storage/storage.go @@ -288,7 +288,10 @@ func (s *StorageServer) close() { func runPrometheusMetrics(op *options.StorageOptions) { http.Handle("/metrics", promhttp.Handler()) // ipv4 ipv6 - ips := []string{op.Address, op.IPv6Address} + ips := []string{op.Address} + if op.IPv6Address != "" && op.IPv6Address != op.Address { + ips = append(ips, op.IPv6Address) + } ipv6Server := ipv6server.NewIPv6Server(ips, strconv.Itoa(int(op.MetricPort)), "", nil) // 启动server,同时监听v4、v6地址 // nolint diff --git a/bcs-services/bcs-user-manager/app/app.go b/bcs-services/bcs-user-manager/app/app.go index 356d2785d4..f63efe15f9 100644 --- a/bcs-services/bcs-user-manager/app/app.go +++ b/bcs-services/bcs-user-manager/app/app.go @@ -15,12 +15,14 @@ package app import ( "fmt" + "net" "os" "github.com/Tencent/bk-bcs/bcs-common/common" "github.com/Tencent/bk-bcs/bcs-common/common/blog" "github.com/Tencent/bk-bcs/bcs-common/common/encrypt" "github.com/Tencent/bk-bcs/bcs-common/common/ssl" + "github.com/Tencent/bk-bcs/bcs-common/common/types" "github.com/Tencent/bk-bcs/bcs-common/common/util" "github.com/Tencent/bk-bcs/bcs-services/bcs-user-manager/app/pkg/component" @@ -91,7 +93,13 @@ func parseConfig(op *options.UserManagerOptions) (*config.UserMgrConfig, error) userMgrConfig := config.NewUserMgrConfig() userMgrConfig.Address = op.Address - userMgrConfig.IPv6Address = util.InitIPv6Address(op.IPv6Address) + ipv6Address := util.InitIPv6Address(op.IPv6Address) + // 如果没有主动配置IPv6,同时也没有从环境变量解析出可用IPv6,则不监听IPv6地址 + if op.IPv6Address == "" && ipv6Address == net.IPv6loopback.String() && + util.GetIPv6Address(os.Getenv(types.LOCALIPV6)) == "" { + ipv6Address = "" + } + userMgrConfig.IPv6Address = ipv6Address userMgrConfig.Port = op.Port userMgrConfig.InsecureAddress = op.InsecureAddress userMgrConfig.InsecurePort = op.InsecurePort From 799168a592e92ef90b94e3a670cf8bafa25ee75d Mon Sep 17 00:00:00 2001 From: carlchen2 Date: Wed, 12 Nov 2025 19:00:00 +0800 Subject: [PATCH 2/2] fix: golangci-lint --- bcs-services/bcs-user-manager/app/app.go | 1 + 1 file changed, 1 insertion(+) diff --git a/bcs-services/bcs-user-manager/app/app.go b/bcs-services/bcs-user-manager/app/app.go index f63efe15f9..91e344ef39 100644 --- a/bcs-services/bcs-user-manager/app/app.go +++ b/bcs-services/bcs-user-manager/app/app.go @@ -89,6 +89,7 @@ func Run(op *options.UserManagerOptions) { } // parseConfig parse the option to config +// nolint:funlen func parseConfig(op *options.UserManagerOptions) (*config.UserMgrConfig, error) { userMgrConfig := config.NewUserMgrConfig()