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
89064592
Commit
89064592
authored
Sep 21, 2023
by
Brad Davidson
Committed by
Brad Davidson
Sep 25, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't export functions not needed outside the etcd package
Signed-off-by:
Brad Davidson
<
brad.davidson@rancher.com
>
parent
a3c52d60
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
31 deletions
+31
-31
etcd.go
pkg/etcd/etcd.go
+25
-25
etcd_test.go
pkg/etcd/etcd_test.go
+6
-6
No files found.
pkg/etcd/etcd.go
View file @
89064592
...
...
@@ -167,7 +167,7 @@ func (e *ETCD) EndpointName() string {
func
(
e
*
ETCD
)
SetControlConfig
(
ctx
context
.
Context
,
config
*
config
.
Control
)
error
{
e
.
config
=
config
client
,
err
:=
G
etClient
(
ctx
,
e
.
config
)
client
,
err
:=
g
etClient
(
ctx
,
e
.
config
)
if
err
!=
nil
{
return
err
}
...
...
@@ -242,26 +242,26 @@ func (e *ETCD) Test(ctx context.Context) error {
return
&
MembershipError
{
Members
:
memberNameUrls
,
Self
:
e
.
name
+
"="
+
e
.
peerURL
()}
}
//
DB
Dir returns the path to dataDir/db/etcd
func
DB
Dir
(
config
*
config
.
Control
)
string
{
//
db
Dir returns the path to dataDir/db/etcd
func
db
Dir
(
config
*
config
.
Control
)
string
{
return
filepath
.
Join
(
config
.
DataDir
,
"db"
,
"etcd"
)
}
// walDir returns the path to etcd
DB
Dir/member/wal
// walDir returns the path to etcd
db
Dir/member/wal
func
walDir
(
config
*
config
.
Control
)
string
{
return
filepath
.
Join
(
DB
Dir
(
config
),
"member"
,
"wal"
)
return
filepath
.
Join
(
db
Dir
(
config
),
"member"
,
"wal"
)
}
func
sqliteFile
(
config
*
config
.
Control
)
string
{
return
filepath
.
Join
(
config
.
DataDir
,
"db"
,
"state.db"
)
}
// nameFile returns the path to etcd
DB
Dir/name.
// nameFile returns the path to etcd
db
Dir/name.
func
nameFile
(
config
*
config
.
Control
)
string
{
return
filepath
.
Join
(
DB
Dir
(
config
),
"name"
)
return
filepath
.
Join
(
db
Dir
(
config
),
"name"
)
}
// ResetFile returns the path to etcd
DB
Dir/reset-flag.
// ResetFile returns the path to etcd
db
Dir/reset-flag.
func
ResetFile
(
config
*
config
.
Control
)
string
{
return
filepath
.
Join
(
config
.
DataDir
,
"db"
,
"reset-flag"
)
}
...
...
@@ -389,7 +389,7 @@ func (e *ETCD) Start(ctx context.Context, clientAccessInfo *clientaccess.Info) e
if
isInitialized
{
//check etcd dir permission
etcdDir
:=
DB
Dir
(
e
.
config
)
etcdDir
:=
db
Dir
(
e
.
config
)
info
,
err
:=
os
.
Stat
(
etcdDir
)
if
err
!=
nil
{
return
err
...
...
@@ -455,7 +455,7 @@ func (e *ETCD) join(ctx context.Context, clientAccessInfo *clientaccess.Info) er
return
err
}
client
,
err
:=
G
etClient
(
clientCtx
,
e
.
config
,
clientURLs
...
)
client
,
err
:=
g
etClient
(
clientCtx
,
e
.
config
,
clientURLs
...
)
if
err
!=
nil
{
return
err
}
...
...
@@ -520,7 +520,7 @@ func (e *ETCD) join(ctx context.Context, clientAccessInfo *clientaccess.Info) er
func
(
e
*
ETCD
)
Register
(
ctx
context
.
Context
,
config
*
config
.
Control
,
handler
http
.
Handler
)
(
http
.
Handler
,
error
)
{
e
.
config
=
config
client
,
err
:=
G
etClient
(
ctx
,
e
.
config
)
client
,
err
:=
g
etClient
(
ctx
,
e
.
config
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -560,10 +560,10 @@ func (e *ETCD) Register(ctx context.Context, config *config.Control, handler htt
// Tombstone file checking is unnecessary if we're not running etcd.
if
!
e
.
config
.
DisableETCD
{
tombstoneFile
:=
filepath
.
Join
(
DB
Dir
(
e
.
config
),
"tombstone"
)
tombstoneFile
:=
filepath
.
Join
(
db
Dir
(
e
.
config
),
"tombstone"
)
if
_
,
err
:=
os
.
Stat
(
tombstoneFile
);
err
==
nil
{
logrus
.
Infof
(
"tombstone file has been detected, removing data dir to rejoin the cluster"
)
if
_
,
err
:=
backupDirWithRetention
(
DB
Dir
(
e
.
config
),
maxBackupRetention
);
err
!=
nil
{
if
_
,
err
:=
backupDirWithRetention
(
db
Dir
(
e
.
config
),
maxBackupRetention
);
err
!=
nil
{
return
nil
,
err
}
}
...
...
@@ -631,12 +631,12 @@ func (e *ETCD) infoHandler() http.Handler {
})
}
//
G
etClient returns an etcd client connected to the specified endpoints.
//
g
etClient returns an etcd client connected to the specified endpoints.
// If no endpoints are provided, endpoints are retrieved from the provided runtime config.
// If the runtime config does not list any endpoints, the default endpoint is used.
// The returned client should be closed when no longer needed, in order to avoid leaking GRPC
// client goroutines.
func
G
etClient
(
ctx
context
.
Context
,
control
*
config
.
Control
,
endpoints
...
string
)
(
*
clientv3
.
Client
,
error
)
{
func
g
etClient
(
ctx
context
.
Context
,
control
*
config
.
Control
,
endpoints
...
string
)
(
*
clientv3
.
Client
,
error
)
{
cfg
,
err
:=
getClientConfig
(
ctx
,
control
,
endpoints
...
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -761,7 +761,7 @@ func (e *ETCD) migrateFromSQLite(ctx context.Context) error {
}
defer
sqliteClient
.
Close
()
etcdClient
,
err
:=
G
etClient
(
ctx
,
e
.
config
)
etcdClient
,
err
:=
g
etClient
(
ctx
,
e
.
config
)
if
err
!=
nil
{
return
err
}
...
...
@@ -853,7 +853,7 @@ func (e *ETCD) cluster(ctx context.Context, reset bool, options executor.Initial
ListenMetricsURLs
:
e
.
listenMetricsURLs
(
reset
),
ListenPeerURLs
:
e
.
listenPeerURLs
(
reset
),
AdvertiseClientURLs
:
e
.
advertiseClientURLs
(
reset
),
DataDir
:
DB
Dir
(
e
.
config
),
DataDir
:
db
Dir
(
e
.
config
),
ServerTrust
:
executor
.
ServerTrust
{
CertFile
:
e
.
config
.
Runtime
.
ServerETCDCert
,
KeyFile
:
e
.
config
.
Runtime
.
ServerETCDKey
,
...
...
@@ -877,7 +877,7 @@ func (e *ETCD) cluster(ctx context.Context, reset bool, options executor.Initial
}
func
(
e
*
ETCD
)
StartEmbeddedTemporary
(
ctx
context
.
Context
)
error
{
etcdDataDir
:=
DB
Dir
(
e
.
config
)
etcdDataDir
:=
db
Dir
(
e
.
config
)
tmpDataDir
:=
etcdDataDir
+
"-tmp"
os
.
RemoveAll
(
tmpDataDir
)
...
...
@@ -1222,7 +1222,7 @@ func (e *ETCD) preSnapshotSetup(ctx context.Context, config *config.Control) err
if
e
.
config
==
nil
{
e
.
config
=
config
}
client
,
err
:=
G
etClient
(
ctx
,
e
.
config
)
client
,
err
:=
g
etClient
(
ctx
,
e
.
config
)
if
err
!=
nil
{
return
err
}
...
...
@@ -1990,7 +1990,7 @@ func (e *ETCD) setSnapshotFunction(ctx context.Context) {
// completion.
func
(
e
*
ETCD
)
Restore
(
ctx
context
.
Context
)
error
{
// check the old etcd data dir
oldDataDir
:=
DB
Dir
(
e
.
config
)
+
"-old-"
+
strconv
.
Itoa
(
int
(
time
.
Now
()
.
Unix
()))
oldDataDir
:=
db
Dir
(
e
.
config
)
+
"-old-"
+
strconv
.
Itoa
(
int
(
time
.
Now
()
.
Unix
()))
if
e
.
config
.
ClusterResetRestorePath
==
""
{
return
errors
.
New
(
"no etcd restore path was specified"
)
}
...
...
@@ -2017,7 +2017,7 @@ func (e *ETCD) Restore(ctx context.Context) error {
}
// move the data directory to a temp path
if
err
:=
os
.
Rename
(
DB
Dir
(
e
.
config
),
oldDataDir
);
err
!=
nil
{
if
err
:=
os
.
Rename
(
db
Dir
(
e
.
config
),
oldDataDir
);
err
!=
nil
{
return
err
}
...
...
@@ -2031,7 +2031,7 @@ func (e *ETCD) Restore(ctx context.Context) error {
return
snapshot
.
NewV3
(
lg
)
.
Restore
(
snapshot
.
RestoreConfig
{
SnapshotPath
:
restorePath
,
Name
:
e
.
name
,
OutputDataDir
:
DB
Dir
(
e
.
config
),
OutputDataDir
:
db
Dir
(
e
.
config
),
OutputWALDir
:
walDir
(
e
.
config
),
PeerURLs
:
[]
string
{
e
.
peerURL
()},
InitialCluster
:
e
.
name
+
"="
+
e
.
peerURL
(),
...
...
@@ -2127,7 +2127,7 @@ func backupDirWithRetention(dir string, maxBackupRetention int) (string, error)
// GetAPIServerURLsFromETCD will try to fetch the version.Program/apiaddresses key from etcd
// and unmarshal it to a list of apiserver endpoints.
func
GetAPIServerURLsFromETCD
(
ctx
context
.
Context
,
cfg
*
config
.
Control
)
([]
string
,
error
)
{
cl
,
err
:=
G
etClient
(
ctx
,
cfg
)
cl
,
err
:=
g
etClient
(
ctx
,
cfg
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -2181,8 +2181,8 @@ func (e *ETCD) RemoveSelf(ctx context.Context) error {
}
// backup the data dir to avoid issues when re-enabling etcd
oldDataDir
:=
DB
Dir
(
e
.
config
)
+
"-old-"
+
strconv
.
Itoa
(
int
(
time
.
Now
()
.
Unix
()))
oldDataDir
:=
db
Dir
(
e
.
config
)
+
"-old-"
+
strconv
.
Itoa
(
int
(
time
.
Now
()
.
Unix
()))
// move the data directory to a temp path
return
os
.
Rename
(
DB
Dir
(
e
.
config
),
oldDataDir
)
return
os
.
Rename
(
db
Dir
(
e
.
config
),
oldDataDir
)
}
pkg/etcd/etcd_test.go
View file @
89064592
...
...
@@ -170,17 +170,17 @@ func Test_UnitETCD_Register(t *testing.T) {
if
err
:=
testutil
.
GenerateRuntime
(
cnf
);
err
!=
nil
{
return
err
}
if
err
:=
os
.
MkdirAll
(
DB
Dir
(
cnf
),
0700
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
db
Dir
(
cnf
),
0700
);
err
!=
nil
{
return
err
}
tombstoneFile
:=
filepath
.
Join
(
DB
Dir
(
cnf
),
"tombstone"
)
tombstoneFile
:=
filepath
.
Join
(
db
Dir
(
cnf
),
"tombstone"
)
if
_
,
err
:=
os
.
Create
(
tombstoneFile
);
err
!=
nil
{
return
err
}
return
nil
},
teardown
:
func
(
cnf
*
config
.
Control
)
error
{
tombstoneFile
:=
filepath
.
Join
(
DB
Dir
(
cnf
),
"tombstone"
)
tombstoneFile
:=
filepath
.
Join
(
db
Dir
(
cnf
),
"tombstone"
)
os
.
Remove
(
tombstoneFile
)
testutil
.
CleanupDataDir
(
cnf
)
return
nil
...
...
@@ -244,7 +244,7 @@ func Test_UnitETCD_Start(t *testing.T) {
ctxInfo
.
ctx
,
ctxInfo
.
cancel
=
context
.
WithCancel
(
context
.
Background
())
e
.
config
.
EtcdDisableSnapshots
=
true
testutil
.
GenerateRuntime
(
e
.
config
)
client
,
err
:=
G
etClient
(
ctxInfo
.
ctx
,
e
.
config
)
client
,
err
:=
g
etClient
(
ctxInfo
.
ctx
,
e
.
config
)
e
.
client
=
client
return
err
...
...
@@ -275,7 +275,7 @@ func Test_UnitETCD_Start(t *testing.T) {
setup
:
func
(
e
*
ETCD
,
ctxInfo
*
contextInfo
)
error
{
ctxInfo
.
ctx
,
ctxInfo
.
cancel
=
context
.
WithCancel
(
context
.
Background
())
testutil
.
GenerateRuntime
(
e
.
config
)
client
,
err
:=
G
etClient
(
ctxInfo
.
ctx
,
e
.
config
)
client
,
err
:=
g
etClient
(
ctxInfo
.
ctx
,
e
.
config
)
e
.
client
=
client
return
err
...
...
@@ -308,7 +308,7 @@ func Test_UnitETCD_Start(t *testing.T) {
if
err
:=
testutil
.
GenerateRuntime
(
e
.
config
);
err
!=
nil
{
return
err
}
client
,
err
:=
G
etClient
(
ctxInfo
.
ctx
,
e
.
config
)
client
,
err
:=
g
etClient
(
ctxInfo
.
ctx
,
e
.
config
)
if
err
!=
nil
{
return
err
}
...
...
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