Skip to content

Commit 22dd846

Browse files
committed
informer restart
Signed-off-by: Attila Mészáros <[email protected]>
1 parent ea6e6a3 commit 22dd846

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,16 @@ private boolean acceptedByDeleteFilters(R resource, boolean b) {
312312
public void setConfigurationService(ConfigurationService configurationService) {
313313
super.setConfigurationService(configurationService);
314314

315-
super.addIndexers(indexerBuffer);
315+
super.addIndexers(indexerBuffer); // todo check
316316
indexerBuffer = new HashMap<>();
317317
}
318318

319319
@Override
320320
public void addIndexers(Map<String, Function<R, List<String>>> indexers) {
321-
if (indexerBuffer == null) {
321+
if (isRunning()) {
322322
throw new OperatorException("Cannot add indexers after InformerEventSource started.");
323323
}
324-
indexerBuffer.putAll(indexers);
324+
indexerBuffer.putAll(indexers); // todo check
325325
}
326326

327327
/**

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package io.javaoperatorsdk.operator.processing.event.source.informer;
22

3-
import java.util.List;
4-
import java.util.Map;
5-
import java.util.Optional;
6-
import java.util.Set;
3+
import java.util.*;
74
import java.util.function.Function;
85
import java.util.function.Predicate;
96
import java.util.stream.Stream;
@@ -36,17 +33,21 @@ public abstract class ManagedInformerEventSource<R extends HasMetadata, P extend
3633
InformerWrappingEventSourceHealthIndicator<R>, Configurable<C> {
3734

3835
private static final Logger log = LoggerFactory.getLogger(ManagedInformerEventSource.class);
39-
private final InformerManager<R, C> cache;
36+
private InformerManager<R, C> cache;
37+
private boolean parseResourceVersions;
38+
private ConfigurationService configurationService;
39+
private C configuration;
40+
private Map<String, Function<R, List<String>>> indexers = new HashMap<>();
4041
protected TemporaryResourceCache<R> temporaryResourceCache;
4142
protected MixedOperation<R, KubernetesResourceList<R>, Resource<R>> client;
4243

4344
protected ManagedInformerEventSource(
4445
MixedOperation<R, KubernetesResourceList<R>, Resource<R>> client, C configuration,
4546
boolean parseResourceVersions) {
4647
super(configuration.getResourceClass());
48+
this.parseResourceVersions = parseResourceVersions;
4749
this.client = client;
48-
temporaryResourceCache = new TemporaryResourceCache<>(this, parseResourceVersions);
49-
this.cache = new InformerManager<>(client, configuration, this);
50+
this.configuration = configuration;
5051
}
5152

5253
@Override
@@ -77,6 +78,10 @@ public void changeNamespaces(Set<String> namespaces) {
7778

7879
@Override
7980
public void start() {
81+
temporaryResourceCache = new TemporaryResourceCache<>(this, parseResourceVersions);
82+
this.cache = new InformerManager<>(client, configuration, this);
83+
cache.setConfigurationService(configurationService);
84+
cache.addIndexers(indexers);
8085
manager().start();
8186
super.start();
8287
}
@@ -129,7 +134,7 @@ void setTemporalResourceCache(TemporaryResourceCache<R> temporaryResourceCache)
129134

130135
@Override
131136
public void addIndexers(Map<String, Function<R, List<String>>> indexers) {
132-
cache.addIndexers(indexers);
137+
this.indexers.putAll(indexers);
133138
}
134139

135140
@Override
@@ -175,6 +180,6 @@ public String toString() {
175180
}
176181

177182
public void setConfigurationService(ConfigurationService configurationService) {
178-
cache.setConfigurationService(configurationService);
183+
this.configurationService = configurationService;
179184
}
180185
}

Diff for: operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerResourceEventSourceTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ControllerResourceEventSourceTest extends
3737

3838
@BeforeEach
3939
public void setup() {
40-
setUpSource(new ControllerResourceEventSource<>(testController), false,
40+
setUpSource(new ControllerResourceEventSource<>(testController), true,
4141
new BaseConfigurationService());
4242
}
4343

Diff for: operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSourceTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ void setup() {
5555
when(informerConfiguration.getResourceClass()).thenReturn(Deployment.class);
5656

5757
informerEventSource = new InformerEventSource<>(informerConfiguration, clientMock);
58-
informerEventSource.setTemporalResourceCache(temporaryResourceCacheMock);
59-
informerEventSource.setEventHandler(eventHandlerMock);
60-
6158

59+
informerEventSource.setEventHandler(eventHandlerMock);
60+
informerEventSource.setConfigurationService(new BaseConfigurationService());
6261
SecondaryToPrimaryMapper secondaryToPrimaryMapper = mock(SecondaryToPrimaryMapper.class);
6362
when(informerConfiguration.getSecondaryToPrimaryMapper())
6463
.thenReturn(secondaryToPrimaryMapper);
6564
when(secondaryToPrimaryMapper.toPrimaryResourceIDs(any()))
6665
.thenReturn(Set.of(ResourceID.fromResource(testDeployment())));
66+
informerEventSource.start();
67+
informerEventSource.setTemporalResourceCache(temporaryResourceCacheMock);
6768
}
6869

6970
@Test

0 commit comments

Comments
 (0)