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

feat: using temp etcd dirs #69

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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