Skip to content

Commit 3196b5e

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 2702919 commit 3196b5e

File tree

4 files changed

+49
-25
lines changed

4 files changed

+49
-25
lines changed

sample-operators/metrics-processing/src/main/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingReconciler1.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@
2626
import io.javaoperatorsdk.operator.processing.event.source.timer.TimerEventSource;
2727
import io.javaoperatorsdk.operator.sample.metrics.customresource.MetricsHandlingCustomResource1;
2828

29-
@ControllerConfiguration
29+
import static io.javaoperatorsdk.operator.sample.metrics.MetricsHandlingReconciler1.NAME;
30+
31+
@ControllerConfiguration(name = NAME)
3032
public class MetricsHandlingReconciler1
3133
extends AbstractMetricsHandlingReconciler<MetricsHandlingCustomResource1> {
3234

35+
public static final String NAME = "MetricsHandlingReconciler1";
36+
3337
private static final long TIMER_DELAY = 5000;
3438

3539
private final TimerEventSource<MetricsHandlingCustomResource1> timerEventSource;

sample-operators/metrics-processing/src/main/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingReconciler2.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
public class MetricsHandlingReconciler2
2323
extends AbstractMetricsHandlingReconciler<MetricsHandlingCustomResource2> {
2424

25+
public static final String NAME = "MetricsHandlingReconciler2";
26+
2527
public MetricsHandlingReconciler2() {
2628
super(150);
2729
}

sample-operators/metrics-processing/src/main/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingSampleOperator.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
import java.util.HashMap;
2424
import java.util.Map;
2525

26-
import io.javaoperatorsdk.operator.config.loader.ConfigProvider;
27-
import io.javaoperatorsdk.operator.config.loader.provider.EnvVarConfigProvider;
28-
import io.javaoperatorsdk.operator.config.loader.provider.YamlConfigProvider;
2926
import org.jspecify.annotations.NonNull;
3027
import org.jspecify.annotations.Nullable;
3128
import org.slf4j.Logger;
@@ -34,6 +31,11 @@
3431

3532
import io.javaoperatorsdk.operator.Operator;
3633
import io.javaoperatorsdk.operator.api.monitoring.Metrics;
34+
import io.javaoperatorsdk.operator.config.loader.ConfigLoader;
35+
import io.javaoperatorsdk.operator.config.loader.ConfigProvider;
36+
import io.javaoperatorsdk.operator.config.loader.provider.AggregatePriorityListConfigProvider;
37+
import io.javaoperatorsdk.operator.config.loader.provider.EnvVarConfigProvider;
38+
import io.javaoperatorsdk.operator.config.loader.provider.YamlConfigProvider;
3739
import io.javaoperatorsdk.operator.monitoring.micrometer.MicrometerMetricsV2;
3840
import io.micrometer.core.instrument.Clock;
3941
import io.micrometer.core.instrument.MeterRegistry;
@@ -70,12 +72,17 @@ public static void main(String[] args) {
7072
var configProviders = new ArrayList<ConfigProvider>();
7173
configProviders.add(new EnvVarConfigProvider());
7274
configProviders.add(new YamlConfigProvider(Path.of("/config/config.yaml")));
75+
var configLoader = new ConfigLoader(new AggregatePriorityListConfigProvider(configProviders));
7376

7477
Metrics metrics = initOTLPMetrics(isLocal());
7578
Operator operator =
76-
new Operator(o -> o.withStopOnInformerErrorDuringStartup(false).withMetrics(metrics));
77-
operator.register(new MetricsHandlingReconciler1());
78-
operator.register(new MetricsHandlingReconciler2());
79+
new Operator(o -> configLoader.applyConfigs().andThen(k -> k.withMetrics(metrics)));
80+
operator.register(
81+
new MetricsHandlingReconciler1(),
82+
configLoader.applyControllerConfigs(MetricsHandlingReconciler1.NAME));
83+
operator.register(
84+
new MetricsHandlingReconciler2(),
85+
configLoader.applyControllerConfigs(MetricsHandlingReconciler2.NAME));
7986
operator.start();
8087
}
8188

sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ class MetricsHandlingE2E {
7777
.withConfigurationService(
7878
c -> c.withMetrics(MetricsHandlingSampleOperator.initOTLPMetrics(true)))
7979
.build()
80-
: ClusterDeployedOperatorExtension.builder()
81-
.build();
80+
: ClusterDeployedOperatorExtension.builder().build();
8281

8382
@BeforeAll
8483
void setup() {
@@ -105,22 +104,28 @@ void cleanup() throws IOException {
105104

106105
private void helmInstall() {
107106
try {
108-
var chartPath = findProjectRoot("helm").toPath()
109-
.resolve("helm/generic-helm-chart").toString();
110-
var valuesUrl = MetricsHandlingE2E.class.getClassLoader()
111-
.getResource("helm-values.yaml");
107+
var chartPath =
108+
findProjectRoot("helm").toPath().resolve("helm/generic-helm-chart").toString();
109+
var valuesUrl = MetricsHandlingE2E.class.getClassLoader().getResource("helm-values.yaml");
112110
if (valuesUrl == null) {
113111
throw new IllegalStateException("helm-values.yaml not found on classpath");
114112
}
115113
var valuesPath = new File(valuesUrl.toURI()).getAbsolutePath();
116114
var namespace = operator.getNamespace();
117115

118116
log.info("Installing helm release '{}' into namespace '{}'", HELM_RELEASE_NAME, namespace);
119-
runCommand("helm", "install", HELM_RELEASE_NAME, chartPath,
120-
"-f", valuesPath,
121-
"--namespace", namespace,
117+
runCommand(
118+
"helm",
119+
"install",
120+
HELM_RELEASE_NAME,
121+
chartPath,
122+
"-f",
123+
valuesPath,
124+
"--namespace",
125+
namespace,
122126
"--wait",
123-
"--timeout", "2m");
127+
"--timeout",
128+
"2m");
124129
log.info("Helm release '{}' installed successfully", HELM_RELEASE_NAME);
125130
} catch (Exception e) {
126131
throw new RuntimeException("Failed to install helm chart", e);
@@ -131,10 +136,15 @@ private void helmUninstall() {
131136
try {
132137
var namespace = operator.getNamespace();
133138
log.info("Uninstalling helm release '{}' from namespace '{}'", HELM_RELEASE_NAME, namespace);
134-
runCommand("helm", "uninstall", HELM_RELEASE_NAME,
135-
"--namespace", namespace,
139+
runCommand(
140+
"helm",
141+
"uninstall",
142+
HELM_RELEASE_NAME,
143+
"--namespace",
144+
namespace,
136145
"--wait",
137-
"--timeout", "2m");
146+
"--timeout",
147+
"2m");
138148
log.info("Helm release '{}' uninstalled successfully", HELM_RELEASE_NAME);
139149
} catch (Exception e) {
140150
log.warn("Failed to uninstall helm release", e);
@@ -347,8 +357,11 @@ private String queryPrometheus(String prometheusUrl, String query) throws IOExce
347357

348358
private void installObservabilityServices() {
349359
try {
350-
File scriptFile = findProjectRoot("observability").toPath()
351-
.resolve("observability/install-observability.sh").toFile();
360+
File scriptFile =
361+
findProjectRoot("observability")
362+
.toPath()
363+
.resolve("observability/install-observability.sh")
364+
.toFile();
352365
log.info("Running observability setup script: {}", scriptFile.getAbsolutePath());
353366
runCommand("/bin/sh", scriptFile.getAbsolutePath());
354367
log.info("Observability stack is ready");
@@ -370,9 +383,7 @@ private static File findProjectRoot(String marker) throws IOException {
370383
}
371384

372385
private static void runCommand(String... command) throws IOException, InterruptedException {
373-
var process = new ProcessBuilder(command)
374-
.redirectErrorStream(true)
375-
.start();
386+
var process = new ProcessBuilder(command).redirectErrorStream(true).start();
376387
try (var reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
377388
String line;
378389
while ((line = reader.readLine()) != null) {

0 commit comments

Comments
 (0)