mirror of https://github.com/k3s-io/k3s.git
Use k3s lease only to avoid the informer not starting problem
The logic of the k3s controllers and the k3s-etcd controllers is in the same condition which is APIServer enabled. After running all the callbacks of k3s lease then re-start the controllers can avoid the informer not starting problem of etcd snapshot handlers. Signed-off-by: Yuxing Deng <jxfa0043379@hotmail.com>
This commit is contained in:
parent
14549535f1
commit
7d68d9e210
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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"))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue