diff --git a/cmd/endpoint.go b/cmd/endpoint.go index 5be80b3dc899d..84a6a61571e2b 100644 --- a/cmd/endpoint.go +++ b/cmd/endpoint.go @@ -103,7 +103,7 @@ func (endpoint Endpoint) GridHost() string { // UpdateIsLocal - resolves the host and updates if it is local or not. func (endpoint *Endpoint) UpdateIsLocal() (err error) { - if !endpoint.IsLocal { + if endpoint.Host != "" { endpoint.IsLocal, err = isLocalHost(endpoint.Hostname(), endpoint.Port(), globalMinioPort) if err != nil { return err @@ -522,6 +522,16 @@ func (endpoints Endpoints) UpdateIsLocal() error { continue } + if endpoints[i].Host == "" { + resolvedList[i] = true + endpoints[i].IsLocal = true + epsResolved++ + if !foundLocal { + foundLocal = true + } + continue + } + // Log the message to console about the host resolving reqInfo := (&logger.ReqInfo{}).AppendTags( "host", @@ -705,6 +715,17 @@ func (p PoolEndpointList) UpdateIsLocal() error { continue } + if endpoint.Host == "" { + if !foundLocal { + foundLocal = true + } + endpoint.IsLocal = true + endpoints[j] = endpoint + epsResolved++ + resolvedList[endpoint] = true + continue + } + // Log the message to console about the host resolving reqInfo := (&logger.ReqInfo{}).AppendTags( "host", @@ -859,6 +880,8 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E return poolEndpoints, setupType, nil } + uniqueArgs := set.NewStringSet() + for poolIdx, pool := range poolsLayout { var endpoints Endpoints for setIdx, setLayout := range pool.layout { @@ -889,26 +912,10 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E poolEndpoints[poolIdx] = endpoints } - for _, endpoints := range poolEndpoints { - // Return Erasure setup when all endpoints are path style. - if endpoints[0].Type() == PathEndpointType { - setupType = ErasureSetupType - } - if endpoints[0].Type() == URLEndpointType && setupType != DistErasureSetupType { - setupType = DistErasureSetupType - } - } - - if setupType == ErasureSetupType { - return poolEndpoints, setupType, nil - } - if err := poolEndpoints.UpdateIsLocal(); err != nil { return nil, setupType, config.ErrInvalidErasureEndpoints(nil).Msg(err.Error()) } - uniqueArgs := set.NewStringSet() - for i, endpoints := range poolEndpoints { // Here all endpoints are URL style. endpointPathSet := set.NewStringSet() @@ -918,7 +925,7 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E for _, endpoint := range endpoints { endpointPathSet.Add(endpoint.Path) - if endpoint.IsLocal { + if endpoint.IsLocal && endpoint.Host != "" { localServerHostSet.Add(endpoint.Hostname()) _, port, err := net.SplitHostPort(endpoint.Host) @@ -934,9 +941,8 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E orchestrated := IsKubernetes() || IsDocker() reverseProxy := (env.Get("_MINIO_REVERSE_PROXY", "") != "") && ((env.Get("MINIO_CI_CD", "") != "") || (env.Get("CI", "") != "")) // If not orchestrated - if !orchestrated && - // and not setup in reverse proxy - !reverseProxy { + // and not setup in reverse proxy + if !orchestrated && !reverseProxy { // Check whether same path is not used in endpoints of a host on different port. // Only verify this on baremetal setups, DNS is not available in orchestrated // environments so we can't do much here. @@ -944,14 +950,18 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E hostIPCache := make(map[string]set.StringSet) for _, endpoint := range endpoints { host := endpoint.Hostname() - hostIPSet, ok := hostIPCache[host] - if !ok { - var err error - hostIPSet, err = getHostIP(host) - if err != nil { - return nil, setupType, config.ErrInvalidErasureEndpoints(nil).Msg(fmt.Sprintf("host '%s' cannot resolve: %s", host, err)) + var hostIPSet set.StringSet + if host != "" { + var ok bool + hostIPSet, ok = hostIPCache[host] + if !ok { + var err error + hostIPSet, err = getHostIP(host) + if err != nil { + return nil, setupType, config.ErrInvalidErasureEndpoints(nil).Msg(fmt.Sprintf("host '%s' cannot resolve: %s", host, err)) + } + hostIPCache[host] = hostIPSet } - hostIPCache[host] = hostIPSet } if IPSet, ok := pathIPMap[endpoint.Path]; ok { if !IPSet.Intersection(hostIPSet).IsEmpty() { @@ -982,12 +992,14 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E // Add missing port in all endpoints. for i := range endpoints { - _, port, err := net.SplitHostPort(endpoints[i].Host) - if err != nil { - endpoints[i].Host = net.JoinHostPort(endpoints[i].Host, serverAddrPort) - } else if endpoints[i].IsLocal && serverAddrPort != port { - // If endpoint is local, but port is different than serverAddrPort, then make it as remote. - endpoints[i].IsLocal = false + if endpoints[i].Host != "" { + _, port, err := net.SplitHostPort(endpoints[i].Host) + if err != nil { + endpoints[i].Host = net.JoinHostPort(endpoints[i].Host, serverAddrPort) + } else if endpoints[i].IsLocal && serverAddrPort != port { + // If endpoint is local, but port is different than serverAddrPort, then make it as remote. + endpoints[i].IsLocal = false + } } } @@ -1006,10 +1018,12 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E // This means it is DistErasure setup. } - poolEndpoints[i] = endpoints - for _, endpoint := range endpoints { - uniqueArgs.Add(endpoint.Host) + if endpoint.Host != "" { + uniqueArgs.Add(endpoint.Host) + } else { + uniqueArgs.Add(net.JoinHostPort("localhost", serverAddrPort)) + } } poolEndpoints[i] = endpoints @@ -1020,13 +1034,21 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E updateDomainIPs(uniqueArgs) } + erasureType := len(uniqueArgs.ToSlice()) == 1 + for _, endpoints := range poolEndpoints { // Return Erasure setup when all endpoints are path style. if endpoints[0].Type() == PathEndpointType { setupType = ErasureSetupType + break } - if endpoints[0].Type() == URLEndpointType && setupType != DistErasureSetupType { - setupType = DistErasureSetupType + if endpoints[0].Type() == URLEndpointType { + if erasureType { + setupType = ErasureSetupType + } else { + setupType = DistErasureSetupType + } + break } } diff --git a/cmd/endpoint_test.go b/cmd/endpoint_test.go index 88a85befa74a1..5fd31ed8b9ae5 100644 --- a/cmd/endpoint_test.go +++ b/cmd/endpoint_test.go @@ -258,7 +258,7 @@ func TestCreateEndpoints(t *testing.T) { Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost:9000", Path: "/d2"}, IsLocal: true}, Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost:9000", Path: "/d3"}, IsLocal: true}, Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost:9000", Path: "/d4"}, IsLocal: true}, - }, DistErasureSetupType, nil}, + }, ErasureSetupType, nil}, // DistErasure Setup with URLEndpointType having mixed naming to local host. {"127.0.0.1:10000", []string{"http://localhost/d1", "http://localhost/d2", "http://127.0.0.1/d3", "http://127.0.0.1/d4"}, "", Endpoints{}, -1, fmt.Errorf("all local endpoints should not have different hostnames/ips")},