Unverified Commit 3db7f988 authored by Brian Downs's avatar Brian Downs Committed by GitHub

Merge pull request #3354 from briandowns/backport_etcd_subcommands-1.21

[ Backport 1.21 ] - etcd subcommands 1.21
parents 16ae282c 8fd180e0
...@@ -17,7 +17,8 @@ func main() { ...@@ -17,7 +17,8 @@ func main() {
cmds.NewEtcdSnapshotSubcommands( cmds.NewEtcdSnapshotSubcommands(
etcdsnapshot.Delete, etcdsnapshot.Delete,
etcdsnapshot.List, etcdsnapshot.List,
etcdsnapshot.Prune), etcdsnapshot.Prune,
etcdsnapshot.Run),
), ),
} }
......
...@@ -48,6 +48,7 @@ func main() { ...@@ -48,6 +48,7 @@ func main() {
cmds.NewEtcdSnapshotSubcommands( cmds.NewEtcdSnapshotSubcommands(
etcdsnapshotCommand, etcdsnapshotCommand,
etcdsnapshotCommand, etcdsnapshotCommand,
etcdsnapshotCommand,
etcdsnapshotCommand), etcdsnapshotCommand),
), ),
} }
......
...@@ -47,7 +47,8 @@ func main() { ...@@ -47,7 +47,8 @@ func main() {
cmds.NewEtcdSnapshotSubcommands( cmds.NewEtcdSnapshotSubcommands(
etcdsnapshot.Delete, etcdsnapshot.Delete,
etcdsnapshot.List, etcdsnapshot.List,
etcdsnapshot.Prune), etcdsnapshot.Prune,
etcdsnapshot.Run),
), ),
} }
......
...@@ -31,7 +31,8 @@ func main() { ...@@ -31,7 +31,8 @@ func main() {
cmds.NewEtcdSnapshotSubcommands( cmds.NewEtcdSnapshotSubcommands(
etcdsnapshot.Delete, etcdsnapshot.Delete,
etcdsnapshot.List, etcdsnapshot.List,
etcdsnapshot.Prune), etcdsnapshot.Prune,
etcdsnapshot.Run),
), ),
} }
......
...@@ -95,7 +95,7 @@ func NewEtcdSnapshotCommand(action func(*cli.Context) error, subcommands []cli.C ...@@ -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{ return []cli.Command{
{ {
Name: "delete", Name: "delete",
...@@ -122,10 +122,22 @@ func NewEtcdSnapshotSubcommands(delete, list, prune func(ctx *cli.Context) error ...@@ -122,10 +122,22 @@ func NewEtcdSnapshotSubcommands(delete, list, prune func(ctx *cli.Context) error
Action: prune, Action: prune,
Flags: append(EtcdSnapshotFlags, &cli.IntFlag{ Flags: append(EtcdSnapshotFlags, &cli.IntFlag{
Name: "snapshot-retention", Name: "snapshot-retention",
Usage: "(db) Number of snapshots to retain", Usage: "(db) Number of snapshots to retain. Default: 5",
Destination: &ServerConfig.EtcdSnapshotRetention, Destination: &ServerConfig.EtcdSnapshotRetention,
Value: defaultSnapshotRentention, 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,
}),
},
} }
} }
...@@ -252,7 +252,7 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command { ...@@ -252,7 +252,7 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
}, },
&cli.IntFlag{ &cli.IntFlag{
Name: "etcd-snapshot-retention", Name: "etcd-snapshot-retention",
Usage: "(db) Number of snapshots to retain", Usage: "(db) Number of snapshots to retain Default: 5",
Destination: &ServerConfig.EtcdSnapshotRetention, Destination: &ServerConfig.EtcdSnapshotRetention,
Value: defaultSnapshotRentention, Value: defaultSnapshotRentention,
}, },
......
...@@ -978,6 +978,14 @@ func (e *ETCD) PruneSnapshots(ctx context.Context) error { ...@@ -978,6 +978,14 @@ func (e *ETCD) PruneSnapshots(ctx context.Context) error {
return errors.Wrap(err, "failed to get the snapshot dir") return errors.Wrap(err, "failed to get the snapshot dir")
} }
if e.config.EtcdS3 {
if e.initS3IfNil(ctx); err != nil {
return err
}
return e.s3.snapshotRetention(ctx)
}
return snapshotRetention(e.config.EtcdSnapshotRetention, snapshotDir) return snapshotRetention(e.config.EtcdSnapshotRetention, snapshotDir)
} }
...@@ -1009,12 +1017,13 @@ func (e *ETCD) DeleteSnapshots(ctx context.Context, snapshots []string) error { ...@@ -1009,12 +1017,13 @@ func (e *ETCD) DeleteSnapshots(ctx context.Context, snapshots []string) error {
} }
objectsCh := make(chan minio.ObjectInfo) objectsCh := make(chan minio.ObjectInfo)
defer close(objectsCh)
ctx, cancel := context.WithTimeout(ctx, defaultS3OpTimeout) ctx, cancel := context.WithTimeout(ctx, defaultS3OpTimeout)
defer cancel() defer cancel()
go func() { go func() {
defer close(objectsCh)
opts := minio.ListObjectsOptions{ opts := minio.ListObjectsOptions{
Recursive: true, Recursive: true,
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment