Consolidate debug messages.
This commit is contained in:
parent
9a557f5019
commit
fe18bb3cdf
2 changed files with 13 additions and 13 deletions
|
|
@ -27,6 +27,7 @@ import io.kubernetes.client.util.generic.GenericKubernetesApi;
|
||||||
import io.kubernetes.client.util.generic.options.ListOptions;
|
import io.kubernetes.client.util.generic.options.ListOptions;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
@ -89,9 +90,10 @@ public class K8sObserver<O extends KubernetesObject,
|
||||||
thread = (Components.useVirtualThreads() ? Thread.ofVirtual()
|
thread = (Components.useVirtualThreads() ? Thread.ofVirtual()
|
||||||
: Thread.ofPlatform()).unstarted(() -> {
|
: Thread.ofPlatform()).unstarted(() -> {
|
||||||
try {
|
try {
|
||||||
logger
|
logger.fine(() -> "Observing " + context.getResourcePlural()
|
||||||
.config(() -> "Watching " + context.getResourcePlural()
|
|
||||||
+ " (" + context.getPreferredVersion() + ")"
|
+ " (" + context.getPreferredVersion() + ")"
|
||||||
|
+ Optional.ofNullable(options.getLabelSelector())
|
||||||
|
.map(ls -> " with labels " + ls).orElse("")
|
||||||
+ " in " + namespace);
|
+ " in " + namespace);
|
||||||
|
|
||||||
// Watch sometimes terminates without apparent reason.
|
// Watch sometimes terminates without apparent reason.
|
||||||
|
|
@ -102,7 +104,12 @@ public class K8sObserver<O extends KubernetesObject,
|
||||||
var changed
|
var changed
|
||||||
= api.watch(namespace, options).iterator();
|
= api.watch(namespace, options).iterator();
|
||||||
while (changed.hasNext()) {
|
while (changed.hasNext()) {
|
||||||
handler.accept(client, changed.next());
|
var response = changed.next();
|
||||||
|
logger.fine(() -> "Resource "
|
||||||
|
+ context.getKind() + "/"
|
||||||
|
+ response.object.getMetadata().getName()
|
||||||
|
+ " " + response.type);
|
||||||
|
handler.accept(client, response);
|
||||||
}
|
}
|
||||||
} catch (ApiException | RuntimeException e) {
|
} catch (ApiException | RuntimeException e) {
|
||||||
logger.log(Level.FINE, e, () -> "Problem watching"
|
logger.log(Level.FINE, e, () -> "Problem watching"
|
||||||
|
|
|
||||||
|
|
@ -199,8 +199,6 @@ public abstract class AbstractMonitor<O extends KubernetesObject,
|
||||||
assert client != null;
|
assert client != null;
|
||||||
assert context != null;
|
assert context != null;
|
||||||
assert namespace != null;
|
assert namespace != null;
|
||||||
logger.fine(() -> "Observing " + K8s.toString(context)
|
|
||||||
+ " objects in " + namespace);
|
|
||||||
|
|
||||||
// Monitor all versions
|
// Monitor all versions
|
||||||
for (var version : context.getVersions()) {
|
for (var version : context.getVersions()) {
|
||||||
|
|
@ -219,12 +217,7 @@ public abstract class AbstractMonitor<O extends KubernetesObject,
|
||||||
observerCounter.incrementAndGet();
|
observerCounter.incrementAndGet();
|
||||||
new K8sObserver<>(objectClass, objectListClass, client,
|
new K8sObserver<>(objectClass, objectListClass, client,
|
||||||
K8s.preferred(context, version), namespace, options)
|
K8s.preferred(context, version), namespace, options)
|
||||||
.handler((c, r) -> {
|
.handler(this::handleChange).onTerminated((o, t) -> {
|
||||||
logger.fine(() -> "Resource " + context.getKind()
|
|
||||||
+ "/" + r.object.getMetadata().getName() + " "
|
|
||||||
+ r.type);
|
|
||||||
handleChange(c, r);
|
|
||||||
}).onTerminated((o, t) -> {
|
|
||||||
if (observerCounter.decrementAndGet() == 0) {
|
if (observerCounter.decrementAndGet() == 0) {
|
||||||
unregisterAsGenerator();
|
unregisterAsGenerator();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue