Skip to content

Commit 9c42a92

Browse files
committed
pkg/start: Fill in deferred HandleCrash
Clayton wants these in each goroutine we launch [1]. Obviously there's no way to reach inside the informer Start()s and add it there. I'm also adding this to the FIXME comment for rerolling the auto-update worker goroutines; we'll get those straigtened out in future work. [1]: #424
1 parent dd09c3f commit 9c42a92

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

pkg/autoupdate/autoupdate.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ func New(
8585

8686
// Run runs the autoupdate controller.
8787
func (ctrl *Controller) Run(ctx context.Context, workers int) error {
88-
defer utilruntime.HandleCrash()
8988
defer ctrl.queue.ShutDown()
9089

9190
klog.Info("Starting AutoUpdateController")
@@ -96,7 +95,7 @@ func (ctrl *Controller) Run(ctx context.Context, workers int) error {
9695
}
9796

9897
for i := 0; i < workers; i++ {
99-
// FIXME: actually wait until these complete if the Context is canceled.
98+
// FIXME: actually wait until these complete if the Context is canceled. And possibly add utilruntime.HandleCrash.
10099
go wait.UntilWithContext(ctx, ctrl.worker, time.Second)
101100
}
102101

pkg/cvo/cvo.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ func loadConfigMapVerifierDataFromUpdate(update *payload.Update, clientBuilder s
291291

292292
// Run runs the cluster version operator until stopCh is completed. Workers is ignored for now.
293293
func (optr *Operator) Run(ctx context.Context, workers int) error {
294-
defer utilruntime.HandleCrash()
295294
defer optr.queue.ShutDown()
296295
stopCh := ctx.Done()
297296
workerStopCh := make(chan struct{})

pkg/start/start.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/google/uuid"
1717
v1 "k8s.io/api/core/v1"
1818
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1920
"k8s.io/client-go/informers"
2021
"k8s.io/client-go/kubernetes"
2122
"k8s.io/client-go/kubernetes/scheme"
@@ -184,6 +185,7 @@ func (o *Options) run(ctx context.Context, controllerCtx *Context, lock *resourc
184185
defer func() { signal.Stop(ch) }()
185186
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
186187
go func() {
188+
defer utilruntime.HandleCrash()
187189
sig := <-ch
188190
klog.Infof("Shutting down due to %s", sig)
189191
runCancel()
@@ -204,6 +206,7 @@ func (o *Options) run(ctx context.Context, controllerCtx *Context, lock *resourc
204206
}
205207
resultChannelCount++
206208
go func() {
209+
defer utilruntime.HandleCrash()
207210
err := cvo.RunMetrics(postMainContext, shutdownContext, o.ListenAddr, tlsConfig)
208211
resultChannel <- asyncResult{name: "metrics server", error: err}
209212
}()
@@ -218,6 +221,7 @@ func (o *Options) run(ctx context.Context, controllerCtx *Context, lock *resourc
218221

219222
resultChannelCount++
220223
go func() {
224+
defer utilruntime.HandleCrash()
221225
leaderelection.RunOrDie(postMainContext, leaderelection.LeaderElectionConfig{
222226
Lock: lock,
223227
ReleaseOnCancel: true,
@@ -228,13 +232,15 @@ func (o *Options) run(ctx context.Context, controllerCtx *Context, lock *resourc
228232
OnStartedLeading: func(_ context.Context) { // no need for this passed-through postMainContext, because goroutines we launch inside will use runContext
229233
resultChannelCount++
230234
go func() {
235+
defer utilruntime.HandleCrash()
231236
err := controllerCtx.CVO.Run(runContext, 2)
232237
resultChannel <- asyncResult{name: "main operator", error: err}
233238
}()
234239

235240
if controllerCtx.AutoUpdate != nil {
236241
resultChannelCount++
237242
go func() {
243+
defer utilruntime.HandleCrash()
238244
err := controllerCtx.AutoUpdate.Run(runContext, 2)
239245
resultChannel <- asyncResult{name: "auto-update controller", error: err}
240246
}()

0 commit comments

Comments
 (0)