Skip to content
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

Conversation

vikaschoudhary16
Copy link
Contributor

@vikaschoudhary16 vikaschoudhary16 commented Apr 29, 2019

No description provided.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 29, 2019
@k8s-ci-robot k8s-ci-robot requested review from droot and pwittrock April 29, 2019 10:02
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 29, 2019

// LeaseDurationSeconds is the duration that non-leader candidates will
// wait to force acquire leadership.
LeaseDurationSeconds int
Copy link

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?

@vikaschoudhary16 vikaschoudhary16 force-pushed the le-leaseduration-configurable branch from a9e062c to e7a24d7 Compare April 30, 2019 09:55

// leaseDurationSeconds is the duration that non-leader candidates will
// wait to force acquire leadership.
leaseDurationSeconds *time.Duration
Copy link

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.

// 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these pointers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document the defaults.

@vikaschoudhary16 vikaschoudhary16 force-pushed the le-leaseduration-configurable branch from e7a24d7 to abbfe3e Compare April 30, 2019 10:41
@@ -231,22 +242,42 @@ func New(config *rest.Config, options Options) (Manager, error) {

stop := make(chan struct{})

var leaseDuration, renewDeadline, retryPeriod time.Duration
Copy link

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.

@vikaschoudhary16 vikaschoudhary16 force-pushed the le-leaseduration-configurable branch 2 times, most recently from 8abca02 to bac717e Compare April 30, 2019 11:22

// leaseDurationSeconds is the duration that non-leader candidates will
// wait to force acquire leadership.
leaseDurationSeconds time.Duration
Copy link

@sttts sttts Apr 30, 2019

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.

@@ -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
Copy link

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)

@vikaschoudhary16 vikaschoudhary16 force-pushed the le-leaseduration-configurable branch 2 times, most recently from 40076ec to 982c34a Compare April 30, 2019 12:01
@sttts
Copy link

sttts commented Apr 30, 2019

/assign @droot @DirectXMan12

For approval.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 30, 2019
@shawn-hurley
Copy link

I think we need to turn off cyclomatic complexity for the New function for this to pass CI.

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.

@vikaschoudhary16 vikaschoudhary16 force-pushed the le-leaseduration-configurable branch from 982c34a to 64cbce7 Compare May 6, 2019 11:59
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 6, 2019
@vikaschoudhary16 vikaschoudhary16 force-pushed the le-leaseduration-configurable branch from 64cbce7 to 1c6d891 Compare May 6, 2019 12:07
@@ -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{

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?

@vikaschoudhary16 vikaschoudhary16 force-pushed the le-leaseduration-configurable branch 3 times, most recently from a50eae8 to 2560635 Compare May 6, 2019 14:25
@vikaschoudhary16
Copy link
Contributor Author

/retest

@shawn-hurley
Copy link

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 6, 2019
Copy link
Contributor

@DirectXMan12 DirectXMan12 left a 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

@@ -173,6 +184,7 @@ func (r RunnableFunc) Start(s <-chan struct{}) error {
}

// New returns a new Manager for creating Controllers.
// nolint: gocyclo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Copy link
Contributor

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.

}
if options.RetryPeriod == nil {
retryPeriod = defaultRetryPeriod
}
Copy link
Contributor

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

@vikaschoudhary16 vikaschoudhary16 force-pushed the le-leaseduration-configurable branch from 2560635 to 7205f87 Compare May 14, 2019 12:31
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 14, 2019
@vikaschoudhary16 vikaschoudhary16 force-pushed the le-leaseduration-configurable branch from 7205f87 to 839f168 Compare May 14, 2019 12:44
@vikaschoudhary16 vikaschoudhary16 force-pushed the le-leaseduration-configurable branch from 839f168 to b8b7071 Compare May 14, 2019 12:51
@vikaschoudhary16
Copy link
Contributor Author

/retest

1 similar comment
@vikaschoudhary16
Copy link
Contributor Author

/retest

@vikaschoudhary16
Copy link
Contributor Author

/test all

@vikaschoudhary16
Copy link
Contributor Author

ping @DirectXMan12 @sttts @shawn-hurley .

Copy link
Contributor

@droot droot left a 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
Copy link
Contributor

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.

@droot
Copy link
Contributor

droot commented May 16, 2019

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.

@DirectXMan12 I agree we are not there yet.

@DirectXMan12
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 16, 2019
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 16, 2019
@k8s-ci-robot k8s-ci-robot merged commit f39791e into kubernetes-sigs:master May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants