-
Notifications
You must be signed in to change notification settings - Fork 39.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Lease implementation to leaderelection package #70778
Conversation
staging/src/k8s.io/client-go/tools/leaderelection/resourcelock/leaselock.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/client-go/tools/leaderelection/resourcelock/leaselock.go
Outdated
Show resolved
Hide resolved
if spec.HolderIdentity != nil { | ||
holderIdentity = *spec.HolderIdentity | ||
} | ||
leaseDurationSeconds := 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this allows empty holder identity and zero lease duration in the record, which looks slightly odd. but stepping thru the elector, it will work fine i suppose.
return metav1.NewTime(t), nil | ||
} | ||
|
||
func timeToMicroTime(u *metav1.Time) (metav1.MicroTime, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kubernetes/staging/src/k8s.io/client-go/tools/leaderelection/resourcelock/interface.go
Lines 40 to 41 in 16d0992
AcquireTime metav1.Time `json:"acquireTime"` | |
RenewTime metav1.Time `json:"renewTime"` |
can we switch them to micro time? @mikedanese
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wongma7 why is this helpful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I see that LeaseSpec went with microtime. It should be fine. We don't actually use it to implement correctness. Also metav1.MicroTime to metav1.Time is just:
time := metav1.Time{microTime.Time}
No need for this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow 👍 fixed in new patch
/cc @cheftako |
91f527d
to
5da7a58
Compare
/test pull-kubernetes-e2e-kops-aws |
58a2b76
to
a041e47
Compare
cc @wojtek-t |
/assign |
staging/src/k8s.io/client-go/tools/leaderelection/leaderelection_test.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/client-go/tools/leaderelection/leaderelection_test.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/client-go/tools/leaderelection/leaderelection_test.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/client-go/tools/leaderelection/resourcelock/interface.go
Outdated
Show resolved
Hide resolved
return ll.LockConfig.Identity | ||
} | ||
|
||
func LeaderElectionRecordToLeaseSpec(ler *LeaderElectionRecord) coordinationv1.LeaseSpec { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't access from leaderelection/leaderelection_test.go otherwise, same as the new leaseSpecToLeaderElectionRecord
staging/src/k8s.io/client-go/tools/leaderelection/resourcelock/leaselock.go
Show resolved
Hide resolved
staging/src/k8s.io/client-go/tools/leaderelection/resourcelock/leaselock.go
Outdated
Show resolved
Hide resolved
I'm generally happy with this. Had a couple suggestions. /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mikedanese, wongma7 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
LGTM |
squashed, thank you |
/lgtm |
/retest |
1 similar comment
/retest |
@wongma7: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
What type of PR is this?
/kind feature
What this PR does / why we need it: enables components to use coordination/Lease objects for leaderelection as opposed to endpoints/configmaps. e.g. https://github.com/kubernetes-csi/external-attacher (which doesn't need the configmap) and https://github.com/kubernetes-csi/external-provisioner/ (which is currently using endpoints (oops) and would like to move away)
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #kubernetes/client-go#499
Special notes for your reviewer: Don't know if this is wanted, I see the Lease object is used by kubelet but don't see it anywhere else. Created kubernetes/client-go#499 & didn't get a response.
Does this PR introduce a user-facing change?: