Search in sources :

Example 1 with ServerConfig

use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.

the class OpenShiftExternalServerExposerTest method shouldAddRouteToEnvForExposingSpecifiedServerWithSpecificHost.

@Test
public void shouldAddRouteToEnvForExposingSpecifiedServerWithSpecificHost() {
    // given
    RouteServerExposer osExternalServerExposer = new RouteServerExposer(LABELS, "open.che.org");
    OpenShiftEnvironment osEnv = OpenShiftEnvironment.builder().build();
    Map<String, ServerConfig> servers = new HashMap<>();
    servers.put("server", new ServerConfigImpl());
    // when
    osExternalServerExposer.expose(osEnv, "machine123", "service123", null, new ServicePort(null, "servicePort", null, null, "TCP", null), servers);
    // then
    assertEquals(1, osEnv.getRoutes().size());
    Route route = osEnv.getRoutes().values().iterator().next();
    assertNotNull(route);
    assertEquals(route.getSpec().getTo().getName(), "service123");
    assertEquals(route.getSpec().getPort().getTargetPort().getStrVal(), "servicePort");
    assertTrue(route.getSpec().getHost().endsWith(".open.che.org"));
    assertTrue(route.getSpec().getHost().startsWith("route"));
}
Also used : OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) HashMap(java.util.HashMap) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Example 2 with ServerConfig

use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.

the class KubernetesServerExposer method createService.

private Optional<Service> createService(Map<String, ServerConfig> internalServers, Map<String, ServicePort> unsecuredPorts) {
    Map<String, ServerConfig> allInternalServers = new HashMap<>(internalServers);
    if (unsecuredPorts.isEmpty()) {
        return Optional.empty();
    }
    Service service = new ServerServiceBuilder().withName(generate(SERVER_PREFIX, SERVER_UNIQUE_PART_SIZE) + '-' + machineName).withMachineName(machineName).withSelectorEntry(CHE_ORIGINAL_NAME_LABEL, pod.getMetadata().getName()).withPorts(new ArrayList<>(unsecuredPorts.values())).withServers(allInternalServers).build();
    return Optional.of(service);
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) HashMap(java.util.HashMap) Service(io.fabric8.kubernetes.api.model.Service)

Example 3 with ServerConfig

use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.

the class KubernetesServerExposer method exposeSecureServers.

private void exposeSecureServers(Map<String, ServerConfig> securedServers, Map<String, ServicePort> securedPorts) throws InfrastructureException {
    if (securedPorts.isEmpty()) {
        return;
    }
    Optional<Service> secureService = secureServerExposer.createService(securedPorts.values(), pod, machineName, securedServers);
    String secureServiceName = secureService.map(s -> {
        String n = s.getMetadata().getName();
        k8sEnv.getServices().put(n, s);
        return n;
    }).orElse(null);
    for (ServicePort servicePort : securedPorts.values()) {
        // expose service port related secure servers if exist
        Map<String, ServerConfig> matchedSecureServers = match(securedServers, servicePort);
        if (!matchedSecureServers.isEmpty()) {
            onEachExposableServerSet(matchedSecureServers, (serverId, srvrs) -> {
                secureServerExposer.expose(k8sEnv, pod, machineName, secureServiceName, serverId, servicePort, srvrs);
            });
        }
    }
}
Also used : NameGenerator.generate(org.eclipse.che.commons.lang.NameGenerator.generate) Container(io.fabric8.kubernetes.api.model.Container) ConfigurationProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.ConfigurationProvisioner) ExternalServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ExternalServerExposer) LoggerFactory(org.slf4j.LoggerFactory) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) HashMap(java.util.HashMap) SERVER_NAME_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.ServerConfig.SERVER_NAME_ATTRIBUTE) ArrayList(java.util.ArrayList) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Service(io.fabric8.kubernetes.api.model.Service) UniqueNamesProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.UniqueNamesProvisioner) Constants(org.eclipse.che.workspace.infrastructure.kubernetes.Constants) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) SecureServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposer) Integer.parseInt(java.lang.Integer.parseInt) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) CHE_ORIGINAL_NAME_LABEL(org.eclipse.che.workspace.infrastructure.kubernetes.Constants.CHE_ORIGINAL_NAME_LABEL) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Optional(java.util.Optional) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) Collections(java.util.Collections) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) Service(io.fabric8.kubernetes.api.model.Service)

Example 4 with ServerConfig

use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.

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 5 with ServerConfig

use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project che-server by eclipse-che.

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)

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