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
59b52a15
Commit
59b52a15
authored
Apr 30, 2021
by
Brian Downs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor snapshot storage processing logic
Signed-off-by:
Brian Downs
<
brian.downs@gmail.com
>
parent
60b71bfb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
14 deletions
+12
-14
etcd.go
pkg/etcd/etcd.go
+12
-14
No files found.
pkg/etcd/etcd.go
View file @
59b52a15
...
@@ -826,8 +826,7 @@ func (e *ETCD) Snapshot(ctx context.Context, config *config.Control) error {
...
@@ -826,8 +826,7 @@ func (e *ETCD) Snapshot(ctx context.Context, config *config.Control) error {
return
errors
.
Wrap
(
err
,
"failed to get config for etcd snapshot"
)
return
errors
.
Wrap
(
err
,
"failed to get config for etcd snapshot"
)
}
}
nodeName
:=
os
.
Getenv
(
"NODE_NAME"
)
snapshotName
:=
fmt
.
Sprintf
(
"%s-%s-%d"
,
e
.
config
.
EtcdSnapshotName
,
e
.
nodeName
,
time
.
Now
()
.
Unix
())
snapshotName
:=
fmt
.
Sprintf
(
"%s-%s-%d"
,
e
.
config
.
EtcdSnapshotName
,
nodeName
,
time
.
Now
()
.
Unix
())
snapshotPath
:=
filepath
.
Join
(
snapshotDir
,
snapshotName
)
snapshotPath
:=
filepath
.
Join
(
snapshotDir
,
snapshotName
)
logrus
.
Infof
(
"Saving etcd snapshot to %s"
,
snapshotPath
)
logrus
.
Infof
(
"Saving etcd snapshot to %s"
,
snapshotPath
)
...
@@ -924,7 +923,7 @@ func (e *ETCD) listSnapshots(ctx context.Context, snapshotDir string) ([]snapsho
...
@@ -924,7 +923,7 @@ func (e *ETCD) listSnapshots(ctx context.Context, snapshotDir string) ([]snapsho
snapshots
=
append
(
snapshots
,
snapshotFile
{
snapshots
=
append
(
snapshots
,
snapshotFile
{
Name
:
filepath
.
Base
(
obj
.
Key
),
Name
:
filepath
.
Base
(
obj
.
Key
),
NodeName
:
e
.
nodeName
,
NodeName
:
"s3"
,
CreatedAt
:
&
metav1
.
Time
{
CreatedAt
:
&
metav1
.
Time
{
Time
:
ca
,
Time
:
ca
,
},
},
...
@@ -980,8 +979,6 @@ func updateSnapshotData(data map[string]string, snapshotFiles []snapshotFile) er
...
@@ -980,8 +979,6 @@ 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
)
nodeName
:=
os
.
Getenv
(
"NODE_NAME"
)
snapshotDir
,
err
:=
snapshotDir
(
e
.
config
)
snapshotDir
,
err
:=
snapshotDir
(
e
.
config
)
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"
)
...
@@ -990,6 +987,14 @@ func (e *ETCD) StoreSnapshotData(ctx context.Context) error {
...
@@ -990,6 +987,14 @@ func (e *ETCD) StoreSnapshotData(ctx context.Context) error {
return
retry
.
OnError
(
retry
.
DefaultBackoff
,
func
(
err
error
)
bool
{
return
retry
.
OnError
(
retry
.
DefaultBackoff
,
func
(
err
error
)
bool
{
return
apierrors
.
IsConflict
(
err
)
||
apierrors
.
IsAlreadyExists
(
err
)
return
apierrors
.
IsConflict
(
err
)
||
apierrors
.
IsAlreadyExists
(
err
)
},
func
()
error
{
},
func
()
error
{
// make sure the core.Factory is initialize. There can
// be a race between this core code startup.
for
e
.
config
.
Runtime
.
Core
==
nil
{
runtime
.
Gosched
()
}
snapshotConfigMap
,
getErr
:=
e
.
config
.
Runtime
.
Core
.
Core
()
.
V1
()
.
ConfigMap
()
.
Get
(
metav1
.
NamespaceSystem
,
snapshotConfigMapName
,
metav1
.
GetOptions
{})
snapshotFiles
,
err
:=
e
.
listSnapshots
(
ctx
,
snapshotDir
)
snapshotFiles
,
err
:=
e
.
listSnapshots
(
ctx
,
snapshotDir
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -1000,14 +1005,7 @@ func (e *ETCD) StoreSnapshotData(ctx context.Context) error {
...
@@ -1000,14 +1005,7 @@ func (e *ETCD) StoreSnapshotData(ctx context.Context) error {
return
err
return
err
}
}
// make sure the core.Factory is initialize. There can
if
apierrors
.
IsNotFound
(
getErr
)
{
// be a race between this core code startup.
for
e
.
config
.
Runtime
.
Core
==
nil
{
runtime
.
Gosched
()
}
snapshotConfigMap
,
err
:=
e
.
config
.
Runtime
.
Core
.
Core
()
.
V1
()
.
ConfigMap
()
.
Get
(
metav1
.
NamespaceSystem
,
snapshotConfigMapName
,
metav1
.
GetOptions
{})
if
apierrors
.
IsNotFound
(
err
)
{
cm
:=
v1
.
ConfigMap
{
cm
:=
v1
.
ConfigMap
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
snapshotConfigMapName
,
Name
:
snapshotConfigMapName
,
...
@@ -1025,7 +1023,7 @@ func (e *ETCD) StoreSnapshotData(ctx context.Context) error {
...
@@ -1025,7 +1023,7 @@ func (e *ETCD) StoreSnapshotData(ctx context.Context) error {
if
err
:=
json
.
Unmarshal
([]
byte
(
v
),
&
sf
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
([]
byte
(
v
),
&
sf
);
err
!=
nil
{
return
err
return
err
}
}
if
sf
.
NodeName
==
nodeName
{
if
sf
.
NodeName
==
e
.
nodeName
||
sf
.
NodeName
==
"s3"
{
delete
(
snapshotConfigMap
.
Data
,
k
)
delete
(
snapshotConfigMap
.
Data
,
k
)
}
}
}
}
...
...
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