Skip to content

Commit

Permalink
Clear errors from async operations upon successful observation
Browse files Browse the repository at this point in the history
Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
  • Loading branch information
ulucinar committed Nov 8, 2023
1 parent 520fe96 commit 00618d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 10 additions & 1 deletion pkg/controller/external_async_nofork.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/crossplane/crossplane-runtime/pkg/logging"
"github.com/crossplane/crossplane-runtime/pkg/meta"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
xpresource "github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/pkg/errors"
Expand All @@ -17,6 +18,7 @@ import (
"github.com/crossplane/upjet/pkg/config"
"github.com/crossplane/upjet/pkg/controller/handler"
"github.com/crossplane/upjet/pkg/metrics"
"github.com/crossplane/upjet/pkg/resource"
"github.com/crossplane/upjet/pkg/terraform"
tferrors "github.com/crossplane/upjet/pkg/terraform/errors"
)
Expand Down Expand Up @@ -112,7 +114,14 @@ func (n *noForkAsyncExternal) Observe(ctx context.Context, mg xpresource.Managed
}
n.opTracker.LastOperation.Flush()

return n.noForkExternal.Observe(ctx, mg)
o, err := n.noForkExternal.Observe(ctx, mg)
// clear any previously reported LastAsyncOperation error condition here,
// because there are no pending updates on the existing resource and it's
// not scheduled to be deleted.
if err == nil && o.ResourceExists && o.ResourceUpToDate && !meta.WasDeleted(mg) {
mg.(resource.Terraformed).SetConditions(resource.LastAsyncOperationCondition(nil))
}
return o, err
}

func (n *noForkAsyncExternal) Create(_ context.Context, mg xpresource.Managed) (managed.ExternalCreation, error) {
Expand Down
1 change: 0 additions & 1 deletion pkg/pipeline/templates/controller.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func Setup(mgr ctrl.Manager, o tjcontroller.Options) error {
{{- else }}
managed.WithFinalizer(terraform.NewWorkspaceFinalizer(o.WorkspaceStore, xpresource.NewAPIFinalizer(mgr.GetClient(), managed.FinalizerName))),
{{- end }}

managed.WithTimeout(3*time.Minute),
managed.WithInitializers(initializers),
managed.WithConnectionPublishers(cps...),
Expand Down

0 comments on commit 00618d7

Please sign in to comment.