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
6b837ae0
Commit
6b837ae0
authored
Jun 03, 2015
by
Brendan Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add pro-active TTL based lease releasing when we can't communicate with etcd.
parent
fc742f8c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
7 deletions
+20
-7
podmaster.go
contrib/pod-master/podmaster.go
+20
-7
No files found.
contrib/pod-master/podmaster.go
View file @
6b837ae0
...
...
@@ -42,6 +42,7 @@ type Config struct {
src
string
dest
string
sleep
time
.
Duration
lastLease
time
.
Time
}
// runs the election loop. never returns.
...
...
@@ -50,7 +51,13 @@ func (c *Config) leaseAndUpdateLoop(etcdClient *etcd.Client) {
master
,
err
:=
c
.
acquireOrRenewLease
(
etcdClient
)
if
err
!=
nil
{
glog
.
Errorf
(
"Error in master election: %v"
,
err
)
continue
if
uint64
(
time
.
Now
()
.
Sub
(
c
.
lastLease
)
.
Seconds
())
<
c
.
ttl
{
continue
}
// Our lease has expired due to our own accounting, pro-actively give it
// up, even if we couldn't contact etcd.
glog
.
Infof
(
"Too much time has elapsed, giving up lease."
)
master
=
false
}
if
err
:=
c
.
update
(
master
);
err
!=
nil
{
glog
.
Errorf
(
"Error updating files: %v"
,
err
)
...
...
@@ -64,13 +71,17 @@ func (c *Config) leaseAndUpdateLoop(etcdClient *etcd.Client) {
// TODO: use the master election utility once it is merged in.
func
(
c
*
Config
)
acquireOrRenewLease
(
etcdClient
*
etcd
.
Client
)
(
bool
,
error
)
{
result
,
err
:=
etcdClient
.
Get
(
c
.
key
,
false
,
false
)
if
tools
.
IsEtcdNotFound
(
err
)
{
// there is no current master, try to become master, create will fail if the key already exists
_
,
err
:=
etcdClient
.
Create
(
c
.
key
,
c
.
whoami
,
c
.
ttl
)
if
err
!=
nil
{
return
false
,
err
if
err
!=
nil
{
if
tools
.
IsEtcdNotFound
(
err
)
{
// there is no current master, try to become master, create will fail if the key already exists
_
,
err
:=
etcdClient
.
Create
(
c
.
key
,
c
.
whoami
,
c
.
ttl
)
if
err
!=
nil
{
return
false
,
err
}
c
.
lastLease
=
time
.
Now
()
return
true
,
nil
}
return
true
,
nil
return
false
,
err
}
if
result
.
Node
.
Value
==
c
.
whoami
{
glog
.
Infof
(
"key already exists, we are the master (%s)"
,
result
.
Node
.
Value
)
...
...
@@ -81,6 +92,7 @@ func (c *Config) acquireOrRenewLease(etcdClient *etcd.Client) (bool, error) {
return
false
,
err
}
}
c
.
lastLease
=
time
.
Now
()
return
true
,
nil
}
glog
.
Infof
(
"key already exists, the master is %s, sleeping."
,
result
.
Node
.
Value
)
...
...
@@ -97,6 +109,7 @@ func (c *Config) update(master bool) error {
switch
{
case
master
&&
!
exists
:
return
copyFile
(
c
.
src
,
c
.
dest
)
// TODO: validate sha hash for the two files and overwrite if dest is different than src.
case
!
master
&&
exists
:
return
os
.
Remove
(
c
.
dest
)
}
...
...
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