Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ public interface InformerWrappingEventSourceHealthIndicator<R extends HasMetadat

@Override
default Status getStatus() {
var nonUp =
informerHealthIndicators().values().stream()
.filter(i -> i.getStatus() != Status.HEALTHY)
.findAny();

return nonUp.isPresent() ? Status.UNHEALTHY : Status.HEALTHY;
var hasNonHealthy =
informerHealthIndicators().values().stream().anyMatch(i -> i.getStatus() != Status.HEALTHY);
return hasNonHealthy ? Status.UNHEALTHY : Status.HEALTHY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ public boolean isRunning() {
public Status getStatus() {
var status = isRunning() && hasSynced() && isWatching() ? Status.HEALTHY : Status.UNHEALTHY;
log.debug(
"Informer status: {} for for type: {}, namespace: {}, details[ is running: {}, has synced:"
+ " {}, is watching: {} ]",
"Informer status: {} for type: {}, namespace: {}, details [is running: {}, has synced: {},"
+ " is watching: {}]",
status,
informer.getApiTypeClass().getSimpleName(),
namespaceIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.slf4j.LoggerFactory;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.health.Status;
import io.javaoperatorsdk.operator.processing.event.Event;
import io.javaoperatorsdk.operator.processing.event.ResourceID;
import io.javaoperatorsdk.operator.processing.event.source.AbstractEventSource;
Expand Down Expand Up @@ -77,6 +78,11 @@ public void stop() {
}
}

@Override
public Status getStatus() {
return isRunning() ? Status.HEALTHY : Status.UNHEALTHY;
}

@Override
public Set<Void> getSecondaryResources(HasMetadata primary) {
return Set.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void propagatesEventOnNewResourceForPrimary() throws InterruptedException {
}

@Test
void updatesHealthIndicatorBasedOnExceptionsInFetcher() throws InterruptedException {
void updatesHealthIndicatorBasedOnExceptionsInFetcher() {
when(resourceFetcher.fetchResources()).thenReturn(testResponseWithOneValue());
pollingEventSource.start();
assertThat(pollingEventSource.getStatus()).isEqualTo(Status.HEALTHY);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.javaoperatorsdk.operator.processing.event.source.timer;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
Expand All @@ -12,6 +11,7 @@
import org.junit.jupiter.api.Test;

import io.javaoperatorsdk.operator.TestUtils;
import io.javaoperatorsdk.operator.health.Status;
import io.javaoperatorsdk.operator.processing.event.Event;
import io.javaoperatorsdk.operator.processing.event.EventHandler;
import io.javaoperatorsdk.operator.processing.event.ResourceID;
Expand Down Expand Up @@ -42,6 +42,7 @@ public void schedulesOnce() {

untilAsserted(() -> assertThat(eventHandler.events).hasSize(1));
untilAsserted(PERIOD * 2, 0, () -> assertThat(eventHandler.events).hasSize(1));
assertThat(source.getStatus()).isEqualTo(Status.HEALTHY);
}

@Test
Expand All @@ -52,6 +53,7 @@ public void canCancelOnce() {
source.cancelOnceSchedule(resourceID);

untilAsserted(() -> assertThat(eventHandler.events).isEmpty());
assertThat(source.getStatus()).isEqualTo(Status.HEALTHY);
}

@Test
Expand All @@ -62,6 +64,7 @@ public void canRescheduleOnceEvent() {
source.scheduleOnce(resourceID, 2 * PERIOD);

untilAsserted(PERIOD * 2, PERIOD, () -> assertThat(eventHandler.events).hasSize(1));
assertThat(source.getStatus()).isEqualTo(Status.HEALTHY);
}

@Test
Expand All @@ -72,23 +75,29 @@ public void deRegistersOnceEventSources() {
source.onResourceDeleted(customResource);

untilAsserted(() -> assertThat(eventHandler.events).isEmpty());
assertThat(source.getStatus()).isEqualTo(Status.HEALTHY);
}

@Test
public void eventNotRegisteredIfStopped() throws IOException {
public void eventNotRegisteredIfStopped() {
var resourceID = ResourceID.fromResource(TestUtils.testCustomResource());
assertThat(source.getStatus()).isEqualTo(Status.HEALTHY);

source.stop();
assertThatExceptionOfType(IllegalStateException.class)
.isThrownBy(() -> source.scheduleOnce(resourceID, PERIOD));
assertThat(source.getStatus()).isEqualTo(Status.UNHEALTHY);
}

@Test
public void eventNotFiredIfStopped() throws IOException {
public void eventNotFiredIfStopped() {
source.scheduleOnce(ResourceID.fromResource(TestUtils.testCustomResource()), PERIOD);
assertThat(source.getStatus()).isEqualTo(Status.HEALTHY);

source.stop();

untilAsserted(() -> assertThat(eventHandler.events).isEmpty());
assertThat(source.getStatus()).isEqualTo(Status.UNHEALTHY);
}

private void untilAsserted(ThrowingRunnable assertion) {
Expand Down