Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
40a46e14
Unverified
Commit
40a46e14
authored
Feb 25, 2022
by
Brian Downs
Committed by
GitHub
Feb 25, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ability to specify etcd snapshot list output format (#5132)
parent
142eed1a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
14 deletions
+52
-14
etcd_snapshot.go
pkg/cli/cmds/etcd_snapshot.go
+5
-1
server.go
pkg/cli/cmds/server.go
+1
-0
etcd_snapshot.go
pkg/cli/etcdsnapshot/etcd_snapshot.go
+45
-13
types.go
pkg/daemons/config/types.go
+1
-0
No files found.
pkg/cli/cmds/etcd_snapshot.go
View file @
40a46e14
...
@@ -128,7 +128,11 @@ func NewEtcdSnapshotSubcommands(delete, list, prune, save func(ctx *cli.Context)
...
@@ -128,7 +128,11 @@ func NewEtcdSnapshotSubcommands(delete, list, prune, save func(ctx *cli.Context)
SkipFlagParsing
:
false
,
SkipFlagParsing
:
false
,
SkipArgReorder
:
true
,
SkipArgReorder
:
true
,
Action
:
list
,
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"
,
Name
:
"prune"
,
...
...
pkg/cli/cmds/server.go
View file @
40a46e14
...
@@ -86,6 +86,7 @@ type Server struct {
...
@@ -86,6 +86,7 @@ type Server struct {
EtcdSnapshotCron
string
EtcdSnapshotCron
string
EtcdSnapshotRetention
int
EtcdSnapshotRetention
int
EtcdSnapshotCompress
bool
EtcdSnapshotCompress
bool
EtcdListFormat
string
EtcdS3
bool
EtcdS3
bool
EtcdS3Endpoint
string
EtcdS3Endpoint
string
EtcdS3EndpointCA
string
EtcdS3EndpointCA
string
...
...
pkg/cli/etcdsnapshot/etcd_snapshot.go
View file @
40a46e14
package
etcdsnapshot
package
etcdsnapshot
import
(
import
(
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"os"
"os"
"path/filepath"
"path/filepath"
"strings"
"text/tabwriter"
"text/tabwriter"
"time"
"time"
...
@@ -17,6 +19,7 @@ import (
...
@@ -17,6 +19,7 @@ import (
util2
"github.com/rancher/k3s/pkg/util"
util2
"github.com/rancher/k3s/pkg/util"
"github.com/rancher/wrangler/pkg/signals"
"github.com/rancher/wrangler/pkg/signals"
"github.com/urfave/cli"
"github.com/urfave/cli"
"gopkg.in/yaml.v2"
)
)
// commandSetup setups up common things needed
// commandSetup setups up common things needed
...
@@ -40,6 +43,7 @@ func commandSetup(app *cli.Context, cfg *cmds.Server, sc *server.Config) (string
...
@@ -40,6 +43,7 @@ func commandSetup(app *cli.Context, cfg *cmds.Server, sc *server.Config) (string
sc
.
ControlConfig
.
EtcdSnapshotName
=
cfg
.
EtcdSnapshotName
sc
.
ControlConfig
.
EtcdSnapshotName
=
cfg
.
EtcdSnapshotName
sc
.
ControlConfig
.
EtcdSnapshotDir
=
cfg
.
EtcdSnapshotDir
sc
.
ControlConfig
.
EtcdSnapshotDir
=
cfg
.
EtcdSnapshotDir
sc
.
ControlConfig
.
EtcdSnapshotCompress
=
cfg
.
EtcdSnapshotCompress
sc
.
ControlConfig
.
EtcdSnapshotCompress
=
cfg
.
EtcdSnapshotCompress
sc
.
ControlConfig
.
EtcdListFormat
=
strings
.
ToLower
(
cfg
.
EtcdListFormat
)
sc
.
ControlConfig
.
EtcdS3
=
cfg
.
EtcdS3
sc
.
ControlConfig
.
EtcdS3
=
cfg
.
EtcdS3
sc
.
ControlConfig
.
EtcdS3Endpoint
=
cfg
.
EtcdS3Endpoint
sc
.
ControlConfig
.
EtcdS3Endpoint
=
cfg
.
EtcdS3Endpoint
sc
.
ControlConfig
.
EtcdS3EndpointCA
=
cfg
.
EtcdS3EndpointCA
sc
.
ControlConfig
.
EtcdS3EndpointCA
=
cfg
.
EtcdS3EndpointCA
...
@@ -152,6 +156,17 @@ func List(app *cli.Context) error {
...
@@ -152,6 +156,17 @@ func List(app *cli.Context) error {
return
list
(
app
,
&
cmds
.
ServerConfig
)
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
{
func
list
(
app
*
cli
.
Context
,
cfg
*
cmds
.
Server
)
error
{
var
serverConfig
server
.
Config
var
serverConfig
server
.
Config
...
@@ -171,21 +186,38 @@ func list(app *cli.Context, cfg *cmds.Server) error {
...
@@ -171,21 +186,38 @@ func list(app *cli.Context, cfg *cmds.Server) error {
return
err
return
err
}
}
w
:=
tabwriter
.
NewWriter
(
os
.
Stdout
,
0
,
0
,
1
,
' '
,
0
)
if
cfg
.
EtcdListFormat
!=
""
&&
!
validEtcdListFormat
(
cfg
.
EtcdListFormat
)
{
defer
w
.
Flush
()
return
errors
.
New
(
"invalid output format: "
+
cfg
.
EtcdListFormat
)
}
if
cfg
.
EtcdS3
{
switch
cfg
.
EtcdListFormat
{
fmt
.
Fprint
(
w
,
"Name
\t
Size
\t
Created
\n
"
)
case
"json"
:
for
_
,
s
:=
range
sf
{
if
err
:=
json
.
NewEncoder
(
os
.
Stdout
)
.
Encode
(
sf
);
err
!=
nil
{
if
s
.
NodeName
==
"s3"
{
return
err
fmt
.
Fprintf
(
w
,
"%s
\t
%d
\t
%s
\n
"
,
s
.
Name
,
s
.
Size
,
s
.
CreatedAt
.
Format
(
time
.
RFC3339
))
}
}
}
}
else
{
return
nil
fmt
.
Fprint
(
w
,
"Name
\t
Location
\t
Size
\t
Created
\n
"
)
case
"yaml"
:
for
_
,
s
:=
range
sf
{
if
err
:=
yaml
.
NewEncoder
(
os
.
Stdout
)
.
Encode
(
sf
);
err
!=
nil
{
if
s
.
NodeName
!=
"s3"
{
return
err
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%d
\t
%s
\n
"
,
s
.
Name
,
s
.
Location
,
s
.
Size
,
s
.
CreatedAt
.
Format
(
time
.
RFC3339
))
}
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
))
}
}
}
}
}
}
}
...
...
pkg/daemons/config/types.go
View file @
40a46e14
...
@@ -173,6 +173,7 @@ type Control struct {
...
@@ -173,6 +173,7 @@ type Control struct {
EtcdSnapshotCron
string
EtcdSnapshotCron
string
EtcdSnapshotRetention
int
EtcdSnapshotRetention
int
EtcdSnapshotCompress
bool
EtcdSnapshotCompress
bool
EtcdListFormat
string
EtcdS3
bool
EtcdS3
bool
EtcdS3Endpoint
string
EtcdS3Endpoint
string
EtcdS3EndpointCA
string
EtcdS3EndpointCA
string
...
...
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