Skip to content

feat: explicit event filters for all event sources #1294

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

Merged
merged 33 commits into from
Jul 4, 2022
Merged

Conversation

csviri
Copy link
Collaborator

@csviri csviri commented Jun 20, 2022

No description provided.

@csviri csviri marked this pull request as draft June 20, 2022 12:45
@csviri csviri linked an issue Jun 20, 2022 that may be closed by this pull request
@csviri csviri changed the title Event filters Explicit Event Filters for All Event Sources Jun 20, 2022
@csviri csviri self-assigned this Jun 21, 2022
@csviri csviri requested a review from metacosm June 22, 2022 06:54
@csviri csviri marked this pull request as ready for review June 22, 2022 06:54
@csviri csviri changed the title Explicit Event Filters for All Event Sources feat: explicit event filters for all event sources Jun 22, 2022
* trigger reconciliation - since if finalizer used there the event is an update that triggers the
* cleanup. If not used the resources are cleaned up by garbage collector.)
**/
Class<? extends Predicate<? extends HasMetadata>> onAddFilter() default VoidOnAddFilter.class;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should have our own interface for this so that it's easier to evolve it if needed and easier to track (i.e. easier to find the usages of our own class than a JDK class)…

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't have strong opinion on this. The only thing that is not nice on that is we need to implement our own operations for add and or. In addition to that this is not one interface, then it is three interfaces for every operation, because those have different parameters. And note that we are already passing all the input from the upstream api (informer, even source), so not sure if that API is somewhere to evolve.

Class<? extends ResourceEventFilter>[] eventFilters() default {};

/**
* Filter of onAdd events of resources. (Note that onDelete is missing, delete events don't
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment on onDelete shouldn't be here, imo, but in the docs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, kk, actually was thinking if this needs explicit docs, since it is quite straightforward, so javadoc might be enough. But had to put the delete part somewhere. Can remove it, and maybe just add an FAQ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed from here.

private boolean namespacesWereConfigured = false;

@SuppressWarnings("rawtypes")
protected Predicate onAddFilter;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not typesafe and can lead to hard to diagnose errors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, the thing is it comes from annotations in this case, can make paramtrized class, at the end itt will not help with that problem, since in the annotation eventually are no generics (KubernetesDependent). But at least on this layer might look better, true.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pushed.


public EventSource initEventSource(EventSourceContext<P> context) {
// some sub-classes (e.g. KubernetesDependentResource) can have their event source created
// before this method is called in the managed case, so only create the event source if it
// hasn't already been set
// hasn't already been set.
// The filters are applied automatically only if event source is created automatically.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why?

Copy link
Collaborator Author

@csviri csviri Jun 24, 2022

Choose a reason for hiding this comment

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

So if the event source is configured explicitly (think like sharing an event source between multiple dependent resources) it does not override the shared event source filters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will add this to the comment.

@@ -15,4 +22,18 @@ protected AbstractResourceEventSource(Class<R> resourceClass) {
public Class<R> resourceType() {
return resourceClass;
}

public void setOnAddFilter(Predicate<R> onAddFilter) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that the set methods should be exposed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is for every event source, so also the external resources ones, will check, maybe to hide here and make it visible there.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 4, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 61 Code Smells

66.4% 66.4% Coverage
0.4% 0.4% Duplication

@metacosm metacosm merged commit 7a6c6d4 into next Jul 4, 2022
@metacosm metacosm deleted the event-filters branch July 4, 2022 14:35
csviri added a commit that referenced this pull request Jul 4, 2022
Co-authored-by: Chris Laprun <metacosm@users.noreply.github.com>
csviri added a commit that referenced this pull request Jul 13, 2022
Co-authored-by: Chris Laprun <metacosm@users.noreply.github.com>
csviri added a commit that referenced this pull request Jul 13, 2022
Co-authored-by: Chris Laprun <metacosm@users.noreply.github.com>
csviri added a commit that referenced this pull request Jul 13, 2022
Co-authored-by: Chris Laprun <metacosm@users.noreply.github.com>
csviri added a commit that referenced this pull request Jul 14, 2022
Co-authored-by: Chris Laprun <metacosm@users.noreply.github.com>
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.

Explicit/Unified filters for All Event Sources
2 participants