mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 04:54:18 +02:00
check at bootstrap which cluster is reachable, fix current cluster
This commit is contained in:
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package cfg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -76,6 +77,8 @@ func (conf *Config) Init() error {
|
||||
}
|
||||
}
|
||||
|
||||
conf.SetupES()
|
||||
|
||||
if conf.CurrentCluster != "" {
|
||||
current, exists := conf.Clusters[conf.CurrentCluster]
|
||||
if !exists {
|
||||
@@ -83,14 +86,29 @@ func (conf *Config) Init() error {
|
||||
} else {
|
||||
conf.DefaultCluster = current
|
||||
}
|
||||
} else {
|
||||
if len(conf.Clusters) == 1 {
|
||||
for _, cluster := range conf.Clusters {
|
||||
conf.DefaultCluster = cluster
|
||||
}
|
||||
} else {
|
||||
for _, cluster := range conf.Clusters {
|
||||
_, err := cluster.ES.Cluster.Health().
|
||||
Header("content-type", "application/json").
|
||||
Header("accept", "application/json").
|
||||
Do(context.Background())
|
||||
|
||||
if err == nil {
|
||||
conf.DefaultCluster = cluster
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if conf.Debug {
|
||||
repr.Println(conf)
|
||||
}
|
||||
|
||||
conf.SetupES()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user