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

Commit 15db5f0

Browse files
committed
wip
1 parent 9ef9f59 commit 15db5f0

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

src/main/java/com/csviri/kubeapi/APIServer.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class APIServer {
1919
private final KubeConfigManager kubeConfigManager;
2020
private Process etcdProcess;
2121
private volatile Process apiServerProcess;
22+
private volatile boolean stopped = false;
2223

2324
public APIServer() {
2425
this(new APIServerConfig());
@@ -42,6 +43,15 @@ public void start() {
4243
log.info("API Server ready to use");
4344
}
4445

46+
public void stop() {
47+
stopped = true;
48+
stopApiServer();
49+
stopEtcd();
50+
kubeConfigManager.cleanupFromKubeConfig();
51+
cleanEtcdData();
52+
log.debug("Fully stopped.");
53+
}
54+
4555
private void prepareLogDirectory() {
4656
var logDir = new File(config.logDirectory());
4757
if (!logDir.exists()) {
@@ -52,13 +62,6 @@ private void prepareLogDirectory() {
5262
}
5363
}
5464

55-
public void stop() {
56-
stopApiServer();
57-
stopEtcd();
58-
kubeConfigManager.cleanupFromKubeConfig();
59-
cleanEtcdData();
60-
log.debug("Fully stopped.");
61-
}
6265

6366
private void stopApiServer() {
6467
if (apiServerProcess != null) {
@@ -127,6 +130,12 @@ private void startEtcd() {
127130
.redirectOutput(logsFile)
128131
.redirectError(logsFile)
129132
.start();
133+
etcdProcess.onExit().thenApply(p-> {
134+
if (!stopped) {
135+
throw new KubeApiException("Etcd stopped unexpectedly");
136+
}
137+
return null;
138+
});
130139
log.debug("etcd started");
131140
} catch (IOException e) {
132141
throw new KubeApiException(e);
@@ -140,7 +149,7 @@ private void startApiServer() {
140149
if (!apiServerBinary.exists()) {
141150
throw new KubeApiException("Missing binary for API Server on path: " + apiServerBinary.getAbsolutePath());
142151
}
143-
var logsFile = new File(config.logDirectory(), "apiserver.logs");
152+
144153
apiServerProcess = new ProcessBuilder(apiServerBinary.getAbsolutePath(),
145154
"--cert-dir", config.getJenvtestDirectory(),
146155
"--etcd-servers", "http://0.0.0.0:2379",
@@ -156,6 +165,12 @@ private void startApiServer() {
156165
"--allow-privileged"
157166
)
158167
.start();
168+
apiServerProcess.onExit().thenApply(p-> {
169+
if (!stopped) {
170+
throw new KubeApiException("APIServer stopped unexpectedly.");
171+
}
172+
return null;
173+
});
159174
log.debug("API Server started");
160175
} catch (IOException e) {
161176
throw new RuntimeException(e);

src/main/java/com/csviri/kubeapi/BinaryManager.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class BinaryManager {
66
public static final String DEFAULT_VERSION_1_26_1 = "v1.26.1";
77
public static final String ETCD_BINARY_NAME = "etcd";
88
public static final String API_SERVER_BINARY_NAME = "kube-apiserver";
9+
public static final String KUBECTL_BINARY_NAME = "kubectl";
910

1011
// todo configurable
1112
//https://dl.k8s.io/v1.26.1/bin/linux/amd64/kube-apiserver
@@ -17,22 +18,27 @@ public BinaryManager(String jenvtestDir) {
1718
this.jenvtestDir = jenvtestDir;
1819
}
1920

20-
public ApiBinaries downloadBinaries() {
21+
public ApiBinaries downloadBinariesIfNotPresent() {
22+
23+
2124
return null;
2225
}
2326

2427
public ApiBinaries binaries() {
2528
return new ApiBinaries(new File(jenvtestDir, ETCD_BINARY_NAME),
26-
new File(jenvtestDir, API_SERVER_BINARY_NAME));
29+
new File(jenvtestDir, API_SERVER_BINARY_NAME),
30+
new File(jenvtestDir, KUBECTL_BINARY_NAME));
2731
}
2832

2933
public static class ApiBinaries {
3034
private final File etcd;
3135
private final File apiServer;
36+
private final File kubectl;
3237

33-
public ApiBinaries(File etcd, File apiServer) {
38+
public ApiBinaries(File etcd, File apiServer, File kubectl) {
3439
this.etcd = etcd;
3540
this.apiServer = apiServer;
41+
this.kubectl = kubectl;
3642
}
3743

3844
public File getEtcd() {
@@ -42,5 +48,9 @@ public File getEtcd() {
4248
public File getApiServer() {
4349
return apiServer;
4450
}
51+
52+
public File getKubectl() {
53+
return kubectl;
54+
}
4555
}
4656
}

src/main/java/com/csviri/kubeapi/CertManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ private void generateUserCertificates() throws IOException, InterruptedException
6666
public String getClientCertPath() {
6767
return new File(jenvtestDir, CLIENT_CERT_NAME).getAbsolutePath();
6868
}
69+
6970
public String getClientKeyPath() {
7071
return new File(jenvtestDir, CLIENT_KEY_NAME).getAbsolutePath();
7172
}

0 commit comments

Comments
 (0)