-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Make leader election lease duration configurable through manager options #412
Make leader election lease duration configurable through manager options #412
Conversation
|
||
// LeaseDurationSeconds is the duration that non-leader candidates will | ||
// wait to force acquire leadership. | ||
LeaseDurationSeconds int |
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.
any reason this is not time.Duration
?
a9e062c
to
e7a24d7
Compare
pkg/manager/internal.go
Outdated
|
||
// leaseDurationSeconds is the duration that non-leader candidates will | ||
// wait to force acquire leadership. | ||
leaseDurationSeconds *time.Duration |
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.
would prefer to do the defaulting during contruction and have non-pointers here.
pkg/manager/manager.go
Outdated
// LeaseDuration is the duration that non-leader candidates will | ||
// wait to force acquire leadership. This is measured against time of | ||
// last observed ack. | ||
LeaseDurationSeconds *time.Duration |
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.
why are these pointers?
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.
Trying to keep consistent with already existing syncPeriod
, https://github.com/kubernetes-sigs/controller-runtime/pull/412/files#diff-7d903b129bc883285ffc5068c39c00b0R102
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 document the defaults.
e7a24d7
to
abbfe3e
Compare
pkg/manager/manager.go
Outdated
@@ -231,22 +242,42 @@ func New(config *rest.Config, options Options) (Manager, error) { | |||
|
|||
stop := make(chan struct{}) | |||
|
|||
var leaseDuration, renewDeadline, retryPeriod time.Duration |
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.
`leastDuration, renewDeadline, retryPeriod := defaultLeastDuration, ...``
Then if clauses without else. Makes it much easier to read.
8abca02
to
bac717e
Compare
pkg/manager/internal.go
Outdated
|
||
// leaseDurationSeconds is the duration that non-leader candidates will | ||
// wait to force acquire leadership. | ||
leaseDurationSeconds time.Duration |
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.
drop the seconds suffix, and the * time.Second
below. Durations have units already.
pkg/manager/internal.go
Outdated
@@ -40,6 +40,13 @@ import ( | |||
"sigs.k8s.io/controller-runtime/pkg/webhook" | |||
) | |||
|
|||
const ( | |||
// Values taken from: https://github.com/kubernetes/apiserver/blob/master/pkg/apis/config/v1alpha1/defaults.go | |||
defaultLeaseDuration = 15 |
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 these durations (* time.Second
)
40076ec
to
982c34a
Compare
/assign @droot @DirectXMan12 For approval. /lgtm |
I think we need to turn off cyclomatic complexity for the Personally, I think that makes sense as the new function is still very readable and I don't think it makes sense to make another function just for this. |
982c34a
to
64cbce7
Compare
64cbce7
to
1c6d891
Compare
@@ -37,7 +37,11 @@ import ( | |||
func Example() { | |||
var log = controllers.Log.WithName("builder-examples") | |||
|
|||
manager, err := controllers.NewManager(controllers.GetConfigOrDie(), controllers.Options{}) | |||
manager, err := controllers.NewManager(controllers.GetConfigOrDie(), controllers.Options{ |
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 you instead create a new example to show how to change leader election lease duration?
a50eae8
to
2560635
Compare
/retest |
/lgtm |
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.
minor comments inline, otherwise seems reasonable
I'm slightly worried about the increase of options in the main controller-manager struct. We might want to consider folding out leader election into its own struct, but I'm not sure we're there yet, and that the ergonomics are worth it.
what do other people thing @droot @shawn-hurley @coderanger
pkg/manager/manager.go
Outdated
@@ -173,6 +184,7 @@ func (r RunnableFunc) Start(s <-chan struct{}) error { | |||
} | |||
|
|||
// New returns a new Manager for creating Controllers. | |||
// nolint: gocyclo |
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.
??
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 don't just turn off the lints because they're annoying. This seems to suggest that perhaps leader election setup should be in a separate helper function.
pkg/manager/manager.go
Outdated
} | ||
if options.RetryPeriod == nil { | ||
retryPeriod = defaultRetryPeriod | ||
} |
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 should be in setOptionsDefaults, as per everything else that's a default
2560635
to
7205f87
Compare
7205f87
to
839f168
Compare
839f168
to
b8b7071
Compare
/retest |
1 similar comment
/retest |
/test all |
ping @DirectXMan12 @sttts @shawn-hurley . |
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.
Looks good to me. minor nit.
@@ -302,6 +316,18 @@ func setOptionsDefaults(options Options) Options { | |||
if options.newMetricsListener == nil { | |||
options.newMetricsListener = metrics.NewListener | |||
} | |||
leaseDuration, renewDeadline, retryPeriod := defaultLeaseDuration, defaultRenewDeadline, defaultRetryPeriod |
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.
We should pull the options.newResourceLock = leaderelection.NewResourceLock
code fragment above closer to this block so that all leader election bits are in same place.
@DirectXMan12 I agree we are not there yet. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: DirectXMan12, vikaschoudhary16 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 |
No description provided.