diff --git a/pkg/controllers/kube-apiserver.go b/pkg/controllers/kube-apiserver.go index 74e333ad444..2b7dbb1506b 100644 --- a/pkg/controllers/kube-apiserver.go +++ b/pkg/controllers/kube-apiserver.go @@ -389,8 +389,21 @@ func (s *KubeAPIServer) Run(ctx context.Context, ready chan<- struct{}, stopped "--openshift-config", fd.Name(), "-v", strconv.Itoa(s.verbosity), }) + + panicChannel := make(chan any, 1) go func() { + defer func() { + if r := recover(); r != nil { + panicChannel <- r + } + }() errorChannel <- cmd.ExecuteContext(ctx) }() - return <-errorChannel + + select { + case err := <-errorChannel: + return err + case perr := <-panicChannel: + panic(perr) + } } diff --git a/pkg/controllers/kube-controller-manager.go b/pkg/controllers/kube-controller-manager.go index 17e6c071f23..52fca3b7163 100644 --- a/pkg/controllers/kube-controller-manager.go +++ b/pkg/controllers/kube-controller-manager.go @@ -138,14 +138,27 @@ func (s *KubeControllerManager) Run(ctx context.Context, ready chan<- struct{}, // which expects to be called at most once in a process. cmd := kubecm.NewControllerManagerCommand() cmd.SetArgs(s.args) + + panicChannel := make(chan any, 1) go func() { + defer func() { + if r := recover(); r != nil { + panicChannel <- r + } + }() errorChannel <- cmd.ExecuteContext(ctx) }() if err := s.applyFn(); err != nil { return fmt.Errorf("failed to apply openshift namespaces: %w", err) } - return <-errorChannel + + select { + case err := <-errorChannel: + return err + case perr := <-panicChannel: + panic(perr) + } } func mergeAndConvertToArgs(overrides *kubecontrolplanev1.KubeControllerManagerConfig) ([]string, error) { diff --git a/pkg/controllers/kube-scheduler.go b/pkg/controllers/kube-scheduler.go index 7c8934414ba..9412b53828c 100644 --- a/pkg/controllers/kube-scheduler.go +++ b/pkg/controllers/kube-scheduler.go @@ -96,9 +96,20 @@ func (s *KubeScheduler) Run(ctx context.Context, ready chan<- struct{}, stopped return err } + panicChannel := make(chan any, 1) go func() { + defer func() { + if r := recover(); r != nil { + panicChannel <- r + } + }() errorChannel <- kubescheduler.Run(ctx, cc, sched) }() - return <-errorChannel + select { + case err := <-errorChannel: + return err + case perr := <-panicChannel: + panic(perr) + } } diff --git a/pkg/controllers/kube-storage-version-migrator.go b/pkg/controllers/kube-storage-version-migrator.go index b5e177e5901..4010080cbcb 100644 --- a/pkg/controllers/kube-storage-version-migrator.go +++ b/pkg/controllers/kube-storage-version-migrator.go @@ -73,11 +73,22 @@ func (s *KubeStorageVersionMigrator) Run(ctx context.Context, ready chan<- struc close(ready) }() + panicChannel := make(chan any, 1) go func() { + defer func() { + if r := recover(); r != nil { + panicChannel <- r + } + }() errorChannel <- s.runMigrator(ctx) }() - return <-errorChannel + select { + case err := <-errorChannel: + return err + case perr := <-panicChannel: + panic(perr) + } } func (s *KubeStorageVersionMigrator) runMigrator(ctx context.Context) error { diff --git a/pkg/controllers/openshift-route-controller-manager.go b/pkg/controllers/openshift-route-controller-manager.go index 29791031d87..6ceba90fd4f 100644 --- a/pkg/controllers/openshift-route-controller-manager.go +++ b/pkg/controllers/openshift-route-controller-manager.go @@ -187,9 +187,20 @@ func (s *OCPRouteControllerManager) Run(ctx context.Context, ready chan<- struct close(ready) }() + panicChannel := make(chan any, 1) go func() { + defer func() { + if r := recover(); r != nil { + panicChannel <- r + } + }() errc <- s.run(ctx) }() - return <-errc + select { + case err := <-errc: + return err + case perr := <-panicChannel: + panic(perr) + } } diff --git a/pkg/node/kubelet.go b/pkg/node/kubelet.go index b04285a2fef..bf352528097 100644 --- a/pkg/node/kubelet.go +++ b/pkg/node/kubelet.go @@ -192,11 +192,22 @@ func (s *KubeletServer) Run(ctx context.Context, ready chan<- struct{}, stopped close(ready) }() + panicChannel := make(chan any, 1) go func() { + defer func() { + if r := recover(); r != nil { + panicChannel <- r + } + }() errc <- kubelet.Run(ctx, kubeletServer, kubeletDeps, utilfeature.DefaultFeatureGate) }() - return <-errc + select { + case err := <-errc: + return err + case perr := <-panicChannel: + panic(perr) + } } func loadConfigFile(name string) (*kubeletconfig.KubeletConfiguration, error) {