Using first unicastable address as local ip (#20674)

Signed-off-by: Ji Bin <matrixji@live.com>

Signed-off-by: Ji Bin <matrixji@live.com>
This commit is contained in:
Ji Bin 2022-12-07 15:03:19 +08:00 committed by GitHub
parent 33a102c6fc
commit 6692c9999e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 7 deletions

1
go.mod
View File

@ -18,7 +18,6 @@ require (
github.com/confluentinc/confluent-kafka-go v1.9.1
github.com/containerd/cgroups v1.0.2
github.com/gin-gonic/gin v1.7.7
github.com/go-basic/ipv4 v1.0.0
github.com/gofrs/flock v0.8.1
github.com/golang/protobuf v1.5.2
github.com/google/btree v1.0.1

2
go.sum
View File

@ -220,8 +220,6 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
github.com/go-basic/ipv4 v1.0.0 h1:gjyFAa1USC1hhXTkPOwBWDPfMcUaIM+tvo1XzV9EZxs=
github.com/go-basic/ipv4 v1.0.0/go.mod h1:etLBnaxbidQfuqE6wgZQfs38nEWNmzALkxDZe4xY8Dg=
github.com/go-fonts/dejavu v0.1.0/go.mod h1:4Wt4I4OU2Nq9asgDCteaAaWZOV24E+0/Pwo0gppep4g=
github.com/go-fonts/latin-modern v0.2.0/go.mod h1:rQVLdDMK+mK1xscDwsqM5J8U2jrRa3T0ecnM9pNujks=
github.com/go-fonts/liberation v0.1.1/go.mod h1:K6qoJYypsmfVjWg8KOVDQhLc8UDgIK2HYqyqAO9z7GY=

View File

@ -31,7 +31,6 @@ import (
"strings"
"time"
"github.com/go-basic/ipv4"
"go.uber.org/zap"
grpcStatus "google.golang.org/grpc/status"
@ -56,7 +55,16 @@ func CheckGrpcReady(ctx context.Context, targetCh chan error) {
// GetLocalIP return the local ip address
func GetLocalIP() string {
return ipv4.LocalIP()
addrs, err := net.InterfaceAddrs()
if err == nil {
for _, addr := range addrs {
ipaddr, ok := addr.(*net.IPNet)
if ok && ipaddr.IP.IsGlobalUnicast() && ipaddr.IP.To4() != nil {
return ipaddr.IP.String()
}
}
}
return "127.0.0.1"
}
// WaitForComponentStates wait for component's state to be one of the specific states

View File

@ -17,8 +17,8 @@ import (
"sync"
"time"
"github.com/go-basic/ipv4"
"github.com/milvus-io/milvus/internal/log"
"github.com/milvus-io/milvus/internal/util/funcutil"
"go.uber.org/zap"
)
@ -81,7 +81,7 @@ func (p *grpcConfig) init(domain string) {
// LoadFromEnv is used to initialize configuration items from env.
func (p *grpcConfig) LoadFromEnv() {
p.IP = ipv4.LocalIP()
p.IP = funcutil.GetLocalIP()
}
// LoadFromArgs is used to initialize configuration items from args.