Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Add proxy support to kubernetes
Browse files Browse the repository at this point in the history
Fixes #625
  • Loading branch information
pearj committed Jul 7, 2018
1 parent bf94ffe commit 631c806
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ public class DockerContainerClient implements ContainerClient {
"/home/seluser/videos",
"/dev/shm"
};
private static final String[] HTTP_PROXY_ENV_VARS = {
"zalenium_http_proxy",
"zalenium_https_proxy",
"zalenium_no_proxy"
};

private static final Environment defaultEnvironment = new Environment();
private static Environment env = defaultEnvironment;
/** Number of times to attempt to create a container when the generated name is not unique. */
Expand Down Expand Up @@ -442,15 +438,6 @@ private synchronized void loadMountedFolders(ContainerInfo containerInfo) {
this.mntFolders.add(containerMount);
}
}

for (String envVar : containerInfo.config().env()) {
Arrays.asList(HTTP_PROXY_ENV_VARS).forEach(httpEnvVar -> {
String httpEnvVarToAdd = envVar.replace("zalenium_", "");
if (envVar.contains(httpEnvVar) && !zaleniumHttpEnvVars.contains(httpEnvVarToAdd)) {
zaleniumHttpEnvVars.add(httpEnvVarToAdd);
}
});
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public static DoneablePod createDoneablePodDefaultImpl(PodConfiguration config)
// so then we can initiate a registration.
.withNewReadinessProbe()
.withNewExec()
.addToCommand(new String[] {"/bin/sh", "-c", "curl -s http://`getent hosts ${HOSTNAME} | awk '{ print $1 }'`:"
.addToCommand(new String[] {"/bin/sh", "-c", "http_proxy=\"\" curl -s http://`getent hosts ${HOSTNAME} | awk '{ print $1 }'`:"
+ config.getNodePort() + "/wd/hub/status | jq .value.ready | grep true"})
.endExec()
.withInitialDelaySeconds(5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ public class DockeredSeleniumStarter {
private static Dimension configuredScreenSize;
private static String containerName;
private static String dockerSeleniumImageName;
private static Map<String, String> zaleniumProxyVars = new HashMap<>();

private static final String[] HTTP_PROXY_ENV_VARS = {
"zalenium_http_proxy",
"zalenium_https_proxy",
"zalenium_no_proxy"
};

/*
* Reading configuration values from the env variables, if a value was not provided it falls back to defaults.
*/
Expand All @@ -94,6 +101,18 @@ public static void readConfigurationFromEnvVariables() {
setSeleniumNodeParameters(seleniumNodeParams);

sendAnonymousUsageInfo = env.getBooleanEnvVariable("ZALENIUM_SEND_ANONYMOUS_USAGE_INFO", false);

addProxyVars();
}

private static void addProxyVars() {
Arrays.asList(HTTP_PROXY_ENV_VARS).forEach(httpEnvVar -> {
String proxyValue = env.getStringEnvVariable(httpEnvVar, null);
String httpEnvVarToAdd = httpEnvVar.replace("zalenium_", "");
if (proxyValue != null) {
zaleniumProxyVars.put(httpEnvVarToAdd, proxyValue);
}
});
}

static {
Expand Down Expand Up @@ -277,6 +296,9 @@ private Map<String, String> buildEnvVars(TimeZone timeZone, Dimension screenSize
envVars.put("CHROME", "false");
envVars.put("FIREFOX", "false");
envVars.put("SELENIUM_NODE_PARAMS", seleniumNodeParams);

// Add the proxy vars
envVars.putAll(zaleniumProxyVars);
return envVars;
}

Expand Down

0 comments on commit 631c806

Please sign in to comment.