Skip to content

Commit

Permalink
logging improvements & refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Erhan Cagirici <erhan@upbound.io>
  • Loading branch information
erhancagirici committed Jan 13, 2024
1 parent 8d39c90 commit 2bfcb4f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
14 changes: 7 additions & 7 deletions pkg/controller/external_async_terraform_plugin_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ func (n *terraformPluginFrameworkAsyncExternalClient) Create(_ context.Context,
go func() {
defer cancel()

n.opTracker.logger.Debug("Async create starting...", "tfID", n.opTracker.GetFrameworkTFID())
n.opTracker.logger.Debug("Async create starting...")
_, err := n.terraformPluginFrameworkExternalClient.Create(ctx, mg)
err = tferrors.NewAsyncCreateFailed(err)
n.opTracker.LastOperation.SetError(err)
n.opTracker.logger.Debug("Async create ended.", "error", err, "tfID", n.opTracker.GetFrameworkTFID())
n.opTracker.logger.Debug("Async create ended.", "error", err)

n.opTracker.LastOperation.MarkEnd()
if cErr := n.callback.Create(mg.GetName())(err, ctx); cErr != nil {
Expand All @@ -158,11 +158,11 @@ func (n *terraformPluginFrameworkAsyncExternalClient) Update(_ context.Context,
go func() {
defer cancel()

n.opTracker.logger.Debug("Async update starting...", "tfID", n.opTracker.GetFrameworkTFID())
n.opTracker.logger.Debug("Async update starting...")
_, err := n.terraformPluginFrameworkExternalClient.Update(ctx, mg)
err = tferrors.NewAsyncUpdateFailed(err)
n.opTracker.LastOperation.SetError(err)
n.opTracker.logger.Debug("Async update ended.", "error", err, "tfID", n.opTracker.GetFrameworkTFID())
n.opTracker.logger.Debug("Async update ended.", "error", err)

n.opTracker.LastOperation.MarkEnd()
if cErr := n.callback.Update(mg.GetName())(err, ctx); cErr != nil {
Expand All @@ -176,7 +176,7 @@ func (n *terraformPluginFrameworkAsyncExternalClient) Update(_ context.Context,
func (n *terraformPluginFrameworkAsyncExternalClient) Delete(_ context.Context, mg xpresource.Managed) error {
switch {
case n.opTracker.LastOperation.Type == "delete":
n.opTracker.logger.Debug("The previous delete operation is still ongoing", "tfID", n.opTracker.GetFrameworkTFID())
n.opTracker.logger.Debug("The previous delete operation is still ongoing")
return nil
case !n.opTracker.LastOperation.MarkStart("delete"):
return errors.Errorf("%s operation that started at %s is still running", n.opTracker.LastOperation.Type, n.opTracker.LastOperation.StartTime().String())
Expand All @@ -186,10 +186,10 @@ func (n *terraformPluginFrameworkAsyncExternalClient) Delete(_ context.Context,
go func() {
defer cancel()

n.opTracker.logger.Debug("Async delete starting...", "tfID", n.opTracker.GetFrameworkTFID())
n.opTracker.logger.Debug("Async delete starting...")
err := tferrors.NewAsyncDeleteFailed(n.terraformPluginFrameworkExternalClient.Delete(ctx, mg))
n.opTracker.LastOperation.SetError(err)
n.opTracker.logger.Debug("Async delete ended.", "error", err, "tfID", n.opTracker.GetFrameworkTFID())
n.opTracker.logger.Debug("Async delete ended.", "error", err)

n.opTracker.LastOperation.MarkEnd()
if cErr := n.callback.Destroy(mg.GetName())(err, ctx); cErr != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/external_terraform_plugin_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ func (n *terraformPluginFrameworkExternalClient) Delete(ctx context.Context, _ x
if err != nil {
return errors.Wrap(err, "cannot unmarshal updated state")
}
n.opTracker.SetFrameworkTFState(applyResponse.NewState)
// mark the resource as logically deleted if the TF call clears the state
n.opTracker.SetDeleted(newStateAfterApplyVal.IsNull())

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/nofork_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (ops *OperationTrackerStore) Tracker(tr resource.Terraformed) *AsyncTracker
defer ops.mu.Unlock()
tracker, ok := ops.store[tr.GetUID()]
if !ok {
l := ops.logger.WithValues("trackerUID", tr.GetUID(), "resourceName", tr.GetName())
l := ops.logger.WithValues("trackerUID", tr.GetUID(), "resourceName", tr.GetName(), "gvk", tr.GetObjectKind().GroupVersionKind().String())
ops.store[tr.GetUID()] = NewAsyncTracker(WithAsyncTrackerLogger(l))
tracker = ops.store[tr.GetUID()]
}
Expand Down

0 comments on commit 2bfcb4f

Please sign in to comment.