Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

controller: set ongoing operation condition correctly #194

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/controller/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (e *external) Observe(ctx context.Context, mg xpresource.Managed) (managed.
}
switch {
case res.IsApplying, res.IsDestroying:
mg.SetConditions(resource.AsyncOperationOngoingCondition())
return managed.ExternalObservation{
ResourceExists: true,
ResourceUpToDate: true,
Expand All @@ -135,6 +136,10 @@ func (e *external) Observe(ctx context.Context, mg xpresource.Managed) (managed.
ResourceExists: false,
}, nil
}
// There might be a case where async operation is finished and the status
// update marking it as finished didn't go through. At this point, we are
// sure that there is no ongoing operation.
tr.SetConditions(resource.AsyncOperationFinishedCondition())

// No operation was in progress, our observation completed successfully, and
// we have an observation to consume.
Expand Down Expand Up @@ -189,7 +194,6 @@ func (e *external) Observe(ctx context.Context, mg xpresource.Managed) (managed.

func (e *external) Create(ctx context.Context, mg xpresource.Managed) (managed.ExternalCreation, error) {
if e.config.UseAsync {
mg.SetConditions(resource.AsyncOperationOngoingCondition())
return managed.ExternalCreation{}, errors.Wrap(e.workspace.ApplyAsync(e.callback.Apply(mg.GetName())), errStartAsyncApply)
}
tr, ok := mg.(resource.Terraformed)
Expand Down Expand Up @@ -217,7 +221,6 @@ func (e *external) Create(ctx context.Context, mg xpresource.Managed) (managed.E

func (e *external) Update(ctx context.Context, mg xpresource.Managed) (managed.ExternalUpdate, error) {
if e.config.UseAsync {
mg.SetConditions(resource.AsyncOperationOngoingCondition())
return managed.ExternalUpdate{}, errors.Wrap(e.workspace.ApplyAsync(e.callback.Apply(mg.GetName())), errStartAsyncApply)
}
tr, ok := mg.(resource.Terraformed)
Expand Down