Deprecation of `etcd-snapshot` command in v1.26 (#6575)

* Consolidate etcd snapshot commands
* Consolidate secrets encryption commands
* Move etcd-snapshot to fatal error stage.

Signed-off-by: Derek Nola <derek.nola@suse.com>
pull/6614/head
Derek Nola 2 years ago committed by GitHub
parent d723775792
commit b5d39df929
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,14 +15,13 @@ import (
func main() { func main() {
app := cmds.NewApp() app := cmds.NewApp()
app.Commands = []cli.Command{ app.Commands = []cli.Command{
cmds.NewSecretsEncryptCommand(cli.ShowAppHelp, cmds.NewSecretsEncryptCommands(
cmds.NewSecretsEncryptSubcommands( secretsencrypt.Status,
secretsencrypt.Status, secretsencrypt.Enable,
secretsencrypt.Enable, secretsencrypt.Disable,
secretsencrypt.Disable, secretsencrypt.Prepare,
secretsencrypt.Prepare, secretsencrypt.Rotate,
secretsencrypt.Rotate, secretsencrypt.Reencrypt,
secretsencrypt.Reencrypt),
), ),
} }

@ -15,12 +15,12 @@ import (
func main() { func main() {
app := cmds.NewApp() app := cmds.NewApp()
app.Commands = []cli.Command{ app.Commands = []cli.Command{
cmds.NewEtcdSnapshotCommand(etcdsnapshot.Save, cmds.NewEtcdSnapshotCommands(
cmds.NewEtcdSnapshotSubcommands( etcdsnapshot.Run,
etcdsnapshot.Delete, etcdsnapshot.Delete,
etcdsnapshot.List, etcdsnapshot.List,
etcdsnapshot.Prune, etcdsnapshot.Prune,
etcdsnapshot.Save), etcdsnapshot.Save,
), ),
} }

@ -51,21 +51,20 @@ func main() {
cmds.NewCRICTL(externalCLIAction("crictl", dataDir)), cmds.NewCRICTL(externalCLIAction("crictl", dataDir)),
cmds.NewCtrCommand(externalCLIAction("ctr", dataDir)), cmds.NewCtrCommand(externalCLIAction("ctr", dataDir)),
cmds.NewCheckConfigCommand(externalCLIAction("check-config", dataDir)), cmds.NewCheckConfigCommand(externalCLIAction("check-config", dataDir)),
cmds.NewEtcdSnapshotCommand(etcdsnapshotCommand, cmds.NewEtcdSnapshotCommands(
cmds.NewEtcdSnapshotSubcommands( etcdsnapshotCommand,
etcdsnapshotCommand, etcdsnapshotCommand,
etcdsnapshotCommand, etcdsnapshotCommand,
etcdsnapshotCommand, etcdsnapshotCommand,
etcdsnapshotCommand), etcdsnapshotCommand,
), ),
cmds.NewSecretsEncryptCommand(secretsencryptCommand, cmds.NewSecretsEncryptCommands(
cmds.NewSecretsEncryptSubcommands( secretsencryptCommand,
secretsencryptCommand, secretsencryptCommand,
secretsencryptCommand, secretsencryptCommand,
secretsencryptCommand, secretsencryptCommand,
secretsencryptCommand, secretsencryptCommand,
secretsencryptCommand, secretsencryptCommand,
secretsencryptCommand),
), ),
cmds.NewCertCommand( cmds.NewCertCommand(
cmds.NewCertSubcommands( cmds.NewCertSubcommands(

@ -48,21 +48,20 @@ func main() {
cmds.NewKubectlCommand(kubectl.Run), cmds.NewKubectlCommand(kubectl.Run),
cmds.NewCRICTL(crictl.Run), cmds.NewCRICTL(crictl.Run),
cmds.NewCtrCommand(ctr.Run), cmds.NewCtrCommand(ctr.Run),
cmds.NewEtcdSnapshotCommand(etcdsnapshot.Save, cmds.NewEtcdSnapshotCommands(
cmds.NewEtcdSnapshotSubcommands( etcdsnapshot.Run,
etcdsnapshot.Delete, etcdsnapshot.Delete,
etcdsnapshot.List, etcdsnapshot.List,
etcdsnapshot.Prune, etcdsnapshot.Prune,
etcdsnapshot.Save), etcdsnapshot.Save,
), ),
cmds.NewSecretsEncryptCommand(cli.ShowAppHelp, cmds.NewSecretsEncryptCommands(
cmds.NewSecretsEncryptSubcommands( secretsencrypt.Status,
secretsencrypt.Status, secretsencrypt.Enable,
secretsencrypt.Enable, secretsencrypt.Disable,
secretsencrypt.Disable, secretsencrypt.Prepare,
secretsencrypt.Prepare, secretsencrypt.Rotate,
secretsencrypt.Rotate, secretsencrypt.Reencrypt,
secretsencrypt.Reencrypt),
), ),
cmds.NewCertCommand( cmds.NewCertCommand(
cmds.NewCertSubcommands( cmds.NewCertSubcommands(

@ -32,21 +32,20 @@ func main() {
cmds.NewAgentCommand(agent.Run), cmds.NewAgentCommand(agent.Run),
cmds.NewKubectlCommand(kubectl.Run), cmds.NewKubectlCommand(kubectl.Run),
cmds.NewCRICTL(crictl.Run), cmds.NewCRICTL(crictl.Run),
cmds.NewEtcdSnapshotCommand(etcdsnapshot.Save, cmds.NewEtcdSnapshotCommands(
cmds.NewEtcdSnapshotSubcommands( etcdsnapshot.Run,
etcdsnapshot.Delete, etcdsnapshot.Delete,
etcdsnapshot.List, etcdsnapshot.List,
etcdsnapshot.Prune, etcdsnapshot.Prune,
etcdsnapshot.Save), etcdsnapshot.Save,
), ),
cmds.NewSecretsEncryptCommand(cli.ShowAppHelp, cmds.NewSecretsEncryptCommands(
cmds.NewSecretsEncryptSubcommands( secretsencrypt.Status,
secretsencrypt.Status, secretsencrypt.Enable,
secretsencrypt.Enable, secretsencrypt.Disable,
secretsencrypt.Disable, secretsencrypt.Prepare,
secretsencrypt.Prepare, secretsencrypt.Rotate,
secretsencrypt.Rotate, secretsencrypt.Reencrypt,
secretsencrypt.Reencrypt),
), ),
cmds.NewCertCommand( cmds.NewCertCommand(
cmds.NewCertSubcommands( cmds.NewCertSubcommands(

@ -99,61 +99,57 @@ var EtcdSnapshotFlags = []cli.Flag{
}, },
} }
func NewEtcdSnapshotCommand(action func(*cli.Context) error, subcommands []cli.Command) cli.Command { func NewEtcdSnapshotCommands(run, delete, list, prune, save func(ctx *cli.Context) error) cli.Command {
return cli.Command{ return cli.Command{
Name: EtcdSnapshotCommand, Name: EtcdSnapshotCommand,
Usage: "Trigger an immediate etcd snapshot", Usage: "Trigger an immediate etcd snapshot",
SkipFlagParsing: false, SkipFlagParsing: false,
SkipArgReorder: true, SkipArgReorder: true,
Action: action, Action: run,
Subcommands: subcommands, Subcommands: []cli.Command{
Flags: EtcdSnapshotFlags, {
} Name: "delete",
} Usage: "Delete given snapshot(s)",
SkipFlagParsing: false,
func NewEtcdSnapshotSubcommands(delete, list, prune, save func(ctx *cli.Context) error) []cli.Command { SkipArgReorder: true,
return []cli.Command{ Action: delete,
{ Flags: EtcdSnapshotFlags,
Name: "delete", },
Usage: "Delete given snapshot(s)", {
SkipFlagParsing: false, Name: "ls",
SkipArgReorder: true, Aliases: []string{"list", "l"},
Action: delete, Usage: "List snapshots",
Flags: EtcdSnapshotFlags, SkipFlagParsing: false,
}, SkipArgReorder: true,
{ Action: list,
Name: "ls", Flags: append(EtcdSnapshotFlags, &cli.StringFlag{
Aliases: []string{"list", "l"}, Name: "o,output",
Usage: "List snapshots", Usage: "(db) List format. Default: standard. Optional: json",
SkipFlagParsing: false, Destination: &ServerConfig.EtcdListFormat,
SkipArgReorder: true, }),
Action: list, },
Flags: append(EtcdSnapshotFlags, &cli.StringFlag{ {
Name: "o,output", Name: "prune",
Usage: "(db) List format. Default: standard. Optional: json", Usage: "Remove snapshots that match the name prefix that exceed the configured retention count",
Destination: &ServerConfig.EtcdListFormat, SkipFlagParsing: false,
}), SkipArgReorder: true,
}, Action: prune,
{ Flags: append(EtcdSnapshotFlags, &cli.IntFlag{
Name: "prune", Name: "snapshot-retention",
Usage: "Remove snapshots that match the name prefix that exceed the configured retention count", Usage: "(db) Number of snapshots to retain.",
SkipFlagParsing: false, Destination: &ServerConfig.EtcdSnapshotRetention,
SkipArgReorder: true, Value: defaultSnapshotRentention,
Action: prune, }),
Flags: append(EtcdSnapshotFlags, &cli.IntFlag{ },
Name: "snapshot-retention", {
Usage: "(db) Number of snapshots to retain.", Name: "save",
Destination: &ServerConfig.EtcdSnapshotRetention, Usage: "Trigger an immediate etcd snapshot",
Value: defaultSnapshotRentention, SkipFlagParsing: false,
}), SkipArgReorder: true,
}, Action: save,
{ Flags: EtcdSnapshotFlags,
Name: "save", },
Usage: "Trigger an immediate etcd snapshot",
SkipFlagParsing: false,
SkipArgReorder: true,
Action: save,
Flags: EtcdSnapshotFlags,
}, },
Flags: EtcdSnapshotFlags,
} }
} }

@ -7,100 +7,83 @@ import (
const SecretsEncryptCommand = "secrets-encrypt" const SecretsEncryptCommand = "secrets-encrypt"
var EncryptFlags = []cli.Flag{ var (
DataDirFlag, forceFlag = cli.BoolFlag{
ServerToken, Name: "f,force",
cli.StringFlag{ Usage: "Force this stage.",
Name: "server, s", Destination: &ServerConfig.EncryptForce,
Usage: "(cluster) Server to connect to",
EnvVar: version.ProgramUpper + "_URL",
Value: "https://127.0.0.1:6443",
Destination: &ServerConfig.ServerURL,
},
}
func NewSecretsEncryptCommand(action func(*cli.Context) error, subcommands []cli.Command) cli.Command {
return cli.Command{
Name: SecretsEncryptCommand,
Usage: "Control secrets encryption and keys rotation",
SkipFlagParsing: false,
SkipArgReorder: true,
Action: action,
Subcommands: subcommands,
} }
} EncryptFlags = []cli.Flag{
DataDirFlag,
func NewSecretsEncryptSubcommands(status, enable, disable, prepare, rotate, reencrypt func(ctx *cli.Context) error) []cli.Command { ServerToken,
return []cli.Command{ cli.StringFlag{
{ Name: "server, s",
Name: "status", Usage: "(cluster) Server to connect to",
Usage: "Print current status of secrets encryption", EnvVar: version.ProgramUpper + "_URL",
SkipFlagParsing: false, Value: "https://127.0.0.1:6443",
SkipArgReorder: true, Destination: &ServerConfig.ServerURL,
Action: status,
Flags: append(EncryptFlags, &cli.StringFlag{
Name: "output,o",
Usage: "Status format. Default: text. Optional: json",
Destination: &ServerConfig.EncryptOutput,
}),
},
{
Name: "enable",
Usage: "Enable secrets encryption",
SkipFlagParsing: false,
SkipArgReorder: true,
Action: enable,
Flags: EncryptFlags,
},
{
Name: "disable",
Usage: "Disable secrets encryption",
SkipFlagParsing: false,
SkipArgReorder: true,
Action: disable,
Flags: EncryptFlags,
}, },
{ }
Name: "prepare", )
Usage: "Prepare for encryption keys rotation",
SkipFlagParsing: false, func NewSecretsEncryptCommands(status, enable, disable, prepare, rotate, reencrypt func(ctx *cli.Context) error) cli.Command {
SkipArgReorder: true, return cli.Command{
Action: prepare, Name: SecretsEncryptCommand,
Flags: append(EncryptFlags, &cli.BoolFlag{ Usage: "Control secrets encryption and keys rotation",
Name: "f,force", SkipArgReorder: true,
Usage: "Force preparation.", Subcommands: []cli.Command{
Destination: &ServerConfig.EncryptForce, {
}), Name: "status",
}, Usage: "Print current status of secrets encryption",
{ SkipArgReorder: true,
Name: "rotate", Action: status,
Usage: "Rotate secrets encryption keys", Flags: append(EncryptFlags, &cli.StringFlag{
SkipFlagParsing: false, Name: "output,o",
SkipArgReorder: true, Usage: "Status format. Default: text. Optional: json",
Action: rotate, Destination: &ServerConfig.EncryptOutput,
Flags: append(EncryptFlags, &cli.BoolFlag{
Name: "f,force",
Usage: "Force key rotation.",
Destination: &ServerConfig.EncryptForce,
}),
},
{
Name: "reencrypt",
Usage: "Reencrypt all data with new encryption key",
SkipFlagParsing: false,
SkipArgReorder: true,
Action: reencrypt,
Flags: append(EncryptFlags,
&cli.BoolFlag{
Name: "f,force",
Usage: "Force secrets reencryption.",
Destination: &ServerConfig.EncryptForce,
},
&cli.BoolFlag{
Name: "skip",
Usage: "Skip removing old key",
Destination: &ServerConfig.EncryptSkip,
}), }),
},
{
Name: "enable",
Usage: "Enable secrets encryption",
SkipArgReorder: true,
Action: enable,
Flags: EncryptFlags,
},
{
Name: "disable",
Usage: "Disable secrets encryption",
SkipArgReorder: true,
Action: disable,
Flags: EncryptFlags,
},
{
Name: "prepare",
Usage: "Prepare for encryption keys rotation",
SkipArgReorder: true,
Action: prepare,
Flags: append(EncryptFlags, &forceFlag),
},
{
Name: "rotate",
Usage: "Rotate secrets encryption keys",
SkipArgReorder: true,
Action: rotate,
Flags: append(EncryptFlags, &forceFlag),
},
{
Name: "reencrypt",
Usage: "Reencrypt all data with new encryption key",
SkipArgReorder: true,
Action: reencrypt,
Flags: append(EncryptFlags,
&forceFlag,
&cli.BoolFlag{
Name: "skip",
Usage: "Skip removing old key",
Destination: &ServerConfig.EncryptSkip,
}),
},
}, },
} }
} }

@ -69,9 +69,10 @@ func commandSetup(app *cli.Context, cfg *cmds.Server, sc *server.Config) error {
return nil return nil
} }
// Run is an alias for Save, retained for compatibility reasons. // Run was an alias for Save
func Run(app *cli.Context) error { func Run(app *cli.Context) error {
return Save(app) cli.ShowAppHelp(app)
return fmt.Errorf("saving with etcd-snapshot was deprecated in v1.26, use \"etcd-snapshot save\" instead")
} }
// Save triggers an on-demand etcd snapshot operation // Save triggers an on-demand etcd snapshot operation

@ -101,11 +101,12 @@ var _ = Describe("Verify Create", Ordered, func() {
It("Verifies Snapshot is created", func() { It("Verifies Snapshot is created", func() {
Eventually(func(g Gomega) { Eventually(func(g Gomega) {
cmd := "sudo k3s etcd-snapshot" cmd := "sudo k3s etcd-snapshot save"
_, err := e2e.RunCmdOnNode(cmd, "server-0") _, err := e2e.RunCmdOnNode(cmd, "server-0")
g.Expect(err).NotTo(HaveOccurred()) g.Expect(err).NotTo(HaveOccurred())
cmd = "sudo ls /var/lib/rancher/k3s/server/db/snapshots/" cmd = "sudo ls /var/lib/rancher/k3s/server/db/snapshots/"
snapshotname, err = e2e.RunCmdOnNode(cmd, "server-0") snapshotname, err = e2e.RunCmdOnNode(cmd, "server-0")
g.Expect(err).NotTo(HaveOccurred())
fmt.Println("Snapshot Name", snapshotname) fmt.Println("Snapshot Name", snapshotname)
g.Expect(snapshotname).Should(ContainSubstring("on-demand-server-0")) g.Expect(snapshotname).Should(ContainSubstring("on-demand-server-0"))
}, "420s", "10s").Should(Succeed()) }, "420s", "10s").Should(Succeed())

Loading…
Cancel
Save