Don't use server and token values from config file for etcd-snapshot commands

Fixes an issue where running etcd-snapshot commands on a node that has a server address set in the config will manage snapshots on that server, instead of on the local node as intended.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/10542/head
Brad Davidson 2024-07-14 00:14:43 +00:00 committed by Brad Davidson
parent bb9991612e
commit 869e19106c
2 changed files with 8 additions and 5 deletions

View File

@ -21,11 +21,14 @@ var EtcdSnapshotFlags = []cli.Flag{
Destination: &AgentConfig.NodeName, Destination: &AgentConfig.NodeName,
}, },
DataDirFlag, DataDirFlag,
ServerToken,
&cli.StringFlag{ &cli.StringFlag{
Name: "server, s", Name: "etcd-token,t",
Usage: "(cluster) Server to connect to", Usage: "(cluster) Shared secret used to authenticate to etcd server",
EnvVar: version.ProgramUpper + "_URL", Destination: &ServerConfig.Token,
},
&cli.StringFlag{
Name: "etcd-server, s",
Usage: "(cluster) Server with etcd role to connect to for snapshot management operations",
Value: "https://127.0.0.1:6443", Value: "https://127.0.0.1:6443",
Destination: &ServerConfig.ServerURL, Destination: &ServerConfig.ServerURL,
}, },

View File

@ -48,7 +48,7 @@ func Test_UnitMustParse(t *testing.T) {
name: "Etcd-snapshot with config with known and unknown flags", name: "Etcd-snapshot with config with known and unknown flags",
args: []string{"k3s", "etcd-snapshot", "save"}, args: []string{"k3s", "etcd-snapshot", "save"},
config: "./testdata/defaultdata.yaml", config: "./testdata/defaultdata.yaml",
want: []string{"k3s", "etcd-snapshot", "save", "--token=12345", "--etcd-s3=true", "--etcd-s3-bucket=my-backup"}, want: []string{"k3s", "etcd-snapshot", "save", "--etcd-s3=true", "--etcd-s3-bucket=my-backup"},
}, },
{ {
name: "Agent with known flags", name: "Agent with known flags",