From 90e5af76f366cbdc97600e441222a233d8a4a8fe Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Thu, 12 Apr 2018 10:32:32 -0700 Subject: [PATCH] etcdctl/ctlv3: use new snapshot package Signed-off-by: Gyuho Lee --- etcdctl/ctlv3/command/global.go | 9 +++++++++ etcdctl/ctlv3/command/snapshot_command.go | 23 +++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/etcdctl/ctlv3/command/global.go b/etcdctl/ctlv3/command/global.go index 618e4aafb..753d0ad8f 100644 --- a/etcdctl/ctlv3/command/global.go +++ b/etcdctl/ctlv3/command/global.go @@ -148,6 +148,15 @@ func clientConfigFromCmd(cmd *cobra.Command) *clientConfig { return cfg } +func mustClientCfgFromCmd(cmd *cobra.Command) *clientv3.Config { + cc := clientConfigFromCmd(cmd) + cfg, err := newClientCfg(cc.endpoints, cc.dialTimeout, cc.keepAliveTime, cc.keepAliveTimeout, cc.scfg, cc.acfg) + if err != nil { + ExitWithError(ExitBadArgs, err) + } + return cfg +} + func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client { cfg := clientConfigFromCmd(cmd) return cfg.mustClient() diff --git a/etcdctl/ctlv3/command/snapshot_command.go b/etcdctl/ctlv3/command/snapshot_command.go index c48045d26..22703feef 100644 --- a/etcdctl/ctlv3/command/snapshot_command.go +++ b/etcdctl/ctlv3/command/snapshot_command.go @@ -20,7 +20,6 @@ import ( "path/filepath" "strings" - "github.com/coreos/etcd/pkg/types" "github.com/coreos/etcd/snapshot" "github.com/spf13/cobra" @@ -104,10 +103,11 @@ func snapshotSaveCommandFunc(cmd *cobra.Command, args []string) { if debug { lg = zap.NewExample() } - sp := snapshot.NewV3(mustClientFromCmd(cmd), lg) + sp := snapshot.NewV3(lg) + cfg := mustClientCfgFromCmd(cmd) path := args[0] - if err := sp.Save(context.TODO(), path); err != nil { + if err := sp.Save(context.TODO(), *cfg, path); err != nil { ExitWithError(ExitInterrupted, err) } fmt.Printf("Snapshot saved at %s\n", path) @@ -128,8 +128,7 @@ func snapshotStatusCommandFunc(cmd *cobra.Command, args []string) { if debug { lg = zap.NewExample() } - sp := snapshot.NewV3(nil, lg) - + sp := snapshot.NewV3(lg) ds, err := sp.Status(args[0]) if err != nil { ExitWithError(ExitError, err) @@ -143,11 +142,6 @@ func snapshotRestoreCommandFunc(cmd *cobra.Command, args []string) { ExitWithError(ExitBadArgs, err) } - urlmap, uerr := types.NewURLsMap(restoreCluster) - if uerr != nil { - ExitWithError(ExitBadArgs, uerr) - } - dataDir := restoreDataDir if dataDir == "" { dataDir = restoreName + ".etcd" @@ -166,15 +160,16 @@ func snapshotRestoreCommandFunc(cmd *cobra.Command, args []string) { if debug { lg = zap.NewExample() } - sp := snapshot.NewV3(nil, lg) + sp := snapshot.NewV3(lg) - if err := sp.Restore(args[0], snapshot.RestoreConfig{ + if err := sp.Restore(snapshot.RestoreConfig{ + SnapshotPath: args[0], Name: restoreName, OutputDataDir: dataDir, OutputWALDir: walDir, - InitialCluster: urlmap, + PeerURLs: strings.Split(restorePeerURLs, ","), + InitialCluster: restoreCluster, InitialClusterToken: restoreClusterToken, - PeerURLs: types.MustNewURLs(strings.Split(restorePeerURLs, ",")), SkipHashCheck: skipHashCheck, }); err != nil { ExitWithError(ExitError, err)