5
5
6
6
import java .io .File ;
7
7
import java .io .IOException ;
8
- import java .util .concurrent .TimeUnit ;
9
8
10
9
public class APIServer {
11
10
@@ -36,6 +35,7 @@ public void start() {
36
35
startEtcd ();
37
36
startApiServer ();
38
37
kubeConfigManager .updateKubeConfig ();
38
+ waitUntilDefaultNamespaceCreated ();
39
39
}
40
40
41
41
private void prepareLogDirectory () {
@@ -51,30 +51,7 @@ private void prepareLogDirectory() {
51
51
public void stop () {
52
52
stopApiServer ();
53
53
stopEtcd ();
54
- }
55
-
56
- private void startApiServer () {
57
- certManager .ensureAPIServerCertificates ();
58
- var apiServerBinary = binaryManager .binaries ().getApiServer ();
59
- try {
60
- if (!apiServerBinary .exists ()) {
61
- throw new KubeApiException ("Missing binary for API Server on path: " + apiServerBinary .getAbsolutePath ());
62
- }
63
- apiServerProcess = new ProcessBuilder (apiServerBinary .getAbsolutePath (),
64
- "--cert-dir" , config .getJenvtestDirectory (), "--etcd-servers" ,
65
- "http://0.0.0.0:2379" , "--authorization-mode" , "RBAC" , "--service-account-issuer" ,
66
- "https://localhost" , "--service-account-signing-key-file" , certManager .getAPIServerKeyPath (),
67
- "--service-account-signing-key-file" , certManager .getAPIServerKeyPath (),
68
- "--service-account-key-file" , certManager .getAPIServerKeyPath (), "--service-account-issuer" ,
69
- certManager .getAPIServerCertPath (),
70
- "--disable-admission-plugins" , "ServiceAccount" , "--client-ca-file" , certManager .getClientCertPath ())
71
- .redirectOutput (new File (config .logDirectory (), "apiserver.logs" ))
72
- .redirectError (new File (config .logDirectory (), "apiserver.logs" ))
73
- .start ();
74
- log .debug ("API Server started" );
75
- } catch (IOException e ) {
76
- throw new RuntimeException (e );
77
- }
54
+ kubeConfigManager .cleanupFromKubeConfig ();
78
55
}
79
56
80
57
private void stopApiServer () {
@@ -96,6 +73,11 @@ private void stopEtcd() {
96
73
log .debug ("etcd stopped" );
97
74
}
98
75
76
+ private void waitUntilDefaultNamespaceCreated () {
77
+
78
+ }
79
+
80
+ // todo detect if process not started up correctly
99
81
private void startEtcd () {
100
82
var etcdBinary = binaryManager .binaries ().getEtcd ();
101
83
try {
@@ -111,10 +93,37 @@ private void startEtcd() {
111
93
.redirectOutput (logsFile )
112
94
.redirectError (logsFile )
113
95
.start ();
114
- // etcdProcess.waitFor(5, TimeUnit.SECONDS);
115
96
log .debug ("etcd started" );
116
97
} catch (IOException e ) {
117
98
throw new KubeApiException (e );
118
99
}
119
100
}
101
+
102
+ private void startApiServer () {
103
+ certManager .ensureAPIServerCertificates ();
104
+ var apiServerBinary = binaryManager .binaries ().getApiServer ();
105
+ try {
106
+ if (!apiServerBinary .exists ()) {
107
+ throw new KubeApiException ("Missing binary for API Server on path: " + apiServerBinary .getAbsolutePath ());
108
+ }
109
+ var logsFile = new File (config .logDirectory (), "apiserver.logs" );
110
+ 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 (),
114
+ "--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"
120
+ )
121
+ .redirectOutput (logsFile )
122
+ .redirectError (logsFile )
123
+ .start ();
124
+ log .debug ("API Server started" );
125
+ } catch (IOException e ) {
126
+ throw new RuntimeException (e );
127
+ }
128
+ }
120
129
}
0 commit comments