Skip to content

Commit 8f1dc62

Browse files
lburgazzolimetacosm
authored andcommitted
chore: refactor dependency management & settle on log4j2 as logging impl
1 parent d87999a commit 8f1dc62

File tree

9 files changed

+235
-142
lines changed

9 files changed

+235
-142
lines changed

operator-framework-core/pom.xml

+10-11
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,18 @@
1515
<description>Core framework for implementing Kubernetes operators</description>
1616
<packaging>jar</packaging>
1717

18-
<properties>
19-
<java.version>11</java.version>
20-
<maven.compiler.source>11</maven.compiler.source>
21-
<maven.compiler.target>11</maven.compiler.target>
22-
</properties>
23-
2418
<build>
2519
<plugins>
2620
<plugin>
2721
<groupId>org.apache.maven.plugins</groupId>
2822
<artifactId>maven-surefire-plugin</artifactId>
29-
<version>${surefire.version}</version>
23+
<version>${maven-surefire-plugin.version}</version>
3024
</plugin>
3125
<plugin>
3226
<!-- Used to generate the version / commit information -->
3327
<groupId>io.github.git-commit-id</groupId>
3428
<artifactId>git-commit-id-maven-plugin</artifactId>
35-
<version>5.0.0</version>
29+
<version>${git-commit-id-maven-plugin.version}</version>
3630
<executions>
3731
<execution>
3832
<id>get-the-git-infos</id>
@@ -82,15 +76,20 @@
8276
<artifactId>mockito-core</artifactId>
8377
<scope>test</scope>
8478
</dependency>
79+
<dependency>
80+
<groupId>org.assertj</groupId>
81+
<artifactId>assertj-core</artifactId>
82+
<scope>test</scope>
83+
</dependency>
84+
8585
<dependency>
8686
<groupId>org.apache.logging.log4j</groupId>
8787
<artifactId>log4j-slf4j-impl</artifactId>
8888
<scope>test</scope>
8989
</dependency>
9090
<dependency>
91-
<groupId>org.assertj</groupId>
92-
<artifactId>assertj-core</artifactId>
93-
<version>3.20.2</version>
91+
<groupId>org.apache.logging.log4j</groupId>
92+
<artifactId>log4j-core</artifactId>
9493
<scope>test</scope>
9594
</dependency>
9695
</dependencies>

operator-framework/pom.xml

+12-23
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,15 @@
1212
<artifactId>operator-framework</artifactId>
1313
<name>Operator SDK - Framework - Plain Java</name>
1414

15-
<properties>
16-
<maven.compiler.source>11</maven.compiler.source>
17-
<maven.compiler.target>11</maven.compiler.target>
18-
</properties>
19-
2015
<dependencies>
2116
<dependency>
2217
<groupId>io.javaoperatorsdk</groupId>
2318
<artifactId>operator-framework-core</artifactId>
24-
<version>${project.version}</version>
2519
</dependency>
20+
2621
<dependency>
2722
<groupId>org.apache.commons</groupId>
2823
<artifactId>commons-lang3</artifactId>
29-
<version>3.12.0</version>
3024
</dependency>
3125
<dependency>
3226
<groupId>org.slf4j</groupId>
@@ -35,14 +29,12 @@
3529
<dependency>
3630
<groupId>com.google.auto.service</groupId>
3731
<artifactId>auto-service</artifactId>
38-
<version>1.0</version>
3932
<scope>compile</scope>
4033
</dependency>
4134

4235
<dependency>
4336
<groupId>com.squareup</groupId>
4437
<artifactId>javapoet</artifactId>
45-
<version>1.13.0</version>
4638
<scope>compile</scope>
4739
</dependency>
4840
<dependency>
@@ -55,39 +47,36 @@
5547
<artifactId>junit-jupiter-engine</artifactId>
5648
<scope>test</scope>
5749
</dependency>
58-
<dependency>
59-
<groupId>ch.qos.logback</groupId>
60-
<artifactId>logback-classic</artifactId>
61-
<version>1.2.5</version>
62-
<scope>test</scope>
63-
</dependency>
6450
<dependency>
6551
<groupId>org.assertj</groupId>
6652
<artifactId>assertj-core</artifactId>
67-
<version>3.20.2</version>
6853
<scope>test</scope>
6954
</dependency>
7055
<dependency>
7156
<groupId>org.awaitility</groupId>
7257
<artifactId>awaitility</artifactId>
73-
<version>4.1.0</version>
7458
<scope>test</scope>
7559
</dependency>
7660
<dependency>
7761
<groupId>com.google.testing.compile</groupId>
7862
<artifactId>compile-testing</artifactId>
79-
<version>0.19</version>
8063
<scope>test</scope>
8164
</dependency>
8265
<dependency>
83-
<groupId>org.slf4j</groupId>
84-
<artifactId>slf4j-simple</artifactId>
85-
<version>${slf4j.version}</version>
66+
<groupId>io.fabric8</groupId>
67+
<artifactId>crd-generator-apt</artifactId>
8668
<scope>test</scope>
8769
</dependency>
8870
<dependency>
89-
<groupId>io.fabric8</groupId>
90-
<artifactId>crd-generator-apt</artifactId>
71+
<groupId>org.apache.logging.log4j</groupId>
72+
<artifactId>log4j-slf4j-impl</artifactId>
73+
<scope>test</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.apache.logging.log4j</groupId>
77+
<artifactId>log4j-core</artifactId>
78+
<version>${log4j.version}</version>
79+
<type>test-jar</type>
9180
<scope>test</scope>
9281
</dependency>
9382
</dependencies>

