Search in sources :

Example 26 with ServerConfig

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));
}
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 27 with ServerConfig

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

Example 28 with ServerConfig

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");
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) HashMap(java.util.HashMap) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Test(org.testng.annotations.Test)

Example 29 with ServerConfig

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");
}
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 30 with ServerConfig

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");
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) 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