Skip to content

Commit

Permalink
Fix sample stopping after 1 minute.
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
  • Loading branch information
csviri committed Jan 31, 2025
1 parent 3a87c96 commit 5c8845a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions samples/spring-boot-auto-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<groupId>io.javaoperatorsdk</groupId>
<artifactId>operator-framework-spring-boot-starter</artifactId>
</dependency>
<!-- without this, the app exits after 1 minute -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.javaoperatorsdk</groupId>
<artifactId>operator-framework-spring-boot-starter-samples-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.javaoperatorsdk.operator.springboot.starter.sample;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;

Expand All @@ -20,6 +20,6 @@
public class SpringBootStarterSampleApplication {

public static void main(String[] args) {
SpringApplication.run(SpringBootStarterSampleApplication.class, args);
new SpringApplicationBuilder(SpringBootStarterSampleApplication.class).run(args);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.javaoperatorsdk.operator.springboot.starter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.stereotype.Component;
Expand All @@ -12,6 +14,8 @@ public class OperatorHealthIndicator extends AbstractHealthIndicator {

private final Operator operator;

private final static Logger log = LoggerFactory.getLogger(OperatorHealthIndicator.class);

public OperatorHealthIndicator(final Operator operator) {
super("OperatorSDK health check failed");
Assert.notNull(operator, "OperatorSDK Operator not initialized");
Expand All @@ -21,6 +25,7 @@ public OperatorHealthIndicator(final Operator operator) {
@Override
protected void doHealthCheck(Health.Builder builder) {
final var runtimeInfo = operator.getRuntimeInfo();
log.debug("Executing health check for {}", runtimeInfo);
if (runtimeInfo.isStarted()) {
final boolean[] healthy = {true};
runtimeInfo.getRegisteredControllers().forEach(rc -> {
Expand All @@ -33,12 +38,14 @@ protected void doHealthCheck(Health.Builder builder) {
builder.withDetail(name, "unhealthy: " + String.join(", ", unhealthy.keySet()));
}
});
log.debug("Healthy: {}", healthy[0]);
if (healthy[0]) {
builder.up();
} else {
builder.down();
}
} else {
log.debug("Healthy: unknown");
builder.unknown();
}
}
Expand Down

0 comments on commit 5c8845a

Please sign in to comment.