mirror of https://github.com/minio/minio.git
treat all localhost endpoints as local setup with same port (#18784)
fixes #18783 and avoids user mistakes
This commit is contained in:
parent
b2b26d9c95
commit
993d96feef
|
@ -103,7 +103,7 @@ func (endpoint Endpoint) GridHost() string {
|
||||||
|
|
||||||
// UpdateIsLocal - resolves the host and updates if it is local or not.
|
// UpdateIsLocal - resolves the host and updates if it is local or not.
|
||||||
func (endpoint *Endpoint) UpdateIsLocal() (err error) {
|
func (endpoint *Endpoint) UpdateIsLocal() (err error) {
|
||||||
if !endpoint.IsLocal {
|
if endpoint.Host != "" {
|
||||||
endpoint.IsLocal, err = isLocalHost(endpoint.Hostname(), endpoint.Port(), globalMinioPort)
|
endpoint.IsLocal, err = isLocalHost(endpoint.Hostname(), endpoint.Port(), globalMinioPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -522,6 +522,16 @@ func (endpoints Endpoints) UpdateIsLocal() error {
|
||||||
continue
|
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
|
// Log the message to console about the host resolving
|
||||||
reqInfo := (&logger.ReqInfo{}).AppendTags(
|
reqInfo := (&logger.ReqInfo{}).AppendTags(
|
||||||
"host",
|
"host",
|
||||||
|
@ -705,6 +715,17 @@ func (p PoolEndpointList) UpdateIsLocal() error {
|
||||||
continue
|
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
|
// Log the message to console about the host resolving
|
||||||
reqInfo := (&logger.ReqInfo{}).AppendTags(
|
reqInfo := (&logger.ReqInfo{}).AppendTags(
|
||||||
"host",
|
"host",
|
||||||
|
@ -859,6 +880,8 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E
|
||||||
return poolEndpoints, setupType, nil
|
return poolEndpoints, setupType, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uniqueArgs := set.NewStringSet()
|
||||||
|
|
||||||
for poolIdx, pool := range poolsLayout {
|
for poolIdx, pool := range poolsLayout {
|
||||||
var endpoints Endpoints
|
var endpoints Endpoints
|
||||||
for setIdx, setLayout := range pool.layout {
|
for setIdx, setLayout := range pool.layout {
|
||||||
|
@ -889,26 +912,10 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E
|
||||||
poolEndpoints[poolIdx] = endpoints
|
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 {
|
if err := poolEndpoints.UpdateIsLocal(); err != nil {
|
||||||
return nil, setupType, config.ErrInvalidErasureEndpoints(nil).Msg(err.Error())
|
return nil, setupType, config.ErrInvalidErasureEndpoints(nil).Msg(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
uniqueArgs := set.NewStringSet()
|
|
||||||
|
|
||||||
for i, endpoints := range poolEndpoints {
|
for i, endpoints := range poolEndpoints {
|
||||||
// Here all endpoints are URL style.
|
// Here all endpoints are URL style.
|
||||||
endpointPathSet := set.NewStringSet()
|
endpointPathSet := set.NewStringSet()
|
||||||
|
@ -918,7 +925,7 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E
|
||||||
|
|
||||||
for _, endpoint := range endpoints {
|
for _, endpoint := range endpoints {
|
||||||
endpointPathSet.Add(endpoint.Path)
|
endpointPathSet.Add(endpoint.Path)
|
||||||
if endpoint.IsLocal {
|
if endpoint.IsLocal && endpoint.Host != "" {
|
||||||
localServerHostSet.Add(endpoint.Hostname())
|
localServerHostSet.Add(endpoint.Hostname())
|
||||||
|
|
||||||
_, port, err := net.SplitHostPort(endpoint.Host)
|
_, port, err := net.SplitHostPort(endpoint.Host)
|
||||||
|
@ -934,9 +941,8 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E
|
||||||
orchestrated := IsKubernetes() || IsDocker()
|
orchestrated := IsKubernetes() || IsDocker()
|
||||||
reverseProxy := (env.Get("_MINIO_REVERSE_PROXY", "") != "") && ((env.Get("MINIO_CI_CD", "") != "") || (env.Get("CI", "") != ""))
|
reverseProxy := (env.Get("_MINIO_REVERSE_PROXY", "") != "") && ((env.Get("MINIO_CI_CD", "") != "") || (env.Get("CI", "") != ""))
|
||||||
// If not orchestrated
|
// If not orchestrated
|
||||||
if !orchestrated &&
|
|
||||||
// and not setup in reverse proxy
|
// and not setup in reverse proxy
|
||||||
!reverseProxy {
|
if !orchestrated && !reverseProxy {
|
||||||
// Check whether same path is not used in endpoints of a host on different port.
|
// 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
|
// Only verify this on baremetal setups, DNS is not available in orchestrated
|
||||||
// environments so we can't do much here.
|
// environments so we can't do much here.
|
||||||
|
@ -944,7 +950,10 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E
|
||||||
hostIPCache := make(map[string]set.StringSet)
|
hostIPCache := make(map[string]set.StringSet)
|
||||||
for _, endpoint := range endpoints {
|
for _, endpoint := range endpoints {
|
||||||
host := endpoint.Hostname()
|
host := endpoint.Hostname()
|
||||||
hostIPSet, ok := hostIPCache[host]
|
var hostIPSet set.StringSet
|
||||||
|
if host != "" {
|
||||||
|
var ok bool
|
||||||
|
hostIPSet, ok = hostIPCache[host]
|
||||||
if !ok {
|
if !ok {
|
||||||
var err error
|
var err error
|
||||||
hostIPSet, err = getHostIP(host)
|
hostIPSet, err = getHostIP(host)
|
||||||
|
@ -953,6 +962,7 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E
|
||||||
}
|
}
|
||||||
hostIPCache[host] = hostIPSet
|
hostIPCache[host] = hostIPSet
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if IPSet, ok := pathIPMap[endpoint.Path]; ok {
|
if IPSet, ok := pathIPMap[endpoint.Path]; ok {
|
||||||
if !IPSet.Intersection(hostIPSet).IsEmpty() {
|
if !IPSet.Intersection(hostIPSet).IsEmpty() {
|
||||||
return nil, setupType,
|
return nil, setupType,
|
||||||
|
@ -982,6 +992,7 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E
|
||||||
|
|
||||||
// Add missing port in all endpoints.
|
// Add missing port in all endpoints.
|
||||||
for i := range endpoints {
|
for i := range endpoints {
|
||||||
|
if endpoints[i].Host != "" {
|
||||||
_, port, err := net.SplitHostPort(endpoints[i].Host)
|
_, port, err := net.SplitHostPort(endpoints[i].Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
endpoints[i].Host = net.JoinHostPort(endpoints[i].Host, serverAddrPort)
|
endpoints[i].Host = net.JoinHostPort(endpoints[i].Host, serverAddrPort)
|
||||||
|
@ -990,6 +1001,7 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E
|
||||||
endpoints[i].IsLocal = false
|
endpoints[i].IsLocal = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// All endpoints are pointing to local host
|
// All endpoints are pointing to local host
|
||||||
if len(endpoints) == localEndpointCount {
|
if len(endpoints) == localEndpointCount {
|
||||||
|
@ -1006,10 +1018,12 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E
|
||||||
// This means it is DistErasure setup.
|
// This means it is DistErasure setup.
|
||||||
}
|
}
|
||||||
|
|
||||||
poolEndpoints[i] = endpoints
|
|
||||||
|
|
||||||
for _, endpoint := range endpoints {
|
for _, endpoint := range endpoints {
|
||||||
|
if endpoint.Host != "" {
|
||||||
uniqueArgs.Add(endpoint.Host)
|
uniqueArgs.Add(endpoint.Host)
|
||||||
|
} else {
|
||||||
|
uniqueArgs.Add(net.JoinHostPort("localhost", serverAddrPort))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
poolEndpoints[i] = endpoints
|
poolEndpoints[i] = endpoints
|
||||||
|
@ -1020,14 +1034,22 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E
|
||||||
updateDomainIPs(uniqueArgs)
|
updateDomainIPs(uniqueArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
erasureType := len(uniqueArgs.ToSlice()) == 1
|
||||||
|
|
||||||
for _, endpoints := range poolEndpoints {
|
for _, endpoints := range poolEndpoints {
|
||||||
// Return Erasure setup when all endpoints are path style.
|
// Return Erasure setup when all endpoints are path style.
|
||||||
if endpoints[0].Type() == PathEndpointType {
|
if endpoints[0].Type() == PathEndpointType {
|
||||||
setupType = ErasureSetupType
|
setupType = ErasureSetupType
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if endpoints[0].Type() == URLEndpointType && setupType != DistErasureSetupType {
|
if endpoints[0].Type() == URLEndpointType {
|
||||||
|
if erasureType {
|
||||||
|
setupType = ErasureSetupType
|
||||||
|
} else {
|
||||||
setupType = DistErasureSetupType
|
setupType = DistErasureSetupType
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return poolEndpoints, setupType, nil
|
return poolEndpoints, setupType, nil
|
||||||
|
|
|
@ -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: "/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: "/d3"}, IsLocal: true},
|
||||||
Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost:9000", Path: "/d4"}, 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.
|
// 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")},
|
{"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")},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue