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

Commit

Permalink
feat: using temp etcd dirs (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
csviri authored Apr 4, 2023
1 parent 92a333a commit e3f2996
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void start() {
log.debug("Stating API Server. Using jenvtest dir: {}", config.getJenvtestDir());
binaryManager.initAndDownloadIfRequired();
certManager.createCertificatesIfNeeded();
etcdProcess.cleanEtcdData();
var etcdPort = etcdProcess.startEtcd();
var apiServerPort = kubeApiServerProcess.startApiServer(etcdPort);
if (config.isUpdateKubeConfig()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
Expand All @@ -22,6 +23,8 @@ public class EtcdProcess {
private volatile Process etcdProcess;
private volatile boolean stopped = false;
private final UnexpectedProcessStopHandler processStopHandler;
private File tempWalDir;
private File tempDataDir;

public EtcdProcess(BinaryManager binaryManager,
UnexpectedProcessStopHandler processStopHandler) {
Expand All @@ -30,15 +33,22 @@ public EtcdProcess(BinaryManager binaryManager,
}

public int startEtcd() {
var etcdBinary = binaryManager.binaries().getEtcd();
var port = Utils.findFreePort();
var peerPort = Utils.findFreePort();
try {
var etcdBinary = binaryManager.binaries().getEtcd();
tempWalDir = Files.createTempDirectory("etcdwal").toFile();
tempDataDir = Files.createTempDirectory("etcddata").toFile();
log.trace("Using temp wal dir: {} and temp data dir: {}", tempWalDir.getPath(),
tempDataDir.getPath());
var port = Utils.findFreePort();
var peerPort = Utils.findFreePort();

if (!etcdBinary.exists()) {
throw new JenvtestException(
"Missing binary for etcd on path: " + etcdBinary.getAbsolutePath());
}
etcdProcess = new ProcessBuilder(etcdBinary.getAbsolutePath(),
"-data-dir", tempDataDir.getPath(),
"-wal-dir", tempWalDir.getPath(),
"--listen-client-urls", "http://0.0.0.0:" + port,
"--advertise-client-urls", "http://0.0.0.0:" + port,
// the below added because of stability
Expand All @@ -65,7 +75,8 @@ public int startEtcd() {

public void cleanEtcdData() {
try {
FileUtils.deleteDirectory(new File("default.etcd"));
FileUtils.deleteDirectory(tempDataDir);
FileUtils.deleteDirectory(tempWalDir);
} catch (IOException e) {
throw new JenvtestException(e);
}
Expand Down

0 comments on commit e3f2996

Please sign in to comment.