Skip to content

Commit

Permalink
Ensure consistent resource status if create errors (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrove-oss authored Dec 12, 2024
1 parent 8262f05 commit b0b0f5b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/controller/appwrapper/resource_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,18 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
}
// fall through. This is not actually an error. The object already exists and the correct appwrapper owns it.
} else {
// resource not actually created; patch status to reflect that
orig := copyForStatusPatch(aw)
meta.SetStatusCondition(&aw.Status.ComponentStatus[componentIdx].Conditions, metav1.Condition{
Type: string(workloadv1beta2.ResourcesDeployed),
Status: metav1.ConditionFalse,
Reason: "ComponentCreationErrored",
})
if patchErr := r.Status().Patch(ctx, aw, client.MergeFrom(orig)); patchErr != nil {
// ugh. Patch failed, so retry the create so we can get to a consistient state
return patchErr, false
}
// return actual error
return err, meta.IsNoMatchError(err) || apierrors.IsInvalid(err) // fatal
}
}
Expand Down

0 comments on commit b0b0f5b

Please sign in to comment.