Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
truenas-rk3588
k3s
Commits
40a46e14
Unverified
Commit
40a46e14
authored
3 years ago
by
Brian Downs
Committed by
GitHub
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
add ability to specify etcd snapshot list output format (#5132)
parent
142eed1a
base
backup-26-10-22
master
rel-v0.0.1
release-test/22.02.3
release/22.02.1
release/22.02.2
release/22.02.3
release/22.02.4
release/22.12
release/22.12-BETA.1
release/22.12-BETA.2
release/22.12-RC.1
release/22.12.1
release/22.12.2
release/22.12.3
release/22.12.4
release/23.10-BETA.1
release/23.10-RC.1
release/23.10.0
release/23.10.1
release/23.10.1.2
release/23.10.1.3
release/23.10.2
release/24.04-BETA.1
release/24.04-RC.1
release/24.04.0
remove-traefik-k3s
stable/angelfish
stable/bluefin
stable/cobia
stable/dragonfish
testing-refine-branchout-process
testing-refine-branchout-process2
truenas/master
truenas/master-backup-12-2-24
truenas/master-backup-14-10-22
truenas/master-backup-17-2-24
truenas/master-backup-2-7-23
truenas/master-backup-21-08-22
truenas/master-backup-25-10-22
truenas/master-fake-update
update-1.27
update-1.28
update-1.29
update-k3s-to-1.25
TS-24.04-RC.1
TS-24.04-BETA.1
TS-23.10.2
TS-23.10.1.3
TS-23.10.1.2
TS-23.10.1.1
TS-23.10.1
TS-23.10.0.1
TS-23.10.0
TS-23.10-RC.1
TS-23.10-BETA.1
TS-22.12.4.2
TS-22.12.4.1
TS-22.12.4
TS-22.12.3.3
TS-22.12.3.2
TS-22.12.3.1
TS-22.12.3
TS-22.12.2
TS-22.12.1
TS-22.12.0
TS-22.12-RC.1
TS-22.12-BETA.2
TS-22.12-BETA.1
TS-22.12-ALPHA.1
TS-22.02.4
TS-22.02.3
TS-22.02.2.1
TS-22.02.2
TS-22.02.1
TS-12.12.3
DN110M-CS-v2.0
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
pkg/cli/cmds/etcd_snapshot.go
+5
-1
pkg/cli/cmds/etcd_snapshot.go
pkg/cli/cmds/server.go
+1
-0
pkg/cli/cmds/server.go
pkg/cli/etcdsnapshot/etcd_snapshot.go
+45
-13
pkg/cli/etcdsnapshot/etcd_snapshot.go
pkg/daemons/config/types.go
+1
-0
pkg/daemons/config/types.go
with
52 additions
and
14 deletions
+52
-14
pkg/cli/cmds/etcd_snapshot.go
View file @
40a46e14
...
...
@@ -128,7 +128,11 @@ func NewEtcdSnapshotSubcommands(delete, list, prune, save func(ctx *cli.Context)
SkipFlagParsing
:
false
,
SkipArgReorder
:
true
,
Action
:
list
,
Flags
:
EtcdSnapshotFlags
,
Flags
:
append
(
EtcdSnapshotFlags
,
&
cli
.
StringFlag
{
Name
:
"o,output"
,
Usage
:
"(db) List format. Default: standard. Optional: json"
,
Destination
:
&
ServerConfig
.
EtcdListFormat
,
}),
},
{
Name
:
"prune"
,
...
...
This diff is collapsed.
Click to expand it.
pkg/cli/cmds/server.go
View file @
40a46e14
...
...
@@ -86,6 +86,7 @@ type Server struct {
EtcdSnapshotCron
string
EtcdSnapshotRetention
int
EtcdSnapshotCompress
bool
EtcdListFormat
string
EtcdS3
bool
EtcdS3Endpoint
string
EtcdS3EndpointCA
string
...
...
This diff is collapsed.
Click to expand it.
pkg/cli/etcdsnapshot/etcd_snapshot.go
View file @
40a46e14
package
etcdsnapshot
import
(
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"text/tabwriter"
"time"
...
...
@@ -17,6 +19,7 @@ import (
util2
"github.com/rancher/k3s/pkg/util"
"github.com/rancher/wrangler/pkg/signals"
"github.com/urfave/cli"
"gopkg.in/yaml.v2"
)
// commandSetup setups up common things needed
...
...
@@ -40,6 +43,7 @@ func commandSetup(app *cli.Context, cfg *cmds.Server, sc *server.Config) (string
sc
.
ControlConfig
.
EtcdSnapshotName
=
cfg
.
EtcdSnapshotName
sc
.
ControlConfig
.
EtcdSnapshotDir
=
cfg
.
EtcdSnapshotDir
sc
.
ControlConfig
.
EtcdSnapshotCompress
=
cfg
.
EtcdSnapshotCompress
sc
.
ControlConfig
.
EtcdListFormat
=
strings
.
ToLower
(
cfg
.
EtcdListFormat
)
sc
.
ControlConfig
.
EtcdS3
=
cfg
.
EtcdS3
sc
.
ControlConfig
.
EtcdS3Endpoint
=
cfg
.
EtcdS3Endpoint
sc
.
ControlConfig
.
EtcdS3EndpointCA
=
cfg
.
EtcdS3EndpointCA
...
...
@@ -152,6 +156,17 @@ func List(app *cli.Context) error {
return
list
(
app
,
&
cmds
.
ServerConfig
)
}
var
etcdListFormats
=
[]
string
{
"json"
,
"yaml"
}
func
validEtcdListFormat
(
format
string
)
bool
{
for
_
,
supportedFormat
:=
range
etcdListFormats
{
if
format
==
supportedFormat
{
return
true
}
}
return
false
}
func
list
(
app
*
cli
.
Context
,
cfg
*
cmds
.
Server
)
error
{
var
serverConfig
server
.
Config
...
...
@@ -171,21 +186,38 @@ func list(app *cli.Context, cfg *cmds.Server) error {
return
err
}
w
:=
tabwriter
.
NewWriter
(
os
.
Stdout
,
0
,
0
,
1
,
' '
,
0
)
defer
w
.
Flush
()
if
cfg
.
EtcdListFormat
!=
""
&&
!
validEtcdListFormat
(
cfg
.
EtcdListFormat
)
{
return
errors
.
New
(
"invalid output format: "
+
cfg
.
EtcdListFormat
)
}
if
cfg
.
EtcdS3
{
fmt
.
Fprint
(
w
,
"Name
\t
Size
\t
Created
\n
"
)
for
_
,
s
:=
range
sf
{
if
s
.
NodeName
==
"s3"
{
fmt
.
Fprintf
(
w
,
"%s
\t
%d
\t
%s
\n
"
,
s
.
Name
,
s
.
Size
,
s
.
CreatedAt
.
Format
(
time
.
RFC3339
))
}
switch
cfg
.
EtcdListFormat
{
case
"json"
:
if
err
:=
json
.
NewEncoder
(
os
.
Stdout
)
.
Encode
(
sf
);
err
!=
nil
{
return
err
}
}
else
{
fmt
.
Fprint
(
w
,
"Name
\t
Location
\t
Size
\t
Created
\n
"
)
for
_
,
s
:=
range
sf
{
if
s
.
NodeName
!=
"s3"
{
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%d
\t
%s
\n
"
,
s
.
Name
,
s
.
Location
,
s
.
Size
,
s
.
CreatedAt
.
Format
(
time
.
RFC3339
))
return
nil
case
"yaml"
:
if
err
:=
yaml
.
NewEncoder
(
os
.
Stdout
)
.
Encode
(
sf
);
err
!=
nil
{
return
err
}
return
nil
default
:
w
:=
tabwriter
.
NewWriter
(
os
.
Stdout
,
0
,
0
,
1
,
' '
,
0
)
defer
w
.
Flush
()
if
cfg
.
EtcdS3
{
fmt
.
Fprint
(
w
,
"Name
\t
Size
\t
Created
\n
"
)
for
_
,
s
:=
range
sf
{
if
s
.
NodeName
==
"s3"
{
fmt
.
Fprintf
(
w
,
"%s
\t
%d
\t
%s
\n
"
,
s
.
Name
,
s
.
Size
,
s
.
CreatedAt
.
Format
(
time
.
RFC3339
))
}
}
}
else
{
fmt
.
Fprint
(
w
,
"Name
\t
Location
\t
Size
\t
Created
\n
"
)
for
_
,
s
:=
range
sf
{
if
s
.
NodeName
!=
"s3"
{
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%d
\t
%s
\n
"
,
s
.
Name
,
s
.
Location
,
s
.
Size
,
s
.
CreatedAt
.
Format
(
time
.
RFC3339
))
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
pkg/daemons/config/types.go
View file @
40a46e14
...
...
@@ -173,6 +173,7 @@ type Control struct {
EtcdSnapshotCron
string
EtcdSnapshotRetention
int
EtcdSnapshotCompress
bool
EtcdListFormat
string
EtcdS3
bool
EtcdS3Endpoint
string
EtcdS3EndpointCA
string
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help