|
|
@ -18,7 +18,6 @@ package cmd |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"context" |
|
|
|
"errors" |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"net" |
|
|
|
"net" |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
@ -230,23 +229,25 @@ func (endpoints Endpoints) GetString(i int) string { |
|
|
|
return endpoints[i].String() |
|
|
|
return endpoints[i].String() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (endpoints Endpoints) doAnyHostsResolveToLocalhost() bool { |
|
|
|
func hostResolveToLocalhost(endpoint Endpoint) bool { |
|
|
|
for _, endpoint := range endpoints { |
|
|
|
hostIPs, err := getHostIP(endpoint.Hostname()) |
|
|
|
hostIPs, err := getHostIP(endpoint.Hostname()) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
// Log the message to console about the host resolving
|
|
|
|
continue |
|
|
|
reqInfo := (&logger.ReqInfo{}).AppendTags( |
|
|
|
} |
|
|
|
"host", |
|
|
|
var loopback int |
|
|
|
endpoint.Hostname(), |
|
|
|
for _, hostIP := range hostIPs.ToSlice() { |
|
|
|
) |
|
|
|
if net.ParseIP(hostIP).IsLoopback() { |
|
|
|
ctx := logger.SetReqInfo(context.Background(), reqInfo) |
|
|
|
loopback++ |
|
|
|
logger.LogIf(ctx, err, logger.Application) |
|
|
|
} |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
if loopback == len(hostIPs) { |
|
|
|
var loopback int |
|
|
|
return true |
|
|
|
for _, hostIP := range hostIPs.ToSlice() { |
|
|
|
} |
|
|
|
if net.ParseIP(hostIP).IsLoopback() { |
|
|
|
} |
|
|
|
loopback++ |
|
|
|
return false |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return loopback == len(hostIPs) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (endpoints Endpoints) atleastOneEndpointLocal() bool { |
|
|
|
func (endpoints Endpoints) atleastOneEndpointLocal() bool { |
|
|
@ -294,8 +295,9 @@ func (endpoints Endpoints) UpdateIsLocal(foundPrevLocal bool) error { |
|
|
|
endpoints[i].Hostname(), |
|
|
|
endpoints[i].Hostname(), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if k8sReplicaSet && endpoints.doAnyHostsResolveToLocalhost() { |
|
|
|
if k8sReplicaSet && hostResolveToLocalhost(endpoints[i]) { |
|
|
|
err := errors.New("host found resolves to 127.*, DNS incorrectly configured retrying") |
|
|
|
err := fmt.Errorf("host %s resolves to 127.*, DNS incorrectly configured retrying", |
|
|
|
|
|
|
|
endpoints[i]) |
|
|
|
// time elapsed
|
|
|
|
// time elapsed
|
|
|
|
timeElapsed := time.Since(startTime) |
|
|
|
timeElapsed := time.Since(startTime) |
|
|
|
// log error only if more than 1s elapsed
|
|
|
|
// log error only if more than 1s elapsed
|
|
|
@ -352,6 +354,21 @@ func (endpoints Endpoints) UpdateIsLocal(foundPrevLocal bool) error { |
|
|
|
// previous local we continue to wait to look for
|
|
|
|
// previous local we continue to wait to look for
|
|
|
|
// atleast one local.
|
|
|
|
// atleast one local.
|
|
|
|
resolvedList[i] = false |
|
|
|
resolvedList[i] = false |
|
|
|
|
|
|
|
// time elapsed
|
|
|
|
|
|
|
|
err := fmt.Errorf("no endpoint is local to this host: %s", endpoints[i]) |
|
|
|
|
|
|
|
timeElapsed := time.Since(startTime) |
|
|
|
|
|
|
|
// log error only if more than 1s elapsed
|
|
|
|
|
|
|
|
if timeElapsed > time.Second { |
|
|
|
|
|
|
|
reqInfo.AppendTags("elapsedTime", |
|
|
|
|
|
|
|
humanize.RelTime(startTime, |
|
|
|
|
|
|
|
startTime.Add(timeElapsed), |
|
|
|
|
|
|
|
"elapsed", |
|
|
|
|
|
|
|
"", |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
ctx := logger.SetReqInfo(context.Background(), |
|
|
|
|
|
|
|
reqInfo) |
|
|
|
|
|
|
|
logger.LogIf(ctx, err, logger.Application) |
|
|
|
|
|
|
|
} |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
epsResolved++ |
|
|
|
epsResolved++ |
|
|
|