use of org.eclipse.che.api.core.model.workspace.config.ServerConfig 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.core.model.workspace.config.ServerConfig 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.core.model.workspace.config.ServerConfig 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.core.model.workspace.config.ServerConfig 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.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.
the class ServerConfigImplTest method testCreateFromEndpointMinimalEndpointShouldTranslateToHttpProtocol.
@Test
public void testCreateFromEndpointMinimalEndpointShouldTranslateToHttpProtocol() {
ServerConfig serverConfig = ServerConfigImpl.createFromEndpoint(new EndpointImpl("name", 123, emptyMap()));
assertEquals(serverConfig.getProtocol(), "http");
}
Aggregations