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
e4d2824f
Unverified
Commit
e4d2824f
authored
Apr 14, 2022
by
Roberto Bonafiglia
Committed by
GitHub
Apr 14, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5420 from rbrtbnfgl/etcd-default-endpoint
Added default endpoint for IPv6
parents
dfb779d0
9c9adda6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
21 deletions
+27
-21
etcd.go
pkg/etcd/etcd.go
+24
-18
etcd_test.go
pkg/etcd/etcd_test.go
+3
-3
No files found.
pkg/etcd/etcd.go
View file @
e4d2824f
...
...
@@ -50,6 +50,7 @@ import (
const
(
defaultEndpoint
=
"https://127.0.0.1:2379"
defaultEndpointv6
=
"https://[::1]:2379"
testTimeout
=
time
.
Second
*
10
manageTickerTime
=
time
.
Second
*
15
learnerMaxStallTime
=
time
.
Minute
*
5
...
...
@@ -150,7 +151,7 @@ func (e *ETCD) EndpointName() string {
func
(
e
*
ETCD
)
SetControlConfig
(
ctx
context
.
Context
,
config
*
config
.
Control
)
error
{
e
.
config
=
config
client
,
err
:=
GetClient
(
ctx
,
e
.
config
.
Runtime
)
client
,
err
:=
GetClient
(
ctx
,
e
.
config
)
if
err
!=
nil
{
return
err
}
...
...
@@ -178,7 +179,7 @@ func (e *ETCD) Test(ctx context.Context) error {
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
testTimeout
)
defer
cancel
()
endpoints
:=
getEndpoints
(
e
.
config
.
Runtime
)
endpoints
:=
getEndpoints
(
e
.
config
)
status
,
err
:=
e
.
client
.
Status
(
ctx
,
endpoints
[
0
])
if
err
!=
nil
{
return
err
...
...
@@ -424,7 +425,7 @@ func (e *ETCD) join(ctx context.Context, clientAccessInfo *clientaccess.Info) er
return
err
}
client
,
err
:=
GetClient
(
clientCtx
,
e
.
config
.
Runtime
,
clientURLs
...
)
client
,
err
:=
GetClient
(
clientCtx
,
e
.
config
,
clientURLs
...
)
if
err
!=
nil
{
return
err
}
...
...
@@ -501,7 +502,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
:=
GetClient
(
ctx
,
e
.
config
.
Runtime
)
client
,
err
:=
GetClient
(
ctx
,
e
.
config
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -518,7 +519,7 @@ func (e *ETCD) Register(ctx context.Context, config *config.Control, handler htt
}
e
.
address
=
address
endpoints
:=
getEndpoints
(
config
.
Runtime
)
endpoints
:=
getEndpoints
(
config
)
e
.
config
.
Datastore
.
Endpoint
=
endpoints
[
0
]
e
.
config
.
Datastore
.
BackendTLSConfig
.
CAFile
=
e
.
config
.
Runtime
.
ETCDServerCA
e
.
config
.
Datastore
.
BackendTLSConfig
.
CertFile
=
e
.
config
.
Runtime
.
ClientETCDCert
...
...
@@ -609,8 +610,8 @@ func (e *ETCD) infoHandler() http.Handler {
// 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
GetClient
(
ctx
context
.
Context
,
runtime
*
config
.
ControlRuntime
,
endpoints
...
string
)
(
*
clientv3
.
Client
,
error
)
{
cfg
,
err
:=
getClientConfig
(
ctx
,
runtime
,
endpoints
...
)
func
GetClient
(
ctx
context
.
Context
,
control
*
config
.
Control
,
endpoints
...
string
)
(
*
clientv3
.
Client
,
error
)
{
cfg
,
err
:=
getClientConfig
(
ctx
,
control
,
endpoints
...
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -620,9 +621,10 @@ func GetClient(ctx context.Context, runtime *config.ControlRuntime, endpoints ..
// getClientConfig generates an etcd client config connected to the specified endpoints.
// If no endpoints are provided, getEndpoints is called to provide defaults.
func
getClientConfig
(
ctx
context
.
Context
,
runtime
*
config
.
ControlRuntime
,
endpoints
...
string
)
(
*
clientv3
.
Config
,
error
)
{
func
getClientConfig
(
ctx
context
.
Context
,
control
*
config
.
Control
,
endpoints
...
string
)
(
*
clientv3
.
Config
,
error
)
{
runtime
:=
control
.
Runtime
if
len
(
endpoints
)
==
0
{
endpoints
=
getEndpoints
(
runtime
)
endpoints
=
getEndpoints
(
control
)
}
config
:=
&
clientv3
.
Config
{
...
...
@@ -641,10 +643,14 @@ func getClientConfig(ctx context.Context, runtime *config.ControlRuntime, endpoi
}
// getEndpoints returns the endpoints from the runtime config if set, otherwise the default endpoint.
func
getEndpoints
(
runtime
*
config
.
ControlRuntime
)
[]
string
{
func
getEndpoints
(
control
*
config
.
Control
)
[]
string
{
runtime
:=
control
.
Runtime
if
len
(
runtime
.
EtcdConfig
.
Endpoints
)
>
0
{
return
runtime
.
EtcdConfig
.
Endpoints
}
if
utilsnet
.
IsIPv6String
(
control
.
PrivateIP
)
{
return
[]
string
{
defaultEndpointv6
}
}
return
[]
string
{
defaultEndpoint
}
}
...
...
@@ -730,7 +736,7 @@ func (e *ETCD) migrateFromSQLite(ctx context.Context) error {
}
defer
sqliteClient
.
Close
()
etcdClient
,
err
:=
GetClient
(
ctx
,
e
.
config
.
Runtime
)
etcdClient
,
err
:=
GetClient
(
ctx
,
e
.
config
)
if
err
!=
nil
{
return
err
}
...
...
@@ -827,7 +833,7 @@ func (e *ETCD) StartEmbeddedTemporary(ctx context.Context) error {
return
err
}
endpoints
:=
getEndpoints
(
e
.
config
.
Runtime
)
endpoints
:=
getEndpoints
(
e
.
config
)
clientURL
:=
endpoints
[
0
]
peerURL
,
err
:=
addPort
(
endpoints
[
0
],
1
)
if
err
!=
nil
{
...
...
@@ -915,7 +921,7 @@ func (e *ETCD) manageLearners(ctx context.Context) {
logrus
.
Debug
(
"Etcd client was nil"
)
continue
}
endpoints
:=
getEndpoints
(
e
.
config
.
Runtime
)
endpoints
:=
getEndpoints
(
e
.
config
)
if
status
,
err
:=
e
.
client
.
Status
(
ctx
,
endpoints
[
0
]);
err
!=
nil
{
logrus
.
Errorf
(
"Failed to check local etcd status for learner management: %v"
,
err
)
continue
...
...
@@ -1071,7 +1077,7 @@ func (e *ETCD) defragment(ctx context.Context) error {
}
logrus
.
Infof
(
"Defragmenting etcd database"
)
endpoints
:=
getEndpoints
(
e
.
config
.
Runtime
)
endpoints
:=
getEndpoints
(
e
.
config
)
_
,
err
:=
e
.
client
.
Defragment
(
ctx
,
endpoints
[
0
])
return
err
}
...
...
@@ -1144,7 +1150,7 @@ func (e *ETCD) preSnapshotSetup(ctx context.Context, config *config.Control) err
if
e
.
config
==
nil
{
e
.
config
=
config
}
client
,
err
:=
GetClient
(
ctx
,
e
.
config
.
Runtime
)
client
,
err
:=
GetClient
(
ctx
,
e
.
config
)
if
err
!=
nil
{
return
err
}
...
...
@@ -1272,7 +1278,7 @@ func (e *ETCD) Snapshot(ctx context.Context, config *config.Control) error {
}
}
endpoints
:=
getEndpoints
(
e
.
config
.
Runtime
)
endpoints
:=
getEndpoints
(
e
.
config
)
status
,
err
:=
e
.
client
.
Status
(
ctx
,
endpoints
[
0
])
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to check etcd status for snapshot"
)
...
...
@@ -1288,7 +1294,7 @@ func (e *ETCD) Snapshot(ctx context.Context, config *config.Control) error {
return
errors
.
Wrap
(
err
,
"failed to get the snapshot dir"
)
}
cfg
,
err
:=
getClientConfig
(
ctx
,
e
.
config
.
Runtime
)
cfg
,
err
:=
getClientConfig
(
ctx
,
e
.
config
)
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to get config for etcd snapshot"
)
}
...
...
@@ -2013,7 +2019,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
:=
GetClient
(
ctx
,
cfg
.
Runtime
)
cl
,
err
:=
GetClient
(
ctx
,
cfg
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
pkg/etcd/etcd_test.go
View file @
e4d2824f
...
...
@@ -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
:=
GetClient
(
ctxInfo
.
ctx
,
e
.
config
.
Runtime
)
client
,
err
:=
GetClient
(
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
:=
GetClient
(
ctxInfo
.
ctx
,
e
.
config
.
Runtime
)
client
,
err
:=
GetClient
(
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
:=
GetClient
(
ctxInfo
.
ctx
,
e
.
config
.
Runtime
)
client
,
err
:=
GetClient
(
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