5
5
import java .util .Set ;
6
6
import java .util .function .Function ;
7
7
8
+ import org .slf4j .Logger ;
9
+ import org .slf4j .LoggerFactory ;
10
+
8
11
import io .fabric8 .kubernetes .api .model .HasMetadata ;
9
12
import io .fabric8 .kubernetes .client .KubernetesClient ;
10
13
import io .fabric8 .kubernetes .client .informers .ResourceEventHandler ;
15
18
16
19
public class InformerEventSource <T extends HasMetadata > extends AbstractEventSource {
17
20
21
+ private static final Logger log = LoggerFactory .getLogger (InformerEventSource .class );
22
+
18
23
private final SharedInformer <T > sharedInformer ;
19
24
private final Function <T , Set <String >> resourceToUIDs ;
20
25
private final Function <HasMetadata , T > associatedWith ;
@@ -41,6 +46,11 @@ public InformerEventSource(SharedInformer<T> sharedInformer,
41
46
Function <T , Set <String >> resourceToUIDs ,
42
47
Function <HasMetadata , T > associatedWith ,
43
48
boolean skipUpdateEventPropagationIfNoChange ) {
49
+ if (sharedInformer .isRunning ()) {
50
+ log .warn (
51
+ "Informer is already running on event source creation, this is not desirable and may " +
52
+ "lead to non deterministic behavior." );
53
+ }
44
54
this .sharedInformer = sharedInformer ;
45
55
this .resourceToUIDs = resourceToUIDs ;
46
56
this .skipUpdateEventPropagationIfNoChange = skipUpdateEventPropagationIfNoChange ;
@@ -81,6 +91,7 @@ private void propagateEvent(InformerEvent.Action action, T object, T oldObject)
81
91
}
82
92
uids .forEach (uid -> {
83
93
InformerEvent event = new InformerEvent (uid , this , action , object , oldObject );
94
+ // In case user passes an already running informer this would fail.
84
95
if (this .eventHandler != null ) {
85
96
this .eventHandler .handleEvent (event );
86
97
}
0 commit comments