From 2d7e0c821380367e0ef3b4e6e54597c56fa3721a Mon Sep 17 00:00:00 2001 From: Cem Mergenci Date: Thu, 5 Dec 2024 18:18:35 +0300 Subject: [PATCH] Pass context to panic handlers. Signed-off-by: Cem Mergenci --- pkg/controller/external_async_tfpluginfw.go | 10 +++++----- pkg/controller/external_async_tfpluginsdk.go | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/controller/external_async_tfpluginfw.go b/pkg/controller/external_async_tfpluginfw.go index 20a6e7f5..e2de21c1 100644 --- a/pkg/controller/external_async_tfpluginfw.go +++ b/pkg/controller/external_async_tfpluginfw.go @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/pkg/controller/external_async_tfpluginsdk.go b/pkg/controller/external_async_tfpluginsdk.go index 1542b87d..bf1f83fd 100644 --- a/pkg/controller/external_async_tfpluginsdk.go +++ b/pkg/controller/external_async_tfpluginsdk.go @@ -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) @@ -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) @@ -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)