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 k3s lease only to avoid the informer not starting problem #10077

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,11 @@ func (e *ETCD) Register(handler http.Handler) (http.Handler, error) {
// also needs to run on a non-etcd node as to avoid disruption if running on the node that
// is being removed from the cluster.
if !e.config.DisableAPIServer {
e.config.Runtime.LeaderElectedClusterControllerStarts[version.Program+"-etcd"] = func(ctx context.Context) {
cb := e.config.Runtime.LeaderElectedClusterControllerStarts[version.Program]
e.config.Runtime.LeaderElectedClusterControllerStarts[version.Program] = func(ctx context.Context) {
if cb != nil {
cb(ctx)
}
registerEndpointsHandlers(ctx, e)
registerMemberHandlers(ctx, e)
registerSnapshotHandlers(ctx, e)
Expand Down
28 changes: 20 additions & 8 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ func runControllers(ctx context.Context, config *Config) error {
}

if !controlConfig.DisableAPIServer {
cb := controlConfig.Runtime.LeaderElectedClusterControllerStarts[version.Program]
controlConfig.Runtime.LeaderElectedClusterControllerStarts[version.Program] = func(ctx context.Context) {
if cb != nil {
cb(ctx)
}
apiserverControllers(ctx, sc, config)
}
}
Expand All @@ -144,11 +148,25 @@ func runControllers(ctx context.Context, config *Config) error {

if controlConfig.NoLeaderElect {
for name, cb := range controlConfig.Runtime.LeaderElectedClusterControllerStarts {
go runOrDie(ctx, name, cb)
go runOrDie(ctx, name, func(ctx context.Context) {
cb(ctx)
// Re-run context startup after core and leader-elected controllers have started. Additional
// informer caches may need to start for the newly added OnChange callbacks.
if err := sc.Start(ctx); err != nil {
panic(errors.Wrap(err, "failed to start wranger controllers"))
}
})
}
} else {
for name, cb := range controlConfig.Runtime.LeaderElectedClusterControllerStarts {
go leader.RunOrDie(ctx, "", name, sc.K8s, cb)
go leader.RunOrDie(ctx, "", name, sc.K8s, func(ctx context.Context) {
cb(ctx)
// Re-run context startup after core and leader-elected controllers have started. Additional
// informer caches may need to start for the newly added OnChange callbacks.
if err := sc.Start(ctx); err != nil {
panic(errors.Wrap(err, "failed to start wranger controllers"))
}
})
}
}

Expand All @@ -166,12 +184,6 @@ func apiserverControllers(ctx context.Context, sc *Context, config *Config) {
panic(errors.Wrapf(err, "failed to start %s leader controller", util.GetFunctionName(controller)))
}
}

// Re-run context startup after core and leader-elected controllers have started. Additional
// informer caches may need to start for the newly added OnChange callbacks.
if err := sc.Start(ctx); err != nil {
panic(errors.Wrap(err, "failed to start wranger controllers"))
}
}

// runOrDie is similar to leader.RunOrDie, except that it runs the callback
Expand Down