Search in sources :

Example 41 with ServerConfig

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");
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)

Example 42 with ServerConfig

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));
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Test(org.testng.annotations.Test)

Example 43 with ServerConfig

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));
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Test(org.testng.annotations.Test)

Example 44 with ServerConfig

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));
}
Also used : ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Test(org.testng.annotations.Test)

Example 45 with ServerConfig

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/");
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Test(org.testng.annotations.Test)

Aggregations

ServerConfig (org.eclipse.che.api.core.model.workspace.config.ServerConfig)74 Test (org.testng.annotations.Test)54 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)42 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)30 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)28 EndpointImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl)20 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)18 HashMap (java.util.HashMap)16 Annotations (org.eclipse.che.workspace.infrastructure.kubernetes.Annotations)16 Service (io.fabric8.kubernetes.api.model.Service)14 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)12 Map (java.util.Map)10 ImmutableMap (com.google.common.collect.ImmutableMap)8 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)8 Container (io.fabric8.kubernetes.api.model.Container)6 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)6 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)6 ArrayList (java.util.ArrayList)6 Collections.singletonMap (java.util.Collections.singletonMap)6 Optional (java.util.Optional)6