mirror of
https://github.com/minio/minio.git
synced 2025-01-12 15:33:22 -05:00
Fallback to non-loopback IF addresses for Domain IPs (#6918)
When MINIO_PUBLIC_IPS is not specified and no endpoints are passed as arguments, fallback to the address of non loop-back interfaces. This is useful so users can avoid setting MINIO_PUBLIC_IPS in docker or orchestration scripts, ince users naturally setup an internal network that connects all instances.
This commit is contained in:
parent
950b4ad9af
commit
61145361fd
@ -221,14 +221,18 @@ func handleCommonEnvVars() {
|
|||||||
minioEndpointsEnv, ok := os.LookupEnv("MINIO_PUBLIC_IPS")
|
minioEndpointsEnv, ok := os.LookupEnv("MINIO_PUBLIC_IPS")
|
||||||
if ok {
|
if ok {
|
||||||
minioEndpoints := strings.Split(minioEndpointsEnv, ",")
|
minioEndpoints := strings.Split(minioEndpointsEnv, ",")
|
||||||
globalDomainIPs = set.NewStringSet()
|
|
||||||
for i, ip := range minioEndpoints {
|
for i, ip := range minioEndpoints {
|
||||||
if net.ParseIP(ip) == nil {
|
if net.ParseIP(ip) == nil {
|
||||||
logger.FatalIf(errInvalidArgument, "Unable to initialize Minio server with invalid MINIO_PUBLIC_IPS[%d]: %s", i, ip)
|
logger.FatalIf(errInvalidArgument, "Unable to initialize Minio server with invalid MINIO_PUBLIC_IPS[%d]: %s", i, ip)
|
||||||
}
|
}
|
||||||
globalDomainIPs.Add(ip)
|
|
||||||
}
|
}
|
||||||
|
updateDomainIPs(set.CreateStringSet(minioEndpoints...))
|
||||||
|
} else {
|
||||||
|
// Add found interfaces IP address to global domain IPS,
|
||||||
|
// loopback addresses will be naturally dropped.
|
||||||
|
updateDomainIPs(localIP4)
|
||||||
}
|
}
|
||||||
|
|
||||||
if globalDomainName != "" && !globalDomainIPs.IsEmpty() && globalEtcdClient != nil {
|
if globalDomainName != "" && !globalDomainIPs.IsEmpty() && globalEtcdClient != nil {
|
||||||
var err error
|
var err error
|
||||||
globalDNSConfig, err = dns.NewCoreDNS(globalDomainName, globalDomainIPs, globalMinioPort, globalEtcdClient)
|
globalDNSConfig, err = dns.NewCoreDNS(globalDomainName, globalDomainIPs, globalMinioPort, globalEtcdClient)
|
||||||
|
@ -455,7 +455,12 @@ func CreateEndpoints(serverAddr string, args ...[]string) (string, EndpointList,
|
|||||||
return serverAddr, endpoints, setupType, err
|
return serverAddr, endpoints, setupType, err
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDomainIPs(uniqueArgs)
|
_, dok := os.LookupEnv("MINIO_DOMAIN")
|
||||||
|
_, eok := os.LookupEnv("MINIO_ETCD_ENDPOINTS")
|
||||||
|
_, iok := os.LookupEnv("MINIO_PUBLIC_IPS")
|
||||||
|
if dok && eok && !iok {
|
||||||
|
updateDomainIPs(uniqueArgs)
|
||||||
|
}
|
||||||
|
|
||||||
setupType = DistXLSetupType
|
setupType = DistXLSetupType
|
||||||
return serverAddr, endpoints, setupType, nil
|
return serverAddr, endpoints, setupType, nil
|
||||||
@ -509,21 +514,21 @@ func GetRemotePeers(endpoints EndpointList) []string {
|
|||||||
return peerSet.ToSlice()
|
return peerSet.ToSlice()
|
||||||
}
|
}
|
||||||
|
|
||||||
// In federated and distributed setup, update IP addresses of the hosts passed in command line
|
|
||||||
// if MINIO_PUBLIC_IPS are not set manually
|
|
||||||
func updateDomainIPs(endPoints set.StringSet) {
|
func updateDomainIPs(endPoints set.StringSet) {
|
||||||
_, dok := os.LookupEnv("MINIO_DOMAIN")
|
ipList := set.NewStringSet()
|
||||||
_, eok := os.LookupEnv("MINIO_ETCD_ENDPOINTS")
|
for e := range endPoints {
|
||||||
_, iok := os.LookupEnv("MINIO_PUBLIC_IPS")
|
host, _, err := net.SplitHostPort(e)
|
||||||
if dok && eok && !iok {
|
if err != nil {
|
||||||
globalDomainIPs = set.NewStringSet()
|
if strings.Contains(err.Error(), "missing port in address") {
|
||||||
for e := range endPoints {
|
host = e
|
||||||
host, _, _ := net.SplitHostPort(e)
|
} else {
|
||||||
ipList, _ := getHostIP4(host)
|
continue
|
||||||
remoteIPList := ipList.FuncMatch(func(ip string, matchString string) bool {
|
}
|
||||||
return !strings.HasPrefix(ip, "127.")
|
|
||||||
}, "")
|
|
||||||
globalDomainIPs.Add(remoteIPList.ToSlice()[0])
|
|
||||||
}
|
}
|
||||||
|
IPs, _ := getHostIP4(host)
|
||||||
|
ipList = ipList.Union(IPs)
|
||||||
}
|
}
|
||||||
|
globalDomainIPs = ipList.FuncMatch(func(ip string, matchString string) bool {
|
||||||
|
return !strings.HasPrefix(ip, "127.")
|
||||||
|
}, "")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user