Skip to content

feat: share InformerManager when configuration is equal #954

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

Closed
wants to merge 3 commits into from

Conversation

metacosm
Copy link
Collaborator

Fixes #942

@metacosm metacosm added dependent-resources-epic kind/feature Categorizes issue or PR as related to a new feature. labels Feb 17, 2022
@metacosm metacosm self-assigned this Feb 17, 2022
@metacosm metacosm requested a review from csviri February 17, 2022 13:21
@@ -141,4 +141,8 @@ public void put(ResourceID key, T resource) {
getSource(key.getNamespace().orElse(ANY_NAMESPACE_MAP_KEY))
.ifPresent(c -> c.put(key, resource));
}

int numberOfSources() {
return sources.size();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we just return an immutable map, this is not very useful outside of the tests.

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 indeed just for tests, which is why it's package-protected.

@@ -13,15 +18,31 @@
extends CachingEventSource<R, P>
implements ResourceEventHandler<R> {

@SuppressWarnings("rawtypes")
private static final ConcurrentMap<ResourceConfigurationAsKey, InformerManager> managedInformers =
Copy link
Collaborator

Choose a reason for hiding this comment

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

TBH, don't know what to think about this static context.
What is this magic number 17?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This will be started and stopped multiple times. Don't like the facts that it is even shared between the controllers. It will be started and stopped multiple times.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So it would deserve a Integration test with multiple controllers and multiple informers each.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, you're the one who wanted to share informers between sources… :)
We now avoid starting or stopping multiple times anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Pls add integration test for this, like when 2 reconcilers added with 2 Informers, so there is only one informer in the background.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And checking that everything is propoerly triggered after resource updated.

}

@Override
public void stop() {
super.stop();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure about the thread safety but probably ok this way

@csviri
Copy link
Collaborator

csviri commented Feb 17, 2022

BTW this is not exactly the same as sharing the Informer event source, we are just sharing the informer, so the events are still propagated twice in case two informers are created?!

@metacosm
Copy link
Collaborator Author

BTW this is not exactly the same as sharing the Informer event source, we are just sharing the informer, so the events are still propagated twice in case two informers are created?!

That's a good point but I'm actually unsure which behavior we would want.

protected ManagedInformerEventSource(
MixedOperation<R, KubernetesResourceList<R>, Resource<R>> client, C configuration) {
super(configuration.getResourceClass());
initCache(configuration);
manager().initSources(client, configuration, this);
Copy link
Collaborator

@csviri csviri Feb 17, 2022

Choose a reason for hiding this comment

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

Won't this multiple time init sources? for the manager?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ehh we need a quite good quality intergation tests here IMHO. This is quite risky to do this way.

@csviri
Copy link
Collaborator

csviri commented Feb 17, 2022

BTW this is not exactly the same as sharing the Informer event source, we are just sharing the informer, so the events are still propagated twice in case two informers are created?!

That's a good point but I'm actually unsure which behavior we would want.

Well with sharing the event source it's one event per event source ( and one informer as here). So we are sharing here the informer not the event source. Not sure that is a good thing, especially quite hard to reason about, well maybe we need to get used to it.

Basically we are sharing it because of the cache. From the point the event source is created the dependent resource only accesses the cache. There should be just one event that triggers the reconciliation from this point. If the primaryResourceMapper would be different for the same informer, that would be a different story.

@metacosm metacosm closed this Feb 17, 2022
@metacosm metacosm reopened this Feb 17, 2022
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 1 Security Hotspot
Code Smell A 22 Code Smells

35.5% 35.5% Coverage
0.6% 0.6% Duplication

@csviri
Copy link
Collaborator

csviri commented Feb 21, 2022

Was thinking more of this, actually the idea is very good, just maybe we should come up with a design how exactly do this. Also not sure again on what layer, probably needed for informers but also for event source layer.

@metacosm
Copy link
Collaborator Author

Was thinking more of this, actually the idea is very good, just maybe we should come up with a design how exactly do this. Also not sure again on what layer, probably needed for informers but also for event source layer.

Yes, this implementation doesn't feel complete and is problematic as shown by the failing tests… 😞

@metacosm metacosm marked this pull request as draft February 21, 2022 17:09
@csviri
Copy link
Collaborator

csviri commented Apr 7, 2022

@metacosm can we close this PR?
probably part of a bugger topic that we should discuss / design better, see : #1134 (point 3)

@metacosm metacosm closed this Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependent-resources-epic kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants