-
Notifications
You must be signed in to change notification settings - Fork 5
feat: able to specify api server flags #46
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package io.javaoperatorsdk.jenvtest; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public final class KubeAPIServerConfigBuilder { | ||
|
||
|
@@ -13,6 +15,7 @@ public final class KubeAPIServerConfigBuilder { | |
private String jenvtestDir; | ||
private String apiServerVersion; | ||
private Boolean offlineMode; | ||
private final List<String> apiServerFlags = new ArrayList<>(0); | ||
|
||
public KubeAPIServerConfigBuilder() {} | ||
|
||
|
@@ -58,6 +61,28 @@ public KubeAPIServerConfig build() { | |
this.apiServerVersion = apiServerVersionEnvVar; | ||
} | ||
} | ||
return new KubeAPIServerConfig(jenvtestDir, apiServerVersion, offlineMode); | ||
return new KubeAPIServerConfig(jenvtestDir, apiServerVersion, offlineMode, apiServerFlags); | ||
} | ||
|
||
public void withApiServerFlags(List<String> flags) { | ||
apiServerFlags.addAll(flags); | ||
} | ||
|
||
public void withApiServerFlag(String key, String value) { | ||
checkKeyPrefix(key); | ||
apiServerFlags.add(key); | ||
apiServerFlags.add(value); | ||
} | ||
|
||
public void withApiServerFlag(String key) { | ||
checkKeyPrefix(key); | ||
apiServerFlags.add(key); | ||
} | ||
|
||
private void checkKeyPrefix(String key) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it'd be better to issue a warning and add the prefix automatically if it's missing to be more user-friendly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually yes, was thinking to ask for the flag without the flag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's a problem with the list of flags. I will merge this simple form, and we can do impovements in a subsequent PR. |
||
if (!key.startsWith("--")) { | ||
throw new JenvtestException( | ||
"Kube API Server flag needs to start with double dash: '--'; Instead found key: " + key); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ | |
*/ | ||
String kubeAPIVersion() default NOT_SET; | ||
|
||
String[] apiServerFlags() default {}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package io.javaoperatorsdk.jenvtest.process; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
|
@@ -39,21 +42,9 @@ public int startApiServer(int etcdPort) { | |
throw new JenvtestException( | ||
"Missing binary for API Server on path: " + apiServerBinary.getAbsolutePath()); | ||
} | ||
var port = Utils.findFreePort(); | ||
apiServerProcess = new ProcessBuilder(apiServerBinary.getAbsolutePath(), | ||
"--cert-dir", config.getJenvtestDir(), | ||
"--secure-port", "" + port, | ||
"--etcd-servers", "http://0.0.0.0:" + etcdPort, | ||
"--authorization-mode", "RBAC", | ||
"--service-account-issuer", "https://localhost", | ||
"--service-account-signing-key-file", certManager.getAPIServerKeyPath(), | ||
"--service-account-signing-key-file", certManager.getAPIServerKeyPath(), | ||
"--service-account-key-file", certManager.getAPIServerKeyPath(), | ||
"--service-account-issuer", certManager.getAPIServerCertPath(), | ||
"--disable-admission-plugins", "ServiceAccount", | ||
"--client-ca-file", certManager.getClientCertPath(), | ||
"--service-cluster-ip-range", "10.0.0.0/24", | ||
"--allow-privileged") | ||
var apiServerPort = Utils.findFreePort(); | ||
var command = createCommand(apiServerBinary, apiServerPort, etcdPort); | ||
apiServerProcess = new ProcessBuilder(command) | ||
.start(); | ||
Utils.redirectProcessOutputToLogger(apiServerProcess.getInputStream(), apiLog); | ||
Utils.redirectProcessOutputToLogger(apiServerProcess.getErrorStream(), apiLog); | ||
|
@@ -66,12 +57,32 @@ public int startApiServer(int etcdPort) { | |
return null; | ||
}); | ||
log.debug("API Server started"); | ||
return port; | ||
return apiServerPort; | ||
} catch (IOException e) { | ||
throw new JenvtestException(e); | ||
} | ||
} | ||
|
||
private List<String> createCommand(File apiServerBinary, int apiServerPort, int etcdPort) { | ||
var command = new ArrayList<String>(); | ||
command.add(apiServerBinary.getAbsolutePath()); | ||
command.addAll(config.getApiServerFlags()); | ||
command.addAll(List.of("--cert-dir", config.getJenvtestDir(), | ||
"--secure-port", "" + apiServerPort, | ||
"--etcd-servers", "http://0.0.0.0:" + etcdPort, | ||
"--authorization-mode", "RBAC", | ||
"--service-account-issuer", "https://localhost", | ||
"--service-account-signing-key-file", certManager.getAPIServerKeyPath(), | ||
"--service-account-signing-key-file", certManager.getAPIServerKeyPath(), | ||
"--service-account-key-file", certManager.getAPIServerKeyPath(), | ||
"--service-account-issuer", certManager.getAPIServerCertPath(), | ||
"--disable-admission-plugins", "ServiceAccount", | ||
"--client-ca-file", certManager.getClientCertPath(), | ||
"--service-cluster-ip-range", "10.0.0.0/24", | ||
"--allow-privileged")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would one capture such a parameter if you're supposed to pass pairs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is also api for that. in the builder |
||
return command; | ||
} | ||
|
||
public void waitUntilDefaultNamespaceCreated() { | ||
try { | ||
AtomicBoolean started = new AtomicBoolean(false); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it could be useful to have a
Flag
class that would encapsulate things instead of just relying on String pairs (similarly to what's done for micrometer tags)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh not sure, it is also some time not a pair, just a single flag name