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

AdviceReconciler #502

Merged
merged 2 commits into from
May 28, 2024
Merged

Conversation

scothis
Copy link
Contributor

@scothis scothis commented Mar 27, 2024

A sketch of a potential method for defining advice for a SubReconciler as a SubReconciler. It can be composed manually into existing SubReconciler hierarchies. Other composition strategies could be explored in the future.

This does not address advice for ResourceReconciler, AggregateReconciler, or AdmissionWebhookAdapter.

Refs #500

@scothis scothis marked this pull request as draft March 27, 2024 16:21
@scothis
Copy link
Contributor Author

scothis commented Mar 27, 2024

cc @squeedee

Copy link

codecov bot commented Mar 27, 2024

Codecov Report

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

Project coverage is 60.46%. Comparing base (7e41cef) to head (ec7561c).

Files Patch % Lines
reconcilers/advice.go 72.72% 12 Missing ⚠️
reconcilers/aggregate.go 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #502      +/-   ##
==========================================
+ Coverage   59.73%   60.46%   +0.73%     
==========================================
  Files          31       32       +1     
  Lines        2779     2861      +82     
==========================================
+ Hits         1660     1730      +70     
- Misses       1027     1039      +12     
  Partials       92       92              

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

reconcilers/advice.go Outdated Show resolved Hide resolved
_ SubReconciler[client.Object] = (*NullReconciler[client.Object])(nil)
)

// NullReconciler does nothing
Copy link
Contributor

@mamachanko mamachanko Mar 28, 2024

Choose a reason for hiding this comment

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

[question]: Is this for testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not just for testing. Since the Reconciler field is required, but Around can choose not to invoke a reconciler it's an easy way to define something that implements the interface, but does nothing.

@scothis scothis mentioned this pull request Apr 4, 2024
@squeedee
Copy link
Collaborator

squeedee commented Apr 4, 2024

This is really great. I started at the Top level reconciler so it didn't occur to me that composable subreconcilers will work for everything else.. I guess a delegate with the same interface for the top level?

@yharish991
Copy link

@scothis I was trying AdviceReconciler and identified a small bug, line 312 in reconcilers/resource.go should be

r.AfterReconcile(ctx, req, result, nil)

@scothis
Copy link
Contributor Author

scothis commented Apr 18, 2024

@scothis I was trying AdviceReconciler and identified a small bug, line 312 in reconcilers/resource.go should be

r.AfterReconcile(ctx, req, result, nil)

@yharish991 good catch, I refactored a bit to make sure this can't happen in the future.

@squeedee
Copy link
Collaborator

@scothis @yharish991 has been using this directly. We're finding this quite useful so far. Do you plan on moving it from "sketch" status? Personally. I think it's a good approach and will serve users well.

@scothis scothis force-pushed the aspect-oriented-reconciler branch 2 times, most recently from 0317a8e to efa6d61 Compare May 27, 2024 18:41
@scothis scothis marked this pull request as ready for review May 27, 2024 18:42
@scothis
Copy link
Contributor Author

scothis commented May 27, 2024

Renamed AdviceReconciler to Advice

@scothis scothis requested a review from mamachanko May 27, 2024 19:05
Copy link
Contributor

@mamachanko mamachanko left a comment

Choose a reason for hiding this comment

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

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated
@@ -618,6 +647,10 @@ func SyncExternalState() *reconcilers.SubReconciler[*resources.MyResource] {
}
```

#### Null

[`Null`](https://pkg.go.dev/reconciler.io/runtime/reconcilers#Null) implements the SubReconciler interface, while performing no action. It can be used where a sub reconciler is required, but no behavior is necessary.
Copy link
Contributor

Choose a reason for hiding this comment

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

[question]: Is there a conceivable example like we've got for the others?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dropping null support for now. It's not essential to this PR.

scothis and others added 2 commits May 28, 2024 08:50
Add hooks to ResourceReconciler, AggregateReconciler and
AdmissionWebhookAdapter before and after the reconciler is called.

The Advice SubReconciler can wrap any other SubReconciler to provide
similar hooks.

Signed-off-by: Scott Andrews <[email protected]>
Co-authored-by: Max Brauer <[email protected]>
Signed-off-by: Scott Andrews <[email protected]>
@scothis scothis force-pushed the aspect-oriented-reconciler branch from 9ffef94 to ec7561c Compare May 28, 2024 12:51
@scothis scothis merged commit 597a9ed into reconcilerio:main May 28, 2024
4 checks passed
@scothis scothis deleted the aspect-oriented-reconciler branch May 28, 2024 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants