Skip to content

Commit 1d56ed8

Browse files
csvirimetacosm
andauthored
fix: improvements on informer start and logging (operator-framework#1749)
* fix: improvements on informer start and logging * additional logging * exception handling fix * remove comment * refactor: avoid retrieving name several times --------- Co-authored-by: Chris Laprun <metacosm@gmail.com>
1 parent dc22768 commit 1d56ed8

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ExecutorServiceManager.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.slf4j.Logger;
1717
import org.slf4j.LoggerFactory;
1818

19+
import io.javaoperatorsdk.operator.OperatorException;
20+
1921
public class ExecutorServiceManager {
2022
private static final Logger log = LoggerFactory.getLogger(ExecutorServiceManager.class);
2123
private static ExecutorServiceManager instance;
@@ -82,7 +84,16 @@ public static <T> void executeAndWaitForAllToComplete(Stream<T> stream,
8284
// restore original name
8385
thread.setName(name);
8486
}
85-
}).collect(Collectors.toList()));
87+
}).collect(Collectors.toList())).forEach(f -> {
88+
try {
89+
// to find out any exceptions
90+
f.get();
91+
} catch (ExecutionException e) {
92+
throw new OperatorException(e.getCause());
93+
} catch (InterruptedException e) {
94+
Thread.currentThread().interrupt();
95+
}
96+
});
8697
shutdown(instrumented);
8798
} catch (InterruptedException e) {
8899
Thread.currentThread().interrupt();

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public synchronized void start(boolean startEventProcessor) throws OperatorExcep
335335
if (startEventProcessor) {
336336
eventProcessor.start();
337337
}
338-
log.info("'{}' controller started, pending event sources initialization", controllerName);
338+
log.info("'{}' controller started", controllerName);
339339
} catch (MissingCRDException e) {
340340
stop();
341341
throwMissingCRDException(e.getCrdName(), e.getSpecVersion(), controllerName);

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private static Function<NamedEventSource, String> getThreadNamer(String stage) {
8282
return es -> {
8383
final var name = es.name();
8484
return es.priority() + " " + stage + " -> "
85-
+ (es.isNameSet() ? name + " " + es.original().getClass().getSimpleName() : name);
85+
+ (es.isNameSet() ? name + " " + es.original().getClass() : es.original());
8686
};
8787
}
8888

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.javaoperatorsdk.operator.ReconcilerUtils;
2626
import io.javaoperatorsdk.operator.api.config.Cloner;
2727
import io.javaoperatorsdk.operator.api.config.ConfigurationServiceProvider;
28+
import io.javaoperatorsdk.operator.api.config.ExecutorServiceManager;
2829
import io.javaoperatorsdk.operator.api.config.ResourceConfiguration;
2930
import io.javaoperatorsdk.operator.health.InformerHealthIndicator;
3031
import io.javaoperatorsdk.operator.processing.LifecycleAware;
@@ -58,7 +59,13 @@ public InformerManager(MixedOperation<T, KubernetesResourceList<T>, Resource<T>>
5859
public void start() throws OperatorException {
5960
initSources();
6061
// make sure informers are all started before proceeding further
61-
sources.values().parallelStream().forEach(InformerWrapper::start);
62+
ExecutorServiceManager.executeAndWaitForAllToComplete(sources.values().stream(),
63+
iw -> {
64+
iw.start();
65+
return null;
66+
},
67+
iw -> "InformerStarter-" + iw.getTargetNamespace() + "-"
68+
+ configuration.getResourceClass().getSimpleName());
6269
}
6370

6471
private void initSources() {

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerWrapper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,19 @@ public void start() throws OperatorException {
7373
final var name = thread.getName();
7474
try {
7575
thread.setName(informerInfo() + " " + thread.getId());
76+
final var resourceName = informer.getApiTypeClass().getSimpleName();
77+
log.debug("Starting informer for namespace: {} resource: {}", namespaceIdentifier,
78+
resourceName);
7679
var start = informer.start();
7780
// note that in case we don't put here timeout and stopOnInformerErrorDuringStartup is
7881
// false, and there is a rbac issue the get never returns; therefore operator never really
7982
// starts
83+
log.trace("Waiting informer to start namespace: {} resource: {}", namespaceIdentifier,
84+
resourceName);
8085
start.toCompletableFuture().get(configService.cacheSyncTimeout().toMillis(),
8186
TimeUnit.MILLISECONDS);
87+
log.debug("Started informer for namespace: {} resource: {}", namespaceIdentifier,
88+
resourceName);
8289
} catch (TimeoutException | ExecutionException e) {
8390
if (configService.stopOnInformerErrorDuringStartup()) {
8491
log.error("Informer startup error. Operator will be stopped. Informer: {}", informer, e);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,11 @@ public ResourceConfiguration<R> getInformerConfiguration() {
163163
public C configuration() {
164164
return manager().configuration();
165165
}
166+
167+
@Override
168+
public String toString() {
169+
return getClass().getSimpleName() + "{" +
170+
"resourceClass: " + configuration.getResourceClass().getSimpleName() +
171+
"}";
172+
}
166173
}

0 commit comments

Comments
 (0)