-
Notifications
You must be signed in to change notification settings - Fork 8
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
Validate nested reconcilers #588
base: main
Are you sure you want to change the base?
Validate nested reconcilers #588
Conversation
* Nested validation is configured via the context with reconcilers#WithNestedValidation * (Sub)Reconciler tests always do nested validation * Moves the Validator interface from testing into reconcilers * Sequence now implements the Validator interface. Its Validate is not called from its SetupWithManager to avoid duplicate validations. fixes reconcilerio#583 Signed-off-by: Max Brauer <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #588 +/- ##
==========================================
+ Coverage 58.26% 59.39% +1.13%
==========================================
Files 33 34 +1
Lines 3800 3916 +116
==========================================
+ Hits 2214 2326 +112
- Misses 1492 1494 +2
- Partials 94 96 +2 ☔ View full report in Codecov by Sentry. |
@scothis I had experimented with validation handlers in the context. However, it did not convince me. It would only move the the call to I had also found myself wanting to test (Sub)ReconcilerTests to assert they are indeed validating reconcilers and not panicking. However, since we call Lastly, |
Propagating the error and letting the caller handle it is the right call. You get better error message that hint towards the location of the error in the reconciler hierarchy as well.
That's not worth it. If you want you can add tests that are excluded by default, but I think it's fine to leave it so long as you have tried a couple known failure cases and there are no regressions to existing tests.
It should be fairly trivial, right? I know |
@scothis 💯 I will tackle that in a follow-up PR. |
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.
Looks good.
We should have each exported Validate
method call init()
before the validation is checked. This will provide a default reconciler name, and let the reconciler be more like what it will run as. I should have added this when exporting the method initially.
reconcilers/validation.go
Outdated
|
||
type nestedValidationKey struct{} | ||
|
||
func WithNestedValidation(ctx context.Context) context.Context { |
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.
Use a stasher
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.
@scothis Great idea! However, I've moved validation into its own validation
package. To break a cyclic dependency on reconcilers
, I would have to move stash stuff into, say, stash
. That's ok I think. But before I plow on, I'd like you to acknowledge.
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.
Sounds good, so long as we alias back the types to not break anyone.
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.
Signed-off-by: Max Brauer <[email protected]>
Signed-off-by: Max Brauer <[email protected]>
* A few reconcilers have not had an init method yet. Now, they do. * Aggregate and Advice are defaulting fields on init. That means some their invalid cases are no longer possible. Signed-off-by: Max Brauer <[email protected]>
@scothis Every |
Nested validation is configured via the context with
reconcilers#WithNestedValidation
(Sub)Reconciler tests always do nested validation
Moves the Validator interface from testing into reconcilers
Sequence now implements the Validator interface. Its Validate is not
called from its SetupWithManager to avoid duplicate validations.
fixes #583
Signed-off-by: Max Brauer [email protected]