use of org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl in project devspaces-images by redhat-developer.
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.workspace.server.model.impl.ServerConfigImpl in project devspaces-images by redhat-developer.
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);
}
use of org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl in project devspaces-images by redhat-developer.
the class IngressServerExposerTest method shouldReplaceServerNamePlaceholders.
@Test
public void shouldReplaceServerNamePlaceholders() {
// given
Map<String, String> annotations = new HashMap<>();
annotations.put("ssl", "true");
annotations.put("websocket-service", SERVICE_NAME_PLACEHOLDER);
IngressServerExposer<KubernetesEnvironment> exposer = new IngressServerExposer<>(serviceExposureStrategy, annotations, null, "");
KubernetesEnvironment env = KubernetesEnvironment.builder().build();
Map<String, ServerConfig> externalServers = new HashMap<>();
externalServers.put("ide", new ServerConfigImpl("6543", "http", "/", emptyMap()));
// when
exposer.expose(env, "editor", "ide", "server123", new ServicePort(), externalServers);
// then
Collection<Ingress> ingresses = env.getIngresses().values();
assertEquals(ingresses.size(), 1);
Ingress ingress = ingresses.iterator().next();
assertEquals(ingress.getMetadata().getAnnotations().get("ssl"), "true");
assertEquals(ingress.getMetadata().getAnnotations().get("websocket-service"), "ide");
}
use of org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl in project devspaces-images by redhat-developer.
the class MultiHostExternalServiceExposureStrategyTest method assertThatExternalServerIsExposed.
private void assertThatExternalServerIsExposed(String machineName, String serviceName, String serverNameRegex, String portProtocol, Integer port, ServicePort servicePort, ServerConfigImpl expected) {
// ensure that required ingress is created
String ingressName = serviceName + "-" + (expected.isUnique() ? serverNameRegex : servicePort.getName());
Ingress ingress = kubernetesEnvironment.getIngresses().get(ingressName);
IngressRule ingressRule = ingress.getSpec().getRules().get(0);
assertEquals(ingressRule.getHost(), ingressName + "." + DOMAIN);
assertEquals(ingressRule.getHttp().getPaths().get(0).getPath(), "/");
IngressBackend backend = ingressRule.getHttp().getPaths().get(0).getBackend();
assertEquals(backend.getService().getName(), serviceName);
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);
assertEquals(serverConfig, expected);
assertEquals(ingressAnnotations.machineName(), machineName);
assertEquals(ingress.getMetadata().getLabels().get("foo"), "bar");
}
use of org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl in project devspaces-images by redhat-developer.
the class TraefikGatewayRouteConfigGeneratorTest method failWhenMultipleServersInConfigmapAnnotations.
@Test(expectedExceptions = InfrastructureException.class)
public void failWhenMultipleServersInConfigmapAnnotations() throws InfrastructureException {
ServerConfigImpl serverConfig = new ServerConfigImpl("123", "https", "/", ImmutableMap.of(SERVICE_NAME_ATTRIBUTE, "service-url", SERVICE_PORT_ATTRIBUTE, "1234", ServerConfig.ENDPOINT_ORIGIN, "/blabol-cesta"));
Map<String, String> annotations = new Annotations.Serializer().server("s1", serverConfig).server("s2", serverConfig).annotations();
ConfigMap routeConfig = new ConfigMapBuilder().withNewMetadata().withName("route").withAnnotations(annotations).endMetadata().build();
gatewayConfigGenerator.addRouteConfig("c1", routeConfig);
gatewayConfigGenerator.generate("che-namespace");
}
Aggregations