pick internode interface properly via globalLocalNodeName (#17680)

current code will not pick the right interface name
if --address or --interface is not provided.
This commit is contained in:
Harshavardhana 2023-07-18 19:18:11 -07:00 committed by GitHub
parent 73a056999c
commit 4f257bf1e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -248,13 +248,13 @@ func serverHandleCmdArgs(ctx *cli.Context) {
logger.FatalIf(err, "Invalid command line arguments")
globalNodes = globalEndpoints.GetNodes()
// Initialize, see which NIC the service is running on, and save it as global
_ = getGlobalInternodeInterface(ctx.String("interface"))
globalLocalNodeName = GetLocalPeer(globalEndpoints, globalMinioHost, globalMinioPort)
nodeNameSum := sha256.Sum256([]byte(globalLocalNodeName))
globalLocalNodeNameHex = hex.EncodeToString(nodeNameSum[:])
// Initialize, see which NIC the service is running on, and save it as global value
setGlobalInternodeInterface(ctx.String("interface"))
// allow transport to be HTTP/1.1 for proxying.
globalProxyTransport = NewCustomHTTPProxyTransport()()
globalProxyEndpoints = GetProxyEndpoints(globalEndpoints)
@ -464,18 +464,27 @@ func initConfigSubsystem(ctx context.Context, newObject ObjectLayer) error {
return nil
}
func getGlobalInternodeInterface(interfs ...string) string {
func setGlobalInternodeInterface(interfaceName string) {
globalInternodeInterfaceOnce.Do(func() {
if len(interfs) != 0 && strings.TrimSpace(interfs[0]) != "" {
globalInternodeInterface = interfs[0]
if interfaceName != "" {
globalInternodeInterface = interfaceName
return
}
ip := "127.0.0.1"
host, _ := mustSplitHostPort(globalMinioAddr)
host, _ := mustSplitHostPort(globalLocalNodeName)
if host != "" {
ip = host
if net.ParseIP(host) != nil {
ip = host
} else {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
haddrs, err := globalDNSCache.LookupHost(ctx, host)
if err == nil {
ip = haddrs[0]
}
}
}
globalInternodeInterface = ip
ifs, _ := net.Interfaces()
for _, interf := range ifs {
addrs, err := interf.Addrs()
@ -488,7 +497,6 @@ func getGlobalInternodeInterface(interfs ...string) string {
}
}
})
return globalInternodeInterface
}
// Return the list of address that MinIO server needs to listen on: