Skip to content

Commit

Permalink
Pass context to panic handlers.
Browse files Browse the repository at this point in the history
Signed-off-by: Cem Mergenci <[email protected]>
  • Loading branch information
mergenci committed Dec 5, 2024
1 parent 7cb4d02 commit 2d7e0c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions pkg/controller/external_async_tfpluginfw.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ type panicHandler struct {
// run. The implementation follows the outline of panic recovery
// mechanism in controller-runtime:
// https://github.com/kubernetes-sigs/controller-runtime/blob/v0.17.3/pkg/internal/controller/controller.go#L105-L112
func (ph *panicHandler) recoverIfPanic() {
func (ph *panicHandler) recoverIfPanic(ctx context.Context) {
if r := recover(); r != nil {
for _, fn := range utilruntime.PanicHandlers {
fn(r)
fn(ctx, r)
}

ph.err = fmt.Errorf("recovered from panic: %v", r)
Expand Down Expand Up @@ -182,7 +182,7 @@ func (n *terraformPluginFrameworkAsyncExternalClient) Create(_ context.Context,
n.opTracker.logger.Info("Async create callback failed", "error", cErr.Error())
}
}()
defer ph.recoverIfPanic()
defer ph.recoverIfPanic(ctx)

n.opTracker.logger.Debug("Async create starting...")
_, ph.err = n.terraformPluginFrameworkExternalClient.Create(ctx, mg)
Expand Down Expand Up @@ -215,7 +215,7 @@ func (n *terraformPluginFrameworkAsyncExternalClient) Update(_ context.Context,
n.opTracker.logger.Info("Async update callback failed", "error", cErr.Error())
}
}()
defer ph.recoverIfPanic()
defer ph.recoverIfPanic(ctx)

n.opTracker.logger.Debug("Async update starting...")
_, ph.err = n.terraformPluginFrameworkExternalClient.Update(ctx, mg)
Expand Down Expand Up @@ -252,7 +252,7 @@ func (n *terraformPluginFrameworkAsyncExternalClient) Delete(_ context.Context,
n.opTracker.logger.Info("Async delete callback failed", "error", cErr.Error())
}
}()
defer ph.recoverIfPanic()
defer ph.recoverIfPanic(ctx)

n.opTracker.logger.Debug("Async delete starting...")
_, ph.err = n.terraformPluginFrameworkExternalClient.Delete(ctx, mg)
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/external_async_tfpluginsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (n *terraformPluginSDKAsyncExternal) Create(_ context.Context, mg xpresourc
n.opTracker.logger.Info("Async create callback failed", "error", cErr.Error())
}
}()
defer ph.recoverIfPanic()
defer ph.recoverIfPanic(ctx)

n.opTracker.logger.Debug("Async create starting...", "tfID", n.opTracker.GetTfID())
_, ph.err = n.terraformPluginSDKExternal.Create(ctx, mg)
Expand Down Expand Up @@ -193,7 +193,7 @@ func (n *terraformPluginSDKAsyncExternal) Update(_ context.Context, mg xpresourc
n.opTracker.logger.Info("Async update callback failed", "error", cErr.Error())
}
}()
defer ph.recoverIfPanic()
defer ph.recoverIfPanic(ctx)

n.opTracker.logger.Debug("Async update starting...", "tfID", n.opTracker.GetTfID())
_, ph.err = n.terraformPluginSDKExternal.Update(ctx, mg)
Expand Down Expand Up @@ -230,7 +230,7 @@ func (n *terraformPluginSDKAsyncExternal) Delete(_ context.Context, mg xpresourc
n.opTracker.logger.Info("Async delete callback failed", "error", cErr.Error())
}
}()
defer ph.recoverIfPanic()
defer ph.recoverIfPanic(ctx)

n.opTracker.logger.Debug("Async delete starting...", "tfID", n.opTracker.GetTfID())
_, ph.err = n.terraformPluginSDKExternal.Delete(ctx, mg)
Expand Down

0 comments on commit 2d7e0c8

Please sign in to comment.