-
Notifications
You must be signed in to change notification settings - Fork 18
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #414 +/- ##
==========================================
- Coverage 60.62% 60.58% -0.04%
==========================================
Files 24 25 +1
Lines 2334 2489 +155
==========================================
+ Hits 1415 1508 +93
- Misses 835 895 +60
- Partials 84 86 +2
☔ View full report in Codecov by Sentry. |
// Catch is called with the results from Try(). New results can be returned | ||
// suppressing the original results. | ||
// | ||
// +optional | ||
Catch func(ctx context.Context, resource Type, result Result, err error) (Result, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After trying TryCatch
on for size mentally, I am wondering if an advice-style reconciler could be implemented with it. For example, could one update a single condition on a resource depending on whether a collection of steps was successful or not like so?
func ApplyResources(c reconcilers.Config) *reconcilers.SubReconciler {
return &TryCatch{
Try: reconcilers.Sequence{
ApplyRegistryCredentialsPlaceholder(c),
ApplyCerts(c),
ApplyRedis(c, images.Redis),
ApplyAuthServer(c, images.AuthServer),
ApplyTokenSignatureKeys(c),
},
Catch: func(ctx, parent *v1alpha1.AuthServer, result Result, err error) {
if err != nil {
parent.Status.MarkResourcesError(ctx, err.Error())
return result, nil
} else {
parent.Status.MarkResourcesApplied(ctx)
return result, nil
}
},
Config: c,
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. You'd probably want to do a little bit of detection on the err to figure out if it is something that should be suppressed or continued.
Reconcilers that direct the flow of a reconcile request at runtime. - IfThen - branch execution based on a boolean condition - While - iterate over a reconciler while a condition is true - TryCatch - recover from errors or rewrite the result - OverrideSetup - suppress calls to the SetupWithManager method Signed-off-by: Scott Andrews <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left a few questions and suggestions
README.md
Outdated
|
||
#### While | ||
|
||
A [`While`](https://pkg.go.dev/github.com/vmware-labs/reconciler-runtime/reconcilers#While) calls the reconciler so long as the condition is true, up to the maximum number of iterations (defaults to 100). The current iteration index can be retried with [`RetrieveIteration`](https://pkg.go.dev/github.com/vmware-labs/reconciler-runtime/reconcilers#RetrieveIteration). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[question, clarification] Iteration is done as a single resource's reconciliation, isn't it? And it's only iterating over the While
and not the entire pipeline of reconcilers?
} | ||
}, | ||
Catch: func(ctx context.Context, resource *buildv1alpha1.Function, result reconcile.Result, err error) (reconcile.Result, error) { | ||
// suppress error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// suppress error | |
// suppress error and/or | |
// log it and/or | |
// update the parent's status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this example, it's surprising the error. Logging or updating status are other things that could be done.
Co-authored-by: Max Brauer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! Looking forward to drying up state maintenance with TryCatch
Spike of reconcilers that direct the flow of a reconcile request at runtime.
IfThen
- branch execution based on a boolean conditionWhile
- iterate over a reconciler while a condition is trueTryCatch
- recover from errors or rewrite the resultOverrideSetup
- suppress calls to the SetupWithManager method