Skip to content

Commit b0b0f5b

Browse files
authored
Ensure consistent resource status if create errors (#277)
1 parent 8262f05 commit b0b0f5b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

internal/controller/appwrapper/resource_management.go

+12
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,18 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
317317
}
318318
// fall through. This is not actually an error. The object already exists and the correct appwrapper owns it.
319319
} else {
320+
// resource not actually created; patch status to reflect that
321+
orig := copyForStatusPatch(aw)
322+
meta.SetStatusCondition(&aw.Status.ComponentStatus[componentIdx].Conditions, metav1.Condition{
323+
Type: string(workloadv1beta2.ResourcesDeployed),
324+
Status: metav1.ConditionFalse,
325+
Reason: "ComponentCreationErrored",
326+
})
327+
if patchErr := r.Status().Patch(ctx, aw, client.MergeFrom(orig)); patchErr != nil {
328+
// ugh. Patch failed, so retry the create so we can get to a consistient state
329+
return patchErr, false
330+
}
331+
// return actual error
320332
return err, meta.IsNoMatchError(err) || apierrors.IsInvalid(err) // fatal
321333
}
322334
}

0 commit comments

Comments
 (0)