operator-framework/src/test/java/io/javaoperatorsdk/operator/config/runtime/DefaultConfigurationServiceTest.java

+44-25
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package io.javaoperatorsdk.operator.config.runtime;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
34
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
45
import static org.junit.jupiter.api.Assertions.assertEquals;
56
import static org.junit.jupiter.api.Assertions.assertFalse;
6-
import static org.junit.jupiter.api.Assertions.assertNull;
7-
import static org.junit.jupiter.api.Assertions.assertTrue;
87

9-
import ch.qos.logback.classic.Logger;
10-
import ch.qos.logback.classic.spi.ILoggingEvent;
11-
import ch.qos.logback.core.read.ListAppender;
128
import io.fabric8.kubernetes.client.CustomResource;
139
import io.fabric8.kubernetes.model.annotation.Group;
1410
import io.fabric8.kubernetes.model.annotation.Version;
@@ -18,35 +14,58 @@
1814
import io.javaoperatorsdk.operator.api.ResourceController;
1915
import io.javaoperatorsdk.operator.api.UpdateControl;
2016
import io.javaoperatorsdk.operator.api.config.AbstractConfigurationService;
17+
import org.apache.logging.log4j.Level;
18+
import org.apache.logging.log4j.core.LoggerContext;
19+
import org.apache.logging.log4j.core.config.AppenderRef;
20+
import org.apache.logging.log4j.core.config.LoggerConfig;
21+
import org.apache.logging.log4j.core.layout.PatternLayout;
22+
import org.apache.logging.log4j.test.appender.ListAppender;
2123
import org.junit.jupiter.api.Test;
22-
import org.slf4j.LoggerFactory;
2324

2425
public class DefaultConfigurationServiceTest {
2526

2627
public static final String CUSTOM_FINALIZER_NAME = "a.custom/finalizer";
2728

2829
@Test
2930
void attemptingToRetrieveAnUnknownControllerShouldLogWarning() {
30-
final var logger = (Logger) LoggerFactory.getLogger(AbstractConfigurationService.LOGGER_NAME);
31-
final var appender = new ListAppender<ILoggingEvent>();
32-
logger.addAppender(appender);
31+
final LoggerContext context = LoggerContext.getContext(false);
32+
final PatternLayout layout = PatternLayout.createDefaultLayout(context.getConfiguration());
33+
final ListAppender appender = new ListAppender("list", null, layout, false, false);
34+
3335
appender.start();
36+
37+
context.getConfiguration().addAppender(appender);
38+
39+
AppenderRef ref = AppenderRef.createAppenderRef("list", null, null);
40+
LoggerConfig loggerConfig =
41+
LoggerConfig.createLogger(
42+
false,
43+
Level.valueOf("info"),
44+
AbstractConfigurationService.LOGGER_NAME,
45+
"false",
46+
new AppenderRef[] {ref},
47+
null,
48+
context.getConfiguration(),
49+
null);
50+
loggerConfig.addAppender(appender, null, null);
51+
52+
context.getConfiguration().addLogger(AbstractConfigurationService.LOGGER_NAME, loggerConfig);
53+
context.updateLoggers();
54+
3455
try {
3556
final var config =
3657
DefaultConfigurationService.instance()
3758
.getConfigurationFor(new NotAutomaticallyCreated(), false);
38-
assertNull(config);
39-
assertEquals(1, appender.list.size());
40-
assertTrue(
41-
appender.list.stream()
42-
.allMatch(
43-
e -> {
44-
final var message = e.getFormattedMessage();
45-
return message.contains(NotAutomaticallyCreated.NAME)
46-
&& message.contains("not found");
47-
}));
59+
60+
assertThat(config).isNull();
61+
assertThat(appender.getMessages())
62+
.hasSize(1)
63+
.allMatch(m -> m.contains(NotAutomaticallyCreated.NAME) && m.contains("not found"));
4864
} finally {
49-
logger.detachAndStopAllAppenders();
65+
appender.stop();
66+
67+
context.getConfiguration().removeLogger(AbstractConfigurationService.LOGGER_NAME);
68+
context.updateLoggers();
5069
}
5170
}
5271

@@ -86,16 +105,16 @@ public void supportsInnerClassCustomResources() {
86105
static class TestCustomFinalizerController
87106
implements ResourceController<TestCustomFinalizerController.InnerCustomResource> {
88107

89-
@Group("test.crd")
90-
@Version("v1")
91-
public class InnerCustomResource extends CustomResource {
92-
}
93-
94108
@Override
95109
public UpdateControl<TestCustomFinalizerController.InnerCustomResource> createOrUpdateResource(
96110
InnerCustomResource resource, Context<InnerCustomResource> context) {
97111
return null;
98112
}
113+
114+
@Group("test.crd")
115+
@Version("v1")
116+
public class InnerCustomResource extends CustomResource {
117+
}
99118
}
100119

101120
@Controller(name = NotAutomaticallyCreated.NAME)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN">
3+
<Appenders>
4+
<Console name="Console" target="SYSTEM_OUT">
5+
<PatternLayout
6+
pattern="%style{%d}{yellow} %style{%threadId}{green} %style{%-30c{1.}}{cyan} %highlight{[%-5level] %msg%n%throwable}{INFO=black}"/>
7+
</Console>
8+
</Appenders>
9+
<Loggers>
10+
<Root level="debug">
11+
<AppenderRef ref="Console"/>
12+
</Root>
13+
</Loggers>
14+
</Configuration>

0 commit comments

Comments
 (0)