Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle read failure after create failure #3219

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

danielrbradley
Copy link
Member

@danielrbradley danielrbradley commented Apr 17, 2024

If a read fails when trying to return a partial result, ensure we still return a partial result with the resource identifier so the operation can be completed using refresh at a later point.

Fixes #3200 - where the partial state failed to be written resulting in the resource being created but lost from state.

If a read fails when trying to return a partial result, ensure we still return a partial result with the resource identifier so the operation can be completed using refresh at a later point.
Copy link

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

Copy link

codecov bot commented Apr 17, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 55.28%. Comparing base (3ce1712) to head (33914c9).
Report is 3 commits behind head on master.

Files Patch % Lines
provider/pkg/provider/crud/crud.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3219      +/-   ##
==========================================
+ Coverage   55.25%   55.28%   +0.03%     
==========================================
  Files          66       66              
  Lines        9908     9917       +9     
==========================================
+ Hits         5475     5483       +8     
- Misses       4001     4002       +1     
  Partials      432      432              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@danielrbradley danielrbradley merged commit fabbaf4 into master Apr 18, 2024
24 checks passed
@danielrbradley danielrbradley deleted the handle-create-read-fail branch April 18, 2024 15:01
@@ -201,7 +201,8 @@ func (r *resourceCrudClient) HandleErrorWithCheckpoint(ctx context.Context, err
// Try reading its state by ID and return a partial error if succeeded.
checkpoint, getErr := r.currentResourceStateCheckpoint(ctx, id, inputs)
if getErr != nil {
return azure.AzureError(errors.Wrapf(err, "resource updated but read failed %s", getErr))
// If reading the state failed, combine the errors but still return the partial state.
err = azure.AzureError(errors.Wrapf(err, "resource created but read failed %s", getErr))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right to me... If getErr is not nil, then checkpoint is nil and that's what we return in the partialError. Are we going to save empty state? Will this work at all? Can you please describe how you tested this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, tested this locally and it works fine. Checkpoint being nil is fine - just means we have no inputs or outputs recorded. Most importantly, we have an ID recorded which lets us run refresh if the resource was actually created correctly - otherwise it'll just show up as an update on the next deployment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably, we could make this slightly better by still creating some kind of checkpoint object if the read fails - but perhaps missing just the final outputs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also get here from Update operation, right? (In which case I'm not sure that the change in the error message makes it better)
Writing an empty snapshot in this case looks even worse? What will Refresh behavior look like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants