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
b4eca61a
Unverified
Commit
b4eca61a
authored
Aug 09, 2021
by
Derek Nola
Committed by
GitHub
Aug 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent snapshot commands from creating empty snapshot directory (#3783)
Signed-off-by:
dereknola
<
derek.nola@suse.com
>
parent
3b01157a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
etcd.go
pkg/etcd/etcd.go
+7
-7
s3.go
pkg/etcd/s3.go
+1
-1
No files found.
pkg/etcd/etcd.go
View file @
b4eca61a
...
@@ -761,14 +761,14 @@ members:
...
@@ -761,14 +761,14 @@ members:
}
}
// snapshotDir ensures that the snapshot directory exists, and then returns its path.
// snapshotDir ensures that the snapshot directory exists, and then returns its path.
func
snapshotDir
(
config
*
config
.
Control
)
(
string
,
error
)
{
func
snapshotDir
(
config
*
config
.
Control
,
create
bool
)
(
string
,
error
)
{
if
config
.
EtcdSnapshotDir
==
""
{
if
config
.
EtcdSnapshotDir
==
""
{
// we have to create the snapshot dir if we are using
// we have to create the snapshot dir if we are using
// the default snapshot dir if it doesn't exist
// the default snapshot dir if it doesn't exist
defaultSnapshotDir
:=
filepath
.
Join
(
config
.
DataDir
,
"db"
,
"snapshots"
)
defaultSnapshotDir
:=
filepath
.
Join
(
config
.
DataDir
,
"db"
,
"snapshots"
)
s
,
err
:=
os
.
Stat
(
defaultSnapshotDir
)
s
,
err
:=
os
.
Stat
(
defaultSnapshotDir
)
if
err
!=
nil
{
if
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
if
create
&&
os
.
IsNotExist
(
err
)
{
if
err
:=
os
.
MkdirAll
(
defaultSnapshotDir
,
0700
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
defaultSnapshotDir
,
0700
);
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
@@ -821,7 +821,7 @@ func (e *ETCD) Snapshot(ctx context.Context, config *config.Control) error {
...
@@ -821,7 +821,7 @@ func (e *ETCD) Snapshot(ctx context.Context, config *config.Control) error {
return
nil
return
nil
}
}
snapshotDir
,
err
:=
snapshotDir
(
e
.
config
)
snapshotDir
,
err
:=
snapshotDir
(
e
.
config
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
return
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
}
}
...
@@ -979,7 +979,7 @@ func (e *ETCD) initS3IfNil(ctx context.Context) error {
...
@@ -979,7 +979,7 @@ func (e *ETCD) initS3IfNil(ctx context.Context) error {
// PruneSnapshots perfrorms a retention run with the given
// PruneSnapshots perfrorms a retention run with the given
// retention duration and removes expired snapshots.
// retention duration and removes expired snapshots.
func
(
e
*
ETCD
)
PruneSnapshots
(
ctx
context
.
Context
)
error
{
func
(
e
*
ETCD
)
PruneSnapshots
(
ctx
context
.
Context
)
error
{
snapshotDir
,
err
:=
snapshotDir
(
e
.
config
)
snapshotDir
,
err
:=
snapshotDir
(
e
.
config
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
return
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
}
}
...
@@ -998,7 +998,7 @@ func (e *ETCD) PruneSnapshots(ctx context.Context) error {
...
@@ -998,7 +998,7 @@ func (e *ETCD) PruneSnapshots(ctx context.Context) error {
// 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
)
{
snapshotDir
,
err
:=
snapshotDir
(
e
.
config
)
snapshotDir
,
err
:=
snapshotDir
(
e
.
config
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
return
nil
,
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
}
}
...
@@ -1009,7 +1009,7 @@ func (e *ETCD) ListSnapshots(ctx context.Context) ([]SnapshotFile, error) {
...
@@ -1009,7 +1009,7 @@ func (e *ETCD) ListSnapshots(ctx context.Context) ([]SnapshotFile, error) {
// deleteSnapshots removes the given snapshots from
// deleteSnapshots removes the given snapshots from
// either local storage or S3.
// either local storage or S3.
func
(
e
*
ETCD
)
DeleteSnapshots
(
ctx
context
.
Context
,
snapshots
[]
string
)
error
{
func
(
e
*
ETCD
)
DeleteSnapshots
(
ctx
context
.
Context
,
snapshots
[]
string
)
error
{
snapshotDir
,
err
:=
snapshotDir
(
e
.
config
)
snapshotDir
,
err
:=
snapshotDir
(
e
.
config
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
return
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
}
}
...
@@ -1106,7 +1106,7 @@ func updateSnapshotData(data map[string]string, snapshotFiles []SnapshotFile) er
...
@@ -1106,7 +1106,7 @@ func updateSnapshotData(data map[string]string, snapshotFiles []SnapshotFile) er
func
(
e
*
ETCD
)
StoreSnapshotData
(
ctx
context
.
Context
)
error
{
func
(
e
*
ETCD
)
StoreSnapshotData
(
ctx
context
.
Context
)
error
{
logrus
.
Infof
(
"Saving current etcd snapshot set to %s ConfigMap"
,
snapshotConfigMapName
)
logrus
.
Infof
(
"Saving current etcd snapshot set to %s ConfigMap"
,
snapshotConfigMapName
)
snapshotDir
,
err
:=
snapshotDir
(
e
.
config
)
snapshotDir
,
err
:=
snapshotDir
(
e
.
config
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
return
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
}
}
...
...
pkg/etcd/s3.go
View file @
b4eca61a
...
@@ -127,7 +127,7 @@ func (s *S3) Download(ctx context.Context) error {
...
@@ -127,7 +127,7 @@ func (s *S3) Download(ctx context.Context) error {
}
}
defer
r
.
Close
()
defer
r
.
Close
()
snapshotDir
,
err
:=
snapshotDir
(
s
.
config
)
snapshotDir
,
err
:=
snapshotDir
(
s
.
config
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
return
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
}
}
...
...
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