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

Use leader election to prevent multiple controllers running #258

Merged
merged 2 commits into from
Jun 6, 2018

Conversation

nicksardo
Copy link
Contributor

@nicksardo nicksardo commented May 9, 2018

Prior to starting the ingress or neg controllers, the binary will now wait to acquire a resource lock.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 9, 2018
@bowei
Copy link
Member

bowei commented May 25, 2018

/assign

@nicksardo nicksardo changed the title Use leader election to prevent multiple controllers running [WIP] Use leader election to prevent multiple controllers running May 25, 2018
@@ -33,22 +33,19 @@ import (
"k8s.io/ingress-gce/pkg/version"
)

func RunHTTPServer(lbc *controller.LoadBalancerController) {
func RunHTTPServer(healthcheck func() error) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you document what the contract is for healthcheck?

cmd/glbc/main.go Outdated
healthCheck := func() error { return nil }
go app.RunHTTPServer(healthCheck)

run := func() {
Copy link
Member

Choose a reason for hiding this comment

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

make this a real method, unless you are heavily using variable capture

cmd/glbc/main.go Outdated
go app.RunHTTPServer(lbc)
go app.RunSIGTERMHandler(lbc, flags.F.DeleteAllOnQuit)
if !flags.F.LeaderElection.Enabled {
run()
Copy link
Member

Choose a reason for hiding this comment

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

return

cmd/glbc/main.go Outdated
}
// add a uniquifier so that two processes on the same host don't accidentally both become active
id := fmt.Sprintf("%v_%x", hostname, rand.Intn(1e6))
Copy link
Member

Choose a reason for hiding this comment

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

why not just math.rand.Int64()? Also, why do we have to use the k8s library?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

DefaultLockObjectNamespace string = "kube-system"

// DefaultLockObjectName is the object name of the lock object.
DefaultLockObjectName = "ingress-gce"
Copy link
Member

Choose a reason for hiding this comment

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

ingress-gce-lock? it may be a possibility to use kube-system:ingress-gce for configuration

// Enabled enables a leader election client to gain leadership
// before executing the main loop. Enable this when running replicated
// components for high availability.
Enabled bool
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this already a command line flag?

Copy link
Member

Choose a reason for hiding this comment

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

i see it, ignore comment

// acquisition and renewal of a leadership. This is only applicable if
// leader election is enabled.
RetryPeriod time.Duration
// ResourceLock indicates the resource object type that will be used to lock
Copy link
Member

Choose a reason for hiding this comment

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

ResourceLock => ResourceType?

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 1, 2018
@nicksardo nicksardo force-pushed the leader-election branch 7 times, most recently from 3f9c401 to 530136d Compare June 4, 2018 21:23
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 6, 2018
Copy link
Member

@bowei bowei left a comment

Choose a reason for hiding this comment

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

minor stuff, you can merge after fix

/lgtm

status := "OK"
if result != nil {
hasErr = true
status = fmt.Sprintf("err: %v", result)
Copy link
Member

Choose a reason for hiding this comment

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

would be easier for the consumer if this was JSON, but let's take it up in a follow up PR

cmd/glbc/main.go Outdated
func runControllers(ctx *context.ControllerContext, cloud *gce.GCECloud) {
namer, err := app.NewNamer(ctx.KubeClient, flags.F.ClusterName, controller.DefaultFirewallName)
if err != nil {
glog.Fatalf("%v", err)
Copy link
Member

Choose a reason for hiding this comment

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

probably want to put more explication here

glog.Fatalf("app.NewNamer(ctx.KubeClient, %q, %q) = %v", ...)

LeaseDuration: metav1.Duration{Duration: DefaultLeaseDuration},
RenewDeadline: metav1.Duration{Duration: DefaultRenewDeadline},
RetryPeriod: metav1.Duration{Duration: DefaultRetryPeriod},
ResourceLock: resourcelock.ConfigMapsResourceLock,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making this default a constant

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

New changes are detected. LGTM label has been removed.

@nicksardo nicksardo added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 6, 2018
@nicksardo nicksardo merged commit 0905182 into kubernetes:master Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants