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..91e344ef39 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" @@ -87,11 +89,18 @@ func Run(op *options.UserManagerOptions) { } // parseConfig parse the option to config +// nolint:funlen 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