use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
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 che-server by eclipse-che.
the class CombinedSingleHostServerExposerTest method shouldExposeDevfileServersOnSubdomans.
@Test
public void shouldExposeDevfileServersOnSubdomans() {
// given
ServerConfig s1 = new ServerConfigImpl("1", "http", "/", emptyMap());
ServerConfig s2 = new ServerConfigImpl("2", "http", "/", singletonMap(REQUIRE_SUBDOMAIN, "false"));
ServerConfig s3 = new ServerConfigImpl("3", "http", "/", singletonMap(REQUIRE_SUBDOMAIN, "true"));
CombinedSingleHostServerExposer<KubernetesEnvironment> serverExposer = new CombinedSingleHostServerExposer<>(subdomainExposer, subpathExposer);
// when
serverExposer.expose(env, MACHINE, SERVICE, SERVER, PORT, Map.of("s1", s1, "s2", s2, "s3", s3));
// then
verify(subdomainExposer).expose(env, MACHINE, SERVICE, SERVER, PORT, Map.of("s3", s3));
verify(subpathExposer).expose(env, MACHINE, SERVICE, SERVER, PORT, Map.of("s1", s1, "s2", s2));
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
the class DefaultHostExternalServiceExposureStrategyTest method shouldCreateSingleIngressForTwoNonUniqueServersWithTheSamePort.
@Test
public void shouldCreateSingleIngressForTwoNonUniqueServersWithTheSamePort() {
// given
ServerConfigImpl httpServerConfig = new ServerConfigImpl("8080/tcp", "http", "/api", ATTRIBUTES_MAP);
ServerConfigImpl wsServerConfig = new ServerConfigImpl("8080/tcp", "ws", "/connect", ATTRIBUTES_MAP);
ServicePort servicePort = new ServicePortBuilder().withName("server-8080").withPort(8080).withProtocol("TCP").withTargetPort(new IntOrString(8080)).build();
Map<String, ServerConfig> serversToExpose = ImmutableMap.of("http-server", httpServerConfig, "ws-server", wsServerConfig);
// when
externalServerExposer.expose(kubernetesEnvironment, MACHINE_NAME, SERVICE_NAME, null, servicePort, serversToExpose);
// then
assertEquals(kubernetesEnvironment.getIngresses().size(), 1);
assertThatExternalServerIsExposed(MACHINE_NAME, SERVICE_NAME, "http-server", servicePort, new ServerConfigImpl(httpServerConfig).withAttributes(ATTRIBUTES_MAP));
assertThatExternalServerIsExposed(MACHINE_NAME, SERVICE_NAME, "ws-server", servicePort, new ServerConfigImpl(wsServerConfig).withAttributes(ATTRIBUTES_MAP));
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
the class DefaultHostExternalServiceExposureStrategyTest method shouldCreateIngressForServer.
@Test
public void shouldCreateIngressForServer() {
// given
ServerConfigImpl httpServerConfig = new ServerConfigImpl("8080/tcp", "http", "/api", ATTRIBUTES_MAP);
ServicePort servicePort = new ServicePortBuilder().withName("server-8080").withPort(8080).withProtocol("TCP").withTargetPort(new IntOrString(8080)).build();
Map<String, ServerConfig> serversToExpose = ImmutableMap.of("http-server", httpServerConfig);
// when
externalServerExposer.expose(kubernetesEnvironment, MACHINE_NAME, SERVICE_NAME, null, servicePort, serversToExpose);
// then
assertThatExternalServerIsExposed(MACHINE_NAME, SERVICE_NAME, "http-server", servicePort, new ServerConfigImpl(httpServerConfig).withAttributes(ATTRIBUTES_MAP));
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.
the class GatewayServerExposerTest method testExposeServiceWithGatewayConfigmap.
@Test
public void testExposeServiceWithGatewayConfigmap() {
// given
KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().build();
// when
serverExposer.expose(k8sEnv, machineName, serviceName, serverId, servicePort, servers);
// then
Map<String, ConfigMap> configMaps = k8sEnv.getConfigMaps();
assertTrue(configMaps.containsKey(serviceName + "-" + serverId));
ConfigMap serverConfigMap = configMaps.get("service-server");
// data should be empty at this point
assertTrue(serverConfigMap.getData() == null || serverConfigMap.getData().isEmpty());
assertEquals(serverConfigMap.getMetadata().getLabels(), GATEWAY_CONFIGMAP_LABELS);
Map<String, String> annotations = serverConfigMap.getMetadata().getAnnotations();
Annotations.Deserializer deserializer = Annotations.newDeserializer(annotations);
assertEquals(deserializer.machineName(), machineName);
Map<String, ServerConfigImpl> exposedServers = deserializer.servers();
assertTrue(exposedServers.containsKey("serverOne"));
ServerConfig s1 = exposedServers.get("serverOne");
assertEquals(s1.getAttributes().get(s1attrs.keySet().iterator().next()), s1attrs.values().iterator().next());
assertEquals(s1.getAttributes().get(ServerConfigImpl.SERVICE_NAME_ATTRIBUTE), "service");
assertEquals(s1.getAttributes().get(ServerConfigImpl.SERVICE_PORT_ATTRIBUTE), "1234");
assertEquals(s1.getPort(), "1111");
assertEquals(s1.getProtocol(), "ws");
assertNull(s1.getPath());
assertEquals(s1.getEndpointOrigin(), "/service/server/");
}
Aggregations