Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.

Commit e3f2996

Browse files
authored
feat: using temp etcd dirs (#69)
1 parent 92a333a commit e3f2996

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

core/src/main/java/io/javaoperatorsdk/jenvtest/KubeAPIServer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public void start() {
4141
log.debug("Stating API Server. Using jenvtest dir: {}", config.getJenvtestDir());
4242
binaryManager.initAndDownloadIfRequired();
4343
certManager.createCertificatesIfNeeded();
44-
etcdProcess.cleanEtcdData();
4544
var etcdPort = etcdProcess.startEtcd();
4645
var apiServerPort = kubeApiServerProcess.startApiServer(etcdPort);
4746
if (config.isUpdateKubeConfig()) {

core/src/main/java/io/javaoperatorsdk/jenvtest/process/EtcdProcess.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.nio.file.Files;
56

67
import org.apache.commons.io.FileUtils;
78
import org.slf4j.Logger;
@@ -22,6 +23,8 @@ public class EtcdProcess {
2223
private volatile Process etcdProcess;
2324
private volatile boolean stopped = false;
2425
private final UnexpectedProcessStopHandler processStopHandler;
26+
private File tempWalDir;
27+
private File tempDataDir;
2528

2629
public EtcdProcess(BinaryManager binaryManager,
2730
UnexpectedProcessStopHandler processStopHandler) {
@@ -30,15 +33,22 @@ public EtcdProcess(BinaryManager binaryManager,
3033
}
3134

3235
public int startEtcd() {
33-
var etcdBinary = binaryManager.binaries().getEtcd();
34-
var port = Utils.findFreePort();
35-
var peerPort = Utils.findFreePort();
3636
try {
37+
var etcdBinary = binaryManager.binaries().getEtcd();
38+
tempWalDir = Files.createTempDirectory("etcdwal").toFile();
39+
tempDataDir = Files.createTempDirectory("etcddata").toFile();
40+
log.trace("Using temp wal dir: {} and temp data dir: {}", tempWalDir.getPath(),
41+
tempDataDir.getPath());
42+
var port = Utils.findFreePort();
43+
var peerPort = Utils.findFreePort();
44+
3745
if (!etcdBinary.exists()) {
3846
throw new JenvtestException(
3947
"Missing binary for etcd on path: " + etcdBinary.getAbsolutePath());
4048
}
4149
etcdProcess = new ProcessBuilder(etcdBinary.getAbsolutePath(),
50+
"-data-dir", tempDataDir.getPath(),
51+
"-wal-dir", tempWalDir.getPath(),
4252
"--listen-client-urls", "http://0.0.0.0:" + port,
4353
"--advertise-client-urls", "http://0.0.0.0:" + port,
4454
// the below added because of stability
@@ -65,7 +75,8 @@ public int startEtcd() {
6575

6676
public void cleanEtcdData() {
6777
try {
68-
FileUtils.deleteDirectory(new File("default.etcd"));
78+
FileUtils.deleteDirectory(tempDataDir);
79+
FileUtils.deleteDirectory(tempWalDir);
6980
} catch (IOException e) {
7081
throw new JenvtestException(e);
7182
}

0 commit comments

Comments
 (0)