-
Notifications
You must be signed in to change notification settings - Fork 220
feat: enable configuring a handler to listen to informers stopping #1493
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
Changes from 2 commits
447b885
9961885
41c0647
8aac329
f4be98d
c5cdd55
233b954
165ab93
0d1d38f
8310ca3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.javaoperatorsdk.operator.api.config; | ||
|
||
import io.fabric8.kubernetes.client.informers.SharedIndexInformer; | ||
|
||
public interface InformerStoppedHandler { | ||
|
||
@SuppressWarnings("rawtypes") | ||
void onStop(SharedIndexInformer informer, Throwable ex); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import io.fabric8.kubernetes.client.informers.cache.Cache; | ||
import io.javaoperatorsdk.operator.OperatorException; | ||
import io.javaoperatorsdk.operator.ReconcilerUtils; | ||
import io.javaoperatorsdk.operator.api.config.ConfigurationServiceProvider; | ||
import io.javaoperatorsdk.operator.processing.LifecycleAware; | ||
import io.javaoperatorsdk.operator.processing.event.ResourceID; | ||
import io.javaoperatorsdk.operator.processing.event.source.IndexerResourceCache; | ||
|
@@ -25,6 +26,18 @@ class InformerWrapper<T extends HasMetadata> | |
|
||
public InformerWrapper(SharedIndexInformer<T> informer) { | ||
this.informer = informer; | ||
|
||
// register | ||
ConfigurationServiceProvider.instance().getInformerStoppedHandler() | ||
.ifPresent(ish -> { | ||
final var stopped = informer.stopped(); | ||
if (stopped != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in which condition I would leave this check out to fail early if this erroneous situation appears. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. This happens during tests, though, where it would require quite a bit of setup just to mock the future… There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather prefer more setup in the tests as opposed to the risk of this to happen and be swallowed in a real operator. If you are really, really against doing it, I should, at least, ask for a loud warning when this situation occurs . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's now explicit so there's no way to silently fail anymore. |
||
stopped.handle((res, ex) -> { | ||
ish.onStop(informer, ex); | ||
return null; | ||
}); | ||
} | ||
}); | ||
this.cache = (Cache<T>) informer.getStore(); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
Would rather rename it to
InformerStopHandler
?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.
I think the current name is better because it reflects the fact that the handler is called after the informer is stopped.