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
9fe2a5a4
Commit
9fe2a5a4
authored
May 11, 2018
by
zhengjiajin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enhance leaderelection code
parent
e59ae29f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
11 deletions
+7
-11
leaderelection.go
...c/k8s.io/client-go/tools/leaderelection/leaderelection.go
+7
-11
No files found.
staging/src/k8s.io/client-go/tools/leaderelection/leaderelection.go
View file @
9fe2a5a4
...
@@ -119,10 +119,6 @@ type LeaderCallbacks struct {
...
@@ -119,10 +119,6 @@ type LeaderCallbacks struct {
}
}
// LeaderElector is a leader election client.
// LeaderElector is a leader election client.
//
// possible future methods:
// * (le *LeaderElector) IsLeader()
// * (le *LeaderElector) GetLeader()
type
LeaderElector
struct
{
type
LeaderElector
struct
{
config
LeaderElectionConfig
config
LeaderElectionConfig
// internal bookkeeping
// internal bookkeeping
...
@@ -239,14 +235,14 @@ func (le *LeaderElector) tryAcquireOrRenew() bool {
...
@@ -239,14 +235,14 @@ func (le *LeaderElector) tryAcquireOrRenew() bool {
le
.
observedTime
=
time
.
Now
()
le
.
observedTime
=
time
.
Now
()
}
}
if
le
.
observedTime
.
Add
(
le
.
config
.
LeaseDuration
)
.
After
(
now
.
Time
)
&&
if
le
.
observedTime
.
Add
(
le
.
config
.
LeaseDuration
)
.
After
(
now
.
Time
)
&&
oldLeaderElectionRecord
.
HolderIdentity
!=
le
.
config
.
Lock
.
Identity
()
{
!
le
.
IsLeader
()
{
glog
.
V
(
4
)
.
Infof
(
"lock is held by %v and has not yet expired"
,
oldLeaderElectionRecord
.
HolderIdentity
)
glog
.
V
(
4
)
.
Infof
(
"lock is held by %v and has not yet expired"
,
oldLeaderElectionRecord
.
HolderIdentity
)
return
false
return
false
}
}
// 3. We're going to try to update. The leaderElectionRecord is set to it's default
// 3. We're going to try to update. The leaderElectionRecord is set to it's default
// here. Let's correct it before updating.
// here. Let's correct it before updating.
if
oldLeaderElectionRecord
.
HolderIdentity
==
le
.
config
.
Lock
.
Identity
()
{
if
le
.
IsLeader
()
{
leaderElectionRecord
.
AcquireTime
=
oldLeaderElectionRecord
.
AcquireTime
leaderElectionRecord
.
AcquireTime
=
oldLeaderElectionRecord
.
AcquireTime
leaderElectionRecord
.
LeaderTransitions
=
oldLeaderElectionRecord
.
LeaderTransitions
leaderElectionRecord
.
LeaderTransitions
=
oldLeaderElectionRecord
.
LeaderTransitions
}
else
{
}
else
{
...
@@ -263,12 +259,12 @@ func (le *LeaderElector) tryAcquireOrRenew() bool {
...
@@ -263,12 +259,12 @@ func (le *LeaderElector) tryAcquireOrRenew() bool {
return
true
return
true
}
}
func
(
l
*
LeaderElector
)
maybeReportTransition
()
{
func
(
l
e
*
LeaderElector
)
maybeReportTransition
()
{
if
l
.
observedRecord
.
HolderIdentity
==
l
.
reportedLeader
{
if
l
e
.
observedRecord
.
HolderIdentity
==
le
.
reportedLeader
{
return
return
}
}
l
.
reportedLeader
=
l
.
observedRecord
.
HolderIdentity
l
e
.
reportedLeader
=
le
.
observedRecord
.
HolderIdentity
if
l
.
config
.
Callbacks
.
OnNewLeader
!=
nil
{
if
l
e
.
config
.
Callbacks
.
OnNewLeader
!=
nil
{
go
l
.
config
.
Callbacks
.
OnNewLeader
(
l
.
reportedLeader
)
go
l
e
.
config
.
Callbacks
.
OnNewLeader
(
le
.
reportedLeader
)
}
}
}
}
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