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
6ee28214
Unverified
Commit
6ee28214
authored
May 13, 2021
by
Brian Downs
Committed by
GitHub
May 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the ability to prune etcd snapshots (#3310)
* add prune subcommand to force rentention policy enforcement
parent
079620de
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
75 additions
and
6 deletions
+75
-6
main.go
cmd/etcdsnapshot/main.go
+6
-1
main.go
cmd/k3s/main.go
+6
-1
main.go
cmd/server/main.go
+6
-1
main.go
main.go
+6
-1
etcd_snapshot.go
pkg/cli/cmds/etcd_snapshot.go
+15
-2
etcd_snapshot.go
pkg/cli/etcdsnapshot/etcd_snapshot.go
+25
-0
etcd.go
pkg/etcd/etcd.go
+11
-0
No files found.
cmd/etcdsnapshot/main.go
View file @
6ee28214
...
@@ -13,7 +13,12 @@ import (
...
@@ -13,7 +13,12 @@ import (
func
main
()
{
func
main
()
{
app
:=
cmds
.
NewApp
()
app
:=
cmds
.
NewApp
()
app
.
Commands
=
[]
cli
.
Command
{
app
.
Commands
=
[]
cli
.
Command
{
cmds
.
NewEtcdSnapshotCommand
(
etcdsnapshot
.
Run
,
cmds
.
NewEtcdSnapshotSubcommands
(
etcdsnapshot
.
Delete
,
etcdsnapshot
.
List
)),
cmds
.
NewEtcdSnapshotCommand
(
etcdsnapshot
.
Run
,
cmds
.
NewEtcdSnapshotSubcommands
(
etcdsnapshot
.
Delete
,
etcdsnapshot
.
List
,
etcdsnapshot
.
Prune
),
),
}
}
if
err
:=
app
.
Run
(
configfilearg
.
MustParse
(
os
.
Args
));
err
!=
nil
{
if
err
:=
app
.
Run
(
configfilearg
.
MustParse
(
os
.
Args
));
err
!=
nil
{
...
...
cmd/k3s/main.go
View file @
6ee28214
...
@@ -44,7 +44,12 @@ func main() {
...
@@ -44,7 +44,12 @@ 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
.
NewEtcdSnapshotSubcommands
(
etcdsnapshotCommand
,
etcdsnapshotCommand
)),
cmds
.
NewEtcdSnapshotCommand
(
etcdsnapshotCommand
,
cmds
.
NewEtcdSnapshotSubcommands
(
etcdsnapshotCommand
,
etcdsnapshotCommand
,
etcdsnapshotCommand
),
),
}
}
if
err
:=
app
.
Run
(
os
.
Args
);
err
!=
nil
{
if
err
:=
app
.
Run
(
os
.
Args
);
err
!=
nil
{
...
...
cmd/server/main.go
View file @
6ee28214
...
@@ -43,7 +43,12 @@ func main() {
...
@@ -43,7 +43,12 @@ 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
.
Run
,
cmds
.
NewEtcdSnapshotSubcommands
(
etcdsnapshot
.
Delete
,
etcdsnapshot
.
List
)),
cmds
.
NewEtcdSnapshotCommand
(
etcdsnapshot
.
Run
,
cmds
.
NewEtcdSnapshotSubcommands
(
etcdsnapshot
.
Delete
,
etcdsnapshot
.
List
,
etcdsnapshot
.
Prune
),
),
}
}
err
:=
app
.
Run
(
configfilearg
.
MustParse
(
os
.
Args
))
err
:=
app
.
Run
(
configfilearg
.
MustParse
(
os
.
Args
))
...
...
main.go
View file @
6ee28214
...
@@ -27,7 +27,12 @@ func main() {
...
@@ -27,7 +27,12 @@ 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
.
Run
,
cmds
.
NewEtcdSnapshotSubcommands
(
etcdsnapshot
.
Delete
,
etcdsnapshot
.
List
)),
cmds
.
NewEtcdSnapshotCommand
(
etcdsnapshot
.
Run
,
cmds
.
NewEtcdSnapshotSubcommands
(
etcdsnapshot
.
Delete
,
etcdsnapshot
.
List
,
etcdsnapshot
.
Prune
),
),
}
}
if
err
:=
app
.
Run
(
configfilearg
.
MustParse
(
os
.
Args
));
err
!=
nil
{
if
err
:=
app
.
Run
(
configfilearg
.
MustParse
(
os
.
Args
));
err
!=
nil
{
...
...
pkg/cli/cmds/etcd_snapshot.go
View file @
6ee28214
...
@@ -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
func
(
ctx
*
cli
.
Context
)
error
)
[]
cli
.
Command
{
func
NewEtcdSnapshotSubcommands
(
delete
,
list
,
prune
func
(
ctx
*
cli
.
Context
)
error
)
[]
cli
.
Command
{
return
[]
cli
.
Command
{
return
[]
cli
.
Command
{
{
{
Name
:
"delete"
,
Name
:
"delete"
,
...
@@ -108,11 +108,24 @@ func NewEtcdSnapshotSubcommands(delete, list func(ctx *cli.Context) error) []cli
...
@@ -108,11 +108,24 @@ func NewEtcdSnapshotSubcommands(delete, list func(ctx *cli.Context) error) []cli
{
{
Name
:
"ls"
,
Name
:
"ls"
,
Aliases
:
[]
string
{
"list"
,
"l"
},
Aliases
:
[]
string
{
"list"
,
"l"
},
Usage
:
"List
etcd
snapshots"
,
Usage
:
"List snapshots"
,
SkipFlagParsing
:
false
,
SkipFlagParsing
:
false
,
SkipArgReorder
:
true
,
SkipArgReorder
:
true
,
Action
:
list
,
Action
:
list
,
Flags
:
EtcdSnapshotFlags
,
Flags
:
EtcdSnapshotFlags
,
},
},
{
Name
:
"prune"
,
Usage
:
"Remove snapshots that exceed the configured retention count"
,
SkipFlagParsing
:
false
,
SkipArgReorder
:
true
,
Action
:
prune
,
Flags
:
append
(
EtcdSnapshotFlags
,
&
cli
.
IntFlag
{
Name
:
"snapshot-retention"
,
Usage
:
"(db) Number of snapshots to retain"
,
Destination
:
&
ServerConfig
.
EtcdSnapshotRetention
,
Value
:
defaultSnapshotRentention
,
}),
},
}
}
}
}
pkg/cli/etcdsnapshot/etcd_snapshot.go
View file @
6ee28214
...
@@ -181,3 +181,28 @@ func list(app *cli.Context, cfg *cmds.Server) error {
...
@@ -181,3 +181,28 @@ func list(app *cli.Context, cfg *cmds.Server) error {
return
nil
return
nil
}
}
func
Prune
(
app
*
cli
.
Context
)
error
{
if
err
:=
cmds
.
InitLogging
();
err
!=
nil
{
return
err
}
return
prune
(
app
,
&
cmds
.
ServerConfig
)
}
func
prune
(
app
*
cli
.
Context
,
cfg
*
cmds
.
Server
)
error
{
var
serverConfig
server
.
Config
dataDir
,
err
:=
commandSetup
(
app
,
cfg
,
&
serverConfig
)
if
err
!=
nil
{
return
err
}
serverConfig
.
ControlConfig
.
DataDir
=
dataDir
serverConfig
.
ControlConfig
.
EtcdSnapshotRetention
=
cfg
.
EtcdSnapshotRetention
ctx
:=
signals
.
SetupSignalHandler
(
context
.
Background
())
e
:=
etcd
.
NewETCD
()
e
.
SetControlConfig
(
&
serverConfig
.
ControlConfig
)
return
e
.
PruneSnapshots
(
ctx
)
}
pkg/etcd/etcd.go
View file @
6ee28214
...
@@ -970,6 +970,17 @@ func (e *ETCD) initS3IfNil(ctx context.Context) error {
...
@@ -970,6 +970,17 @@ func (e *ETCD) initS3IfNil(ctx context.Context) error {
return
nil
return
nil
}
}
// PruneSnapshots perfrorms a retention run with the given
// retention duration and removes expired snapshots.
func
(
e
*
ETCD
)
PruneSnapshots
(
ctx
context
.
Context
)
error
{
snapshotDir
,
err
:=
snapshotDir
(
e
.
config
)
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
}
return
snapshotRetention
(
e
.
config
.
EtcdSnapshotRetention
,
snapshotDir
)
}
// ListSnapshots is an exported wrapper method that wraps an
// ListSnapshots is an exported wrapper method that wraps an
// unexported method of the same name.
// unexported method of the same name.
func
(
e
*
ETCD
)
ListSnapshots
(
ctx
context
.
Context
)
([]
SnapshotFile
,
error
)
{
func
(
e
*
ETCD
)
ListSnapshots
(
ctx
context
.
Context
)
([]
SnapshotFile
,
error
)
{
...
...
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