Simplify k8s replicated set deployment (#8666)

Continuation from #8629 which basically broke
zone deployments on k8s statefulset environment
due to incorrect assumptions which made it work
on replicated set.

Fix this properly such that this container works
for both replicated set and stateful set deployment
master
Harshavardhana 5 years ago committed by kannappanr
parent e047ac52b8
commit 39face27cf
  1. 39
      cmd/endpoint.go

@ -230,40 +230,23 @@ func (endpoints Endpoints) GetString(i int) string {
return endpoints[i].String() return endpoints[i].String()
} }
func (endpoints Endpoints) atleastOneEndpointLocal() bool { func (endpoints Endpoints) doAnyHostsResolveToLocalhost() bool {
for _, endpoint := range endpoints {
if endpoint.IsLocal {
return true
}
}
return false
}
func (endpoints Endpoints) doAllHostsResolveToLocalhost() bool {
var endpointHosts = map[string]set.StringSet{}
for _, endpoint := range endpoints { for _, endpoint := range endpoints {
hostIPs, err := getHostIP(endpoint.Hostname()) hostIPs, err := getHostIP(endpoint.Hostname())
if err != nil { if err != nil {
continue continue
} }
endpointHosts[endpoint.Hostname()] = hostIPs var loopback int
} for _, hostIP := range hostIPs.ToSlice() {
sameHosts := make(map[string]int) if net.ParseIP(hostIP).IsLoopback() {
for hostName, endpointIPs := range endpointHosts { loopback++
for _, endpointIP := range endpointIPs.ToSlice() {
if net.ParseIP(endpointIP).IsLoopback() {
sameHosts[hostName]++
} }
} }
if loopback == len(hostIPs) {
return true
} }
ok := true
for _, localCount := range sameHosts {
ok = ok && localCount > 0
} }
if len(sameHosts) == 0 {
return false return false
}
return ok
} }
// UpdateIsLocal - resolves the host and discovers the local host. // UpdateIsLocal - resolves the host and discovers the local host.
@ -301,8 +284,8 @@ func (endpoints Endpoints) UpdateIsLocal() error {
endpoints[i].Hostname(), endpoints[i].Hostname(),
) )
if orchestrated && endpoints.doAllHostsResolveToLocalhost() { if orchestrated && endpoints.doAnyHostsResolveToLocalhost() {
err := errors.New("hosts resolve to same IP, DNS not updated on k8s") err := errors.New("hosts resolve 127.*, DNS not updated on k8s")
// 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
@ -346,10 +329,6 @@ func (endpoints Endpoints) UpdateIsLocal() error {
} else { } else {
resolvedList[i] = true resolvedList[i] = true
endpoints[i].IsLocal = isLocal endpoints[i].IsLocal = isLocal
if orchestrated && !endpoints.atleastOneEndpointLocal() {
resolvedList[i] = false
continue
}
epsResolved++ epsResolved++
if !foundLocal { if !foundLocal {
foundLocal = isLocal foundLocal = isLocal

Loading…
Cancel
Save