Skip to content

Commit b7f72db

Browse files
[hotfix] Fix the issue related to mounting the Logback configuration file.
1 parent b48ccce commit b7f72db

File tree

3 files changed

+40
-25
lines changed

3 files changed

+40
-25
lines changed

flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/decorators/FlinkConfMountDecorator.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@
5757
import java.util.Map;
5858
import java.util.stream.Collectors;
5959

60-
import static org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_LOG4J_NAME;
61-
import static org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_LOGBACK_NAME;
60+
import static org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_NAME_LIST;
6261
import static org.apache.flink.kubernetes.utils.Constants.CONFIG_MAP_PREFIX;
6362
import static org.apache.flink.kubernetes.utils.Constants.FLINK_CONF_VOLUME;
6463
import static org.apache.flink.util.Preconditions.checkNotNull;
@@ -179,15 +178,14 @@ String getFlinkConfData(List<String> confData) throws IOException {
179178

180179
private List<File> getLocalLogConfFiles() {
181180
final String confDir = kubernetesComponentConf.getConfigDirectory();
182-
final File logbackFile = new File(confDir, CONFIG_FILE_LOGBACK_NAME);
183-
final File log4jFile = new File(confDir, CONFIG_FILE_LOG4J_NAME);
184181

185182
List<File> localLogConfFiles = new ArrayList<>();
186-
if (logbackFile.exists()) {
187-
localLogConfFiles.add(logbackFile);
188-
}
189-
if (log4jFile.exists()) {
190-
localLogConfFiles.add(log4jFile);
183+
184+
for (String fileName : CONFIG_FILE_NAME_LIST) {
185+
final File file = new File(confDir, fileName);
186+
if (file.exists()) {
187+
localLogConfFiles.add(file);
188+
}
191189
}
192190

193191
return localLogConfFiles;

flink-kubernetes/src/main/java/org/apache/flink/kubernetes/utils/Constants.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
package org.apache.flink.kubernetes.utils;
2020

21+
import java.util.ArrayList;
22+
import java.util.Arrays;
23+
import java.util.List;
24+
2125
/** Constants for kubernetes. */
2226
public class Constants {
2327

@@ -30,6 +34,15 @@ public class Constants {
3034

3135
public static final String CONFIG_FILE_LOGBACK_NAME = "logback-console.xml";
3236
public static final String CONFIG_FILE_LOG4J_NAME = "log4j-console.properties";
37+
public static final List<String> CONFIG_FILE_NAME_LIST = Arrays.asList(
38+
"logback.xml",
39+
"log4j.properties",
40+
"logback-console.xml",
41+
"log4j-console.properties",
42+
"logback-session.xml",
43+
"log4j-session.properties",
44+
"log4j-cli.properties"
45+
);
3346
public static final String ENV_FLINK_LOG_DIR = "FLINK_LOG_DIR";
3447

3548
public static final String MAIN_CONTAINER_NAME = "flink-main-container";

flink-kubernetes/src/test/java/org/apache/flink/kubernetes/kubeclient/decorators/FlinkConfMountDecoratorTest.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.junit.jupiter.api.Test;
3939

4040
import java.io.IOException;
41+
import java.util.ArrayList;
4142
import java.util.Arrays;
4243
import java.util.Collections;
4344
import java.util.List;
@@ -47,6 +48,7 @@
4748
import static org.apache.flink.kubernetes.kubeclient.decorators.FlinkConfMountDecorator.getFlinkConfConfigMapName;
4849
import static org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_LOG4J_NAME;
4950
import static org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_LOGBACK_NAME;
51+
import static org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_NAME_LIST;
5052
import static org.assertj.core.api.Assertions.assertThat;
5153

5254
/** General tests for the {@link FlinkConfMountDecorator}. */
@@ -201,25 +203,27 @@ void testDecoratedFlinkPodWithLogback() throws IOException {
201203

202204
@Test
203205
void testDecoratedFlinkPodWithLog4jAndLogback() throws IOException {
204-
KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, CONFIG_FILE_LOG4J_NAME);
205-
KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, CONFIG_FILE_LOGBACK_NAME);
206+
207+
for (String fileName : CONFIG_FILE_NAME_LIST) {
208+
KubernetesTestUtils.createTemporyFile("some data", flinkConfDir, fileName);
209+
}
206210

207211
final FlinkPod resultFlinkPod = flinkConfMountDecorator.decorateFlinkPod(baseFlinkPod);
208212

209-
final List<KeyToPath> expectedKeyToPaths =
210-
Arrays.asList(
211-
new KeyToPathBuilder()
212-
.withKey(CONFIG_FILE_LOGBACK_NAME)
213-
.withPath(CONFIG_FILE_LOGBACK_NAME)
214-
.build(),
215-
new KeyToPathBuilder()
216-
.withKey(CONFIG_FILE_LOG4J_NAME)
217-
.withPath(CONFIG_FILE_LOG4J_NAME)
218-
.build(),
219-
new KeyToPathBuilder()
220-
.withKey(FLINK_CONF_FILENAME)
221-
.withPath(FLINK_CONF_FILENAME)
222-
.build());
213+
final List<KeyToPath> expectedKeyToPaths = new ArrayList<>();
214+
for (String fileName : CONFIG_FILE_NAME_LIST) {
215+
KeyToPath keyToPath = new KeyToPathBuilder()
216+
.withKey(fileName)
217+
.withPath(fileName)
218+
.build();
219+
expectedKeyToPaths.add(keyToPath);
220+
}
221+
expectedKeyToPaths.add(
222+
new KeyToPathBuilder()
223+
.withKey(FLINK_CONF_FILENAME)
224+
.withPath(FLINK_CONF_FILENAME)
225+
.build());
226+
223227
final List<Volume> expectedVolumes =
224228
Collections.singletonList(
225229
new VolumeBuilder()

0 commit comments

Comments
 (0)