use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
the class OpenShiftExternalServerExposerTest method shouldAddRouteToEnvForExposingSpecifiedServerWithSpecificHost.
@Test
public void shouldAddRouteToEnvForExposingSpecifiedServerWithSpecificHost() {
// given
RouteServerExposer osExternalServerExposer = new RouteServerExposer(LABELS, "open.che.org");
OpenShiftEnvironment osEnv = OpenShiftEnvironment.builder().build();
Map<String, ServerConfig> servers = new HashMap<>();
servers.put("server", new ServerConfigImpl());
// when
osExternalServerExposer.expose(osEnv, "machine123", "service123", null, new ServicePort(null, "servicePort", null, null, "TCP", null), servers);
// then
assertEquals(1, osEnv.getRoutes().size());
Route route = osEnv.getRoutes().values().iterator().next();
assertNotNull(route);
assertEquals(route.getSpec().getTo().getName(), "service123");
assertEquals(route.getSpec().getPort().getTargetPort().getStrVal(), "servicePort");
assertTrue(route.getSpec().getHost().endsWith(".open.che.org"));
assertTrue(route.getSpec().getHost().startsWith("route"));
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
the class KubernetesServerExposer method createService.
private Optional<Service> createService(Map<String, ServerConfig> internalServers, Map<String, ServicePort> unsecuredPorts) {
Map<String, ServerConfig> allInternalServers = new HashMap<>(internalServers);
if (unsecuredPorts.isEmpty()) {
return Optional.empty();
}
Service service = new ServerServiceBuilder().withName(generate(SERVER_PREFIX, SERVER_UNIQUE_PART_SIZE) + '-' + machineName).withMachineName(machineName).withSelectorEntry(CHE_ORIGINAL_NAME_LABEL, pod.getMetadata().getName()).withPorts(new ArrayList<>(unsecuredPorts.values())).withServers(allInternalServers).build();
return Optional.of(service);
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
the class KubernetesServerExposer method exposeSecureServers.
private void exposeSecureServers(Map<String, ServerConfig> securedServers, Map<String, ServicePort> securedPorts) throws InfrastructureException {
if (securedPorts.isEmpty()) {
return;
}
Optional<Service> secureService = secureServerExposer.createService(securedPorts.values(), pod, machineName, securedServers);
String secureServiceName = secureService.map(s -> {
String n = s.getMetadata().getName();
k8sEnv.getServices().put(n, s);
return n;
}).orElse(null);
for (ServicePort servicePort : securedPorts.values()) {
// expose service port related secure servers if exist
Map<String, ServerConfig> matchedSecureServers = match(securedServers, servicePort);
if (!matchedSecureServers.isEmpty()) {
onEachExposableServerSet(matchedSecureServers, (serverId, srvrs) -> {
secureServerExposer.expose(k8sEnv, pod, machineName, secureServiceName, serverId, servicePort, srvrs);
});
}
}
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
the class DefaultHostExternalServiceExposureStrategyTest method assertThatExternalServerIsExposed.
@SuppressWarnings("SameParameterValue")
private void assertThatExternalServerIsExposed(String machineName, String serviceName, String serverNameRegex, ServicePort servicePort, ServerConfigImpl expected) {
// ensure that required ingress is created
for (Ingress ingress : kubernetesEnvironment.getIngresses().values()) {
IngressRule ingressRule = ingress.getSpec().getRules().get(0);
IngressBackend backend = ingressRule.getHttp().getPaths().get(0).getBackend();
if (serviceName.equals(backend.getService().getName())) {
assertEquals(backend.getService().getPort().getName(), servicePort.getName());
Annotations.Deserializer ingressAnnotations = Annotations.newDeserializer(ingress.getMetadata().getAnnotations());
Map<String, ServerConfigImpl> servers = ingressAnnotations.servers();
ServerConfig serverConfig = servers.get(serverNameRegex);
if (serverConfig == null) {
// ok, this ingress is not for this particular server
continue;
}
assertEquals(serverConfig, expected);
assertEquals(ingressAnnotations.machineName(), machineName);
return;
}
}
Assert.fail(format("Could not find an ingress for machine '%s' and service '%s'", machineName, serviceName));
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
the class ExternalServerIngressBuilderTest method assertIngressSpec.
private void assertIngressSpec(String path, String host, Ingress ingress) {
assertEquals(ingress.getSpec().getRules().get(0).getHost(), host);
HTTPIngressPath httpIngressPath = ingress.getSpec().getRules().get(0).getHttp().getPaths().get(0);
assertEquals(httpIngressPath.getPath(), path);
assertEquals(httpIngressPath.getPathType(), INGRESS_PATH_TYPE);
assertEquals(httpIngressPath.getBackend().getService().getName(), SERVICE_NAME);
assertEquals(httpIngressPath.getBackend().getService().getPort().getName(), SERVICE_PORT_NAME);
assertEquals(ingress.getMetadata().getName(), NAME);
assertTrue(ingress.getMetadata().getAnnotations().containsKey("annotation-key"));
assertEquals(ingress.getMetadata().getAnnotations().get("annotation-key"), "annotation-value");
Annotations.Deserializer ingressAnnotations = Annotations.newDeserializer(ingress.getMetadata().getAnnotations());
Map<String, ServerConfigImpl> servers = ingressAnnotations.servers();
ServerConfig serverConfig = servers.get("http-server");
assertEquals(serverConfig, SERVER_CONFIG);
assertEquals(ingressAnnotations.machineName(), MACHINE_NAME);
}
Aggregations