mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 06:34:18 +02:00
enhanced default cluster selection, add 'cluster switch', overhaul json header setting (#47)
This commit is contained in:
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -59,36 +58,37 @@ type apiResponse struct {
|
||||
}
|
||||
|
||||
func ClusterList(conf *cfg.Config) error {
|
||||
table := printer.NewTable(conf, 3, len(conf.Clusters))
|
||||
table := printer.NewTable(conf, 4, len(conf.Clusters))
|
||||
|
||||
table.Addheaders("cluster", "uri", "default")
|
||||
table.Addheaders("cluster", "uri", "reachable", "current")
|
||||
|
||||
idx := 0
|
||||
|
||||
names := make([]string, len(conf.Clusters))
|
||||
for name := range conf.Clusters {
|
||||
names[idx] = name
|
||||
idx++
|
||||
}
|
||||
for name, cluster := range conf.Clusters {
|
||||
reachable := "no"
|
||||
current := "no"
|
||||
|
||||
slices.Sort(names)
|
||||
|
||||
for idx, name := range names {
|
||||
current := name == "default" || name == conf.CurrentCluster
|
||||
cluster := conf.Clusters[name]
|
||||
|
||||
_, err := cluster.ES.Cluster.Health().
|
||||
Header("content-type", "application/json").
|
||||
Header("accept", "application/json").
|
||||
_, err := cluster.ES().Cluster.Health().
|
||||
Do(context.Background())
|
||||
|
||||
if err == nil {
|
||||
name = printer.Colorize(conf, "green", name)
|
||||
reachable = printer.Colorize(conf, "green", "reachable")
|
||||
}
|
||||
|
||||
table.Entries[idx] = []string{name, cluster.Uri, fmt.Sprintf("%t", current)}
|
||||
if cluster.Default {
|
||||
current = printer.Colorize(conf, "green", "yes")
|
||||
|
||||
if err != nil {
|
||||
reachable = printer.Colorize(conf, "red", "no")
|
||||
}
|
||||
}
|
||||
|
||||
table.Entries[idx] = []string{name, cluster.Uri, reachable, current}
|
||||
idx++
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
|
||||
if err := table.Print(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -114,9 +114,9 @@ func ClusterStatus(conf *cfg.Config) error {
|
||||
}
|
||||
|
||||
for _, cluster := range clusters {
|
||||
es := conf.DefaultCluster.ES
|
||||
es := conf.DefaultCluster.ES()
|
||||
if cluster != "default" {
|
||||
es = conf.Clusters[cluster].ES
|
||||
es = conf.Clusters[cluster].ES()
|
||||
}
|
||||
|
||||
responses := make(chan apiResponse, gocount)
|
||||
|
||||
Reference in New Issue
Block a user