1
1
package com .csviri .kubeapi ;
2
2
3
+ import org .apache .commons .io .FileUtils ;
3
4
import org .slf4j .Logger ;
4
5
import org .slf4j .LoggerFactory ;
5
6
@@ -31,7 +32,7 @@ public APIServer(APIServerConfig config) {
31
32
public void start () {
32
33
log .debug ("Stating. Using jenvtest dir: {}" , config .getJenvtestDirectory ());
33
34
prepareLogDirectory ();
34
- cleanPreviousState ();
35
+ cleanEtcdData ();
35
36
startEtcd ();
36
37
startApiServer ();
37
38
kubeConfigManager .updateKubeConfig ();
@@ -52,6 +53,7 @@ public void stop() {
52
53
stopApiServer ();
53
54
stopEtcd ();
54
55
kubeConfigManager .cleanupFromKubeConfig ();
56
+ cleanEtcdData ();
55
57
}
56
58
57
59
private void stopApiServer () {
@@ -61,8 +63,12 @@ private void stopApiServer() {
61
63
log .debug ("API Server stopped" );
62
64
}
63
65
64
- private void cleanPreviousState () {
65
- // todo
66
+ private void cleanEtcdData () {
67
+ try {
68
+ FileUtils .deleteDirectory (new File ("default.etcd" ));
69
+ } catch (IOException e ) {
70
+ throw new KubeApiException (e );
71
+ }
66
72
}
67
73
68
74
@@ -74,7 +80,7 @@ private void stopEtcd() {
74
80
}
75
81
76
82
private void waitUntilDefaultNamespaceCreated () {
77
-
83
+ // todo
78
84
}
79
85
80
86
// todo detect if process not started up correctly
@@ -108,19 +114,24 @@ private void startApiServer() {
108
114
}
109
115
var logsFile = new File (config .logDirectory (), "apiserver.logs" );
110
116
apiServerProcess = new ProcessBuilder (apiServerBinary .getAbsolutePath (),
111
- "--cert-dir" , config .getJenvtestDirectory (), "--etcd-servers" ,
112
- "http://0.0.0.0:2379" , "--authorization-mode" , "RBAC" , "--service-account-issuer" ,
113
- "https://localhost" , "--service-account-signing-key-file" , certManager .getAPIServerKeyPath (),
117
+ "--cert-dir" , config .getJenvtestDirectory (),
118
+ "--etcd-servers" , "http://0.0.0.0:2379" ,
119
+ "--authorization-mode" , "RBAC" ,
120
+ "--service-account-issuer" , "https://localhost" ,
121
+ "--service-account-signing-key-file" , certManager .getAPIServerKeyPath (),
114
122
"--service-account-signing-key-file" , certManager .getAPIServerKeyPath (),
115
- "--service-account-key-file" , certManager .getAPIServerKeyPath (), "--service-account-issuer" ,
116
- certManager .getAPIServerCertPath (),
117
- "--disable-admission-plugins" , "ServiceAccount" , "--client-ca-file" , certManager .getClientCertPath ()
118
- // "--service-cluster-ip-range", "10.0.0.0/24",
119
- // "--allow-privileged", "true"
123
+ "--service-account-key-file" , certManager .getAPIServerKeyPath (),
124
+ "--service-account-issuer" , certManager .getAPIServerCertPath (),
125
+ "--disable-admission-plugins" , "ServiceAccount" ,
126
+ "--client-ca-file" , certManager .getClientCertPath (),
127
+ "--service-cluster-ip-range" , "10.0.0.0/24" ,
128
+ "--allow-privileged"
120
129
)
121
130
.redirectOutput (logsFile )
122
131
.redirectError (logsFile )
123
132
.start ();
133
+ // todo detect premature termination
134
+ // apiServerProcess.onExit()
124
135
log .debug ("API Server started" );
125
136
} catch (IOException e ) {
126
137
throw new RuntimeException (e );
0 commit comments