-
Notifications
You must be signed in to change notification settings - Fork 1
Generalize update handlers and add the ReadOnlyRepositoryWithFactory trait
#76
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
Open
s-vitaliy
wants to merge
14
commits into
main
Choose a base branch
from
add-memory-cache-for-validators
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e843641
Add the `ReadOnlyRepositoryWithFactory` trait
s-vitaliy 49d4188
Add ability to generalize update handlers
s-vitaliy f1c31fa
Add ability to generalize update handlers
s-vitaliy 527f861
Update src/services/backends/kubernetes/resource_update_handler/loggi…
s-vitaliy e478ddd
Update src/services/backends/memory.rs
s-vitaliy 1ae136c
Fix documentation
s-vitaliy 7598655
Merge remote-tracking branch 'origin/add-memory-cache-for-validators'…
s-vitaliy 92b783d
Update src/services/backends/kubernetes/resource_update_handler/compo…
s-vitaliy 9dc51f5
Update src/services/backends/kubernetes/resource_update_handler.rs
s-vitaliy c266fd0
A bit of renames
s-vitaliy 0e8d14a
Merge remote-tracking branch 'origin/add-memory-cache-for-validators'…
s-vitaliy e08b61d
Add unit tests
s-vitaliy 6acaa1f
Add more unit tests
s-vitaliy 454a518
Fix formatting issues
s-vitaliy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 1 addition & 9 deletions
10
src/services/backends/kubernetes/kubernetes_resource_watcher.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/services/backends/kubernetes/resource_update_handler.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| pub mod composed_update_handler; | ||
| pub mod logging_update_handler; | ||
|
|
||
| use async_trait::async_trait; | ||
| use kube::Resource; | ||
| use kube::runtime::watcher; | ||
|
|
||
| #[async_trait] | ||
| pub trait ResourceUpdateHandler<S>: Send + Sync | ||
| where | ||
| S: Resource + Send + Sync, | ||
| { | ||
| async fn handle_update(&self, result: &Result<S, watcher::Error>) -> (); | ||
| } | ||
31 changes: 31 additions & 0 deletions
31
src/services/backends/kubernetes/resource_update_handler/composed_update_handler.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| use crate::services::backends::kubernetes::resource_update_handler::ResourceUpdateHandler; | ||
| use async_trait::async_trait; | ||
| use kube::Resource; | ||
| use std::fmt::Debug; | ||
|
|
||
| pub struct ComposedUpdateHandler<T> { | ||
| handlers: Vec<Box<dyn ResourceUpdateHandler<T>>>, | ||
| } | ||
|
|
||
| impl<T> ComposedUpdateHandler<T> { | ||
| pub fn new() -> Self { | ||
| Self { handlers: Vec::new() } | ||
| } | ||
|
|
||
| pub fn add_handler(mut self, handler: Box<dyn ResourceUpdateHandler<T>>) -> Self { | ||
| self.handlers.push(handler); | ||
| self | ||
| } | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl<T> ResourceUpdateHandler<T> for ComposedUpdateHandler<T> | ||
| where | ||
| T: Resource + Debug + Send + Sync + 'static, | ||
| { | ||
| async fn handle_update(&self, result: &Result<T, kube::runtime::watcher::Error>) -> () { | ||
s-vitaliy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for handler in &self.handlers { | ||
| handler.handle_update(result).await; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.