fix: replica set deployment for multi tenants (#8673)

Changes in IP underneath are dynamic in replica sets
with multiple tenants, so deploying in that fashion
will not work until we wait for atleast one participatory
server to be local.

This PR also ensures that multi-tenant zone expansion also
works in replica set k8s deployments.

Introduces a new ENV `KUBERNETES_REPLICA_SET` check to call
appropriate code paths.
This commit is contained in:
Harshavardhana
2019-12-19 13:45:56 -08:00
committed by kannappanr
parent 39face27cf
commit d140074773
7 changed files with 56 additions and 17 deletions

View File

@@ -249,9 +249,19 @@ func (endpoints Endpoints) doAnyHostsResolveToLocalhost() bool {
return false
}
func (endpoints Endpoints) atleastOneEndpointLocal() bool {
for _, endpoint := range endpoints {
if endpoint.IsLocal {
return true
}
}
return false
}
// UpdateIsLocal - resolves the host and discovers the local host.
func (endpoints Endpoints) UpdateIsLocal() error {
func (endpoints Endpoints) UpdateIsLocal(foundPrevLocal bool) error {
orchestrated := IsDocker() || IsKubernetes()
k8sReplicaSet := IsKubernetesReplicaSet()
var epsResolved int
var foundLocal bool
@@ -284,8 +294,8 @@ func (endpoints Endpoints) UpdateIsLocal() error {
endpoints[i].Hostname(),
)
if orchestrated && endpoints.doAnyHostsResolveToLocalhost() {
err := errors.New("hosts resolve 127.*, DNS not updated on k8s")
if k8sReplicaSet && endpoints.doAnyHostsResolveToLocalhost() {
err := errors.New("host found resolves to 127.*, DNS incorrectly configured retrying")
// time elapsed
timeElapsed := time.Since(startTime)
// log error only if more than 1s elapsed
@@ -329,6 +339,21 @@ func (endpoints Endpoints) UpdateIsLocal() error {
} else {
resolvedList[i] = true
endpoints[i].IsLocal = isLocal
if k8sReplicaSet && !endpoints.atleastOneEndpointLocal() && !foundPrevLocal {
// In replicated set in k8s deployment, IPs might
// get resolved for older IPs, add this code
// to ensure that we wait for this server to
// participate atleast one disk and be local.
//
// In special cases for replica set with expanded
// zone setups we need to make sure to provide
// value of foundPrevLocal from zone1 if we already
// found a local setup. Only if we haven't found
// previous local we continue to wait to look for
// atleast one local.
resolvedList[i] = false
continue
}
epsResolved++
if !foundLocal {
foundLocal = isLocal
@@ -439,7 +464,7 @@ func checkCrossDeviceMounts(endpoints Endpoints) (err error) {
}
// CreateEndpoints - validates and creates new endpoints for given args.
func CreateEndpoints(serverAddr string, args ...[]string) (Endpoints, SetupType, error) {
func CreateEndpoints(serverAddr string, foundLocal bool, args ...[]string) (Endpoints, SetupType, error) {
var endpoints Endpoints
var setupType SetupType
var err error
@@ -505,7 +530,7 @@ func CreateEndpoints(serverAddr string, args ...[]string) (Endpoints, SetupType,
return endpoints, setupType, nil
}
if err = endpoints.UpdateIsLocal(); err != nil {
if err = endpoints.UpdateIsLocal(foundLocal); err != nil {
return endpoints, setupType, config.ErrInvalidErasureEndpoints(nil).Msg(err.Error())
}
@@ -695,6 +720,6 @@ func updateDomainIPs(endPoints set.StringSet) {
if err != nil {
host = ip
}
return !net.ParseIP(host).IsLoopback()
return !net.ParseIP(host).IsLoopback() && host != "localhost"
}, "")
}