-
Notifications
You must be signed in to change notification settings - Fork 301
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
Conversation
31101e0
to
bee0d63
Compare
/assign |
cmd/glbc/app/handlers.go
Outdated
@@ -33,22 +33,19 @@ import ( | |||
"k8s.io/ingress-gce/pkg/version" | |||
) | |||
|
|||
func RunHTTPServer(lbc *controller.LoadBalancerController) { | |||
func RunHTTPServer(healthcheck func() 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.
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() { |
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 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() |
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.
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)) |
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 not just math.rand.Int64()? Also, why do we have to use the k8s library?
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.
Done
pkg/flags/flags.go
Outdated
DefaultLockObjectNamespace string = "kube-system" | ||
|
||
// DefaultLockObjectName is the object name of the lock object. | ||
DefaultLockObjectName = "ingress-gce" |
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.
ingress-gce-lock? it may be a possibility to use kube-system:ingress-gce for configuration
pkg/flags/flags.go
Outdated
// 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 |
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.
Isn't this already a command line flag?
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 see it, ignore comment
pkg/flags/flags.go
Outdated
// 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 |
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.
ResourceLock => ResourceType?
aa0e0cc
to
00046f4
Compare
3f9c401
to
530136d
Compare
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 stuff, you can merge after fix
/lgtm
status := "OK" | ||
if result != nil { | ||
hasErr = true | ||
status = fmt.Sprintf("err: %v", result) |
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 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) |
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.
probably want to put more explication here
glog.Fatalf("app.NewNamer(ctx.KubeClient, %q, %q) = %v", ...)
pkg/flags/flags.go
Outdated
LeaseDuration: metav1.Duration{Duration: DefaultLeaseDuration}, | ||
RenewDeadline: metav1.Duration{Duration: DefaultRenewDeadline}, | ||
RetryPeriod: metav1.Duration{Duration: DefaultRetryPeriod}, | ||
ResourceLock: resourcelock.ConfigMapsResourceLock, |
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.
Making this default a constant
530136d
to
26c99f6
Compare
New changes are detected. LGTM label has been removed. |
Prior to starting the ingress or neg controllers, the binary will now wait to acquire a resource lock.