From e8ecc00fc8f8c7ff13d97924f3782660a78fdf54 Mon Sep 17 00:00:00 2001 From: Brian Downs Date: Mon, 17 May 2021 10:55:13 -0700 Subject: [PATCH] add etcd snapshot save subcommand Signed-off-by: Brian Downs --- cmd/etcdsnapshot/main.go | 3 ++- cmd/k3s/main.go | 1 + cmd/server/main.go | 3 ++- main.go | 3 ++- pkg/cli/cmds/etcd_snapshot.go | 14 +++++++++++++- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cmd/etcdsnapshot/main.go b/cmd/etcdsnapshot/main.go index 38c0ed47d8..3d55ab6181 100644 --- a/cmd/etcdsnapshot/main.go +++ b/cmd/etcdsnapshot/main.go @@ -17,7 +17,8 @@ func main() { cmds.NewEtcdSnapshotSubcommands( etcdsnapshot.Delete, etcdsnapshot.List, - etcdsnapshot.Prune), + etcdsnapshot.Prune, + etcdsnapshot.Run), ), } diff --git a/cmd/k3s/main.go b/cmd/k3s/main.go index bbf13850c1..036cea3da9 100644 --- a/cmd/k3s/main.go +++ b/cmd/k3s/main.go @@ -46,6 +46,7 @@ func main() { cmds.NewCheckConfigCommand(externalCLIAction("check-config", dataDir)), cmds.NewEtcdSnapshotCommand(etcdsnapshotCommand, cmds.NewEtcdSnapshotSubcommands( + etcdsnapshotCommand, etcdsnapshotCommand, etcdsnapshotCommand, etcdsnapshotCommand), diff --git a/cmd/server/main.go b/cmd/server/main.go index 17fc818838..bd01b22be2 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -47,7 +47,8 @@ func main() { cmds.NewEtcdSnapshotSubcommands( etcdsnapshot.Delete, etcdsnapshot.List, - etcdsnapshot.Prune), + etcdsnapshot.Prune, + etcdsnapshot.Run), ), } diff --git a/main.go b/main.go index a1c09d7fed..8f9de71b21 100644 --- a/main.go +++ b/main.go @@ -31,7 +31,8 @@ func main() { cmds.NewEtcdSnapshotSubcommands( etcdsnapshot.Delete, etcdsnapshot.List, - etcdsnapshot.Prune), + etcdsnapshot.Prune, + etcdsnapshot.Run), ), } diff --git a/pkg/cli/cmds/etcd_snapshot.go b/pkg/cli/cmds/etcd_snapshot.go index b76a3b3ba1..df0387d011 100644 --- a/pkg/cli/cmds/etcd_snapshot.go +++ b/pkg/cli/cmds/etcd_snapshot.go @@ -95,7 +95,7 @@ func NewEtcdSnapshotCommand(action func(*cli.Context) error, subcommands []cli.C } } -func NewEtcdSnapshotSubcommands(delete, list, prune func(ctx *cli.Context) error) []cli.Command { +func NewEtcdSnapshotSubcommands(delete, list, prune, save func(ctx *cli.Context) error) []cli.Command { return []cli.Command{ { Name: "delete", @@ -127,5 +127,17 @@ func NewEtcdSnapshotSubcommands(delete, list, prune func(ctx *cli.Context) error Value: defaultSnapshotRentention, }), }, + { + Name: "save", + Usage: "Trigger an immediate etcd snapshot", + SkipFlagParsing: false, + SkipArgReorder: true, + Action: save, + Flags: append(EtcdSnapshotFlags, &cli.StringFlag{ + Name: "dir", + Usage: "(db) Directory to save etcd on-demand snapshot. (default: ${data-dir}/db/snapshots)", + Destination: &ServerConfig.EtcdSnapshotDir, + }), + }, } }