add "cluster compare" command and add 1st check (unsync indices) (#2)

This commit is contained in:
T. von Dein
2026-04-27 13:05:30 +02:00
parent 17f92874e5
commit 3cbc67567b
5 changed files with 214 additions and 7 deletions

78
cmd/cluster.go Normal file
View File

@@ -0,0 +1,78 @@
/*
Copyright © 2026 Thomas von Dein
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cmd
import (
"context"
"errors"
"codeberg.org/scip/esctl/pkg/cfg"
"codeberg.org/scip/esctl/pkg/es"
"github.com/urfave/cli/v3"
)
func Cluster(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "cluster",
Aliases: []string{"c"},
Usage: "manage cluster[s]",
Commands: []*cli.Command{
Compare(conf),
},
}
}
func Compare(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "compare",
Aliases: []string{"c"},
Usage: "compare cluster[s] (yaml config with 2 clusters required)",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "exclude",
Usage: "regexp of indicies to exclude",
Destination: &conf.Exclude,
Aliases: []string{"e"},
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
leader := cmd.Args().Get(0)
follower := cmd.Args().Get(1)
if leader == "" || follower == "" {
return errors.New("no leader and follower aliases specified")
}
_, hasLeader := conf.Clusters[leader]
_, hasFollower := conf.Clusters[follower]
if !hasLeader || !hasFollower {
return errors.New("either leader or follower alias not configured")
}
if err := es.ClusterCompare(conf, leader, follower); err != nil {
return err
}
return nil
},
}
}

View File

@@ -76,11 +76,12 @@ func Main() int {
Search(conf),
Index(conf),
Snapshot(conf),
Cluster(conf),
},
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
if err := conf.Init(); err != nil {
Finish(err)
return nil, err
}
log.Init(conf)