-
Notifications
You must be signed in to change notification settings - Fork 38.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 option to disable lock creation by default #109875
Conversation
Hi @aryan9600. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
f4ac2b3
to
4700ecf
Compare
return false | ||
} | ||
// don't create a lock, if lock creation is disabled. | ||
if !le.config.DisableLockCreation { |
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.
Please use
if le.config.DisableLockCreation {
return false
}
to avoid the nesting
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.
Let's also add a klog.Errorf
message. No process can become the leader if the lock doesn't exist. If a user forgets to create the lock when DisableLockCreation
is true, it's their responsibility, but let's at least make the issue more obvious to the user.
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.
I think a klog.Warningf
could be a better log level for this, since there's technically no error, it's improper use of the api.
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.
Agreed
@@ -302,6 +317,9 @@ func testTryAcquireOrRenew(t *testing.T, objectType string) { | |||
} | |||
|
|||
le.maybeReportTransition() | |||
if test.disableLockCreation { | |||
wg.Done() |
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.
Maybe also add a 30s sleep? We want to make sure no one becomes the leader asynchronously. We can sleep and verify reportedLeader
is still emtpy.
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.
I don't think that anyone can become the leader asynchronously if disableLockCreation
is true
. This can be verified by the fact that if we remove this if
block, the test will hang since the OnNewLeader
callback which calls wg.Done()
will never be called. Is it necessary to have a fairly large sleep period to test something which is redundant(imo, please correct me if i'm wrong here) ?
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.
It's to prevent someone from accidentally change the behavior and break the assumption in the future. But I agree a 30s sleep is probably too much for a unit test. I don't feel strongly
@@ -153,6 +153,10 @@ type LeaderElectionConfig struct { | |||
// simultaneously acting on the critical path. | |||
ReleaseOnCancel bool | |||
|
|||
// DisableLockCreation should be set to true if the lock should not be created, |
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.
nit: some clarifications:
"the lock should not be created when it doesn't exist"
By default (when DisableLockCreation is false), leader elector creates a new lock object when trying to acquire a non-existing lock object.
If DisableLockCreation is true and the lock object doesn't exist, the leader elector won't be able to become the leader.
/ok-to-test |
/lgtm /assign @mikedanese |
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
4228490
to
54dadcd
Compare
/retest-required |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
/lgtm |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: aryan9600, roycaihw The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /close |
@k8s-triage-robot: Closed this PR. In response to this:
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. |
Signed-off-by: Sanskar Jaiswal jaiswalsanskar078@gmail.com
What type of PR is this?
/kind feature
What this PR does / why we need it:
Adds an option
DisableLockCreation
inLeaderElectionConfig
to disable lock creationtryAcquireOrRenew()
, if set to true. This lets users manage the lifecycle of the lock, since the lock is never explicitly deleted elsewhere.Which issue(s) this PR fixes:
Fixes #109554
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: