use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.
the class KubernetesServerExposerTest method shouldCreateIngressForServerWhenTwoServersHasTheSamePort.
@Test
public void shouldCreateIngressForServerWhenTwoServersHasTheSamePort() throws InfrastructureException {
// given
ServerConfigImpl httpServerConfig = new ServerConfigImpl("8080/tcp", "http", "/api", ATTRIBUTES_MAP);
ServerConfigImpl wsServerConfig = new ServerConfigImpl("8080/tcp", "ws", "/connect", ATTRIBUTES_MAP);
IntOrString targetPort = new IntOrString(8080);
ServicePort servicePort = new ServicePortBuilder().withName("server-8080").withPort(8080).withProtocol("TCP").withTargetPort(targetPort).build();
Map<String, ServerConfig> serversToExpose = ImmutableMap.of("http-server", httpServerConfig, "ws-server", wsServerConfig);
// when
serverExposer.expose(serversToExpose);
// then
assertThatExternalServersAreExposed(MACHINE_NAME, "tcp", 8080, ImmutableMap.of("http-server", new ServerConfigImpl(httpServerConfig).withAttributes(ATTRIBUTES_MAP), "ws-server", new ServerConfigImpl(wsServerConfig).withAttributes(ATTRIBUTES_MAP)));
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.
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 devspaces-images by redhat-developer.
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/");
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.
the class MultiHostExternalServiceExposureStrategyTest method shouldCreateIngressForServer.
@Test
public void shouldCreateIngressForServer() {
// given
ServerConfigImpl httpServerConfig = new ServerConfigImpl("8080/tcp", "http", "/api", ATTRIBUTES_MAP);
IntOrString targetPort = new IntOrString(8080);
ServicePort servicePort = new ServicePortBuilder().withName("server-8080").withPort(8080).withProtocol("TCP").withTargetPort(targetPort).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", "tcp", 8080, servicePort, new ServerConfigImpl(httpServerConfig).withAttributes(ATTRIBUTES_MAP));
}
use of org.eclipse.che.api.core.model.workspace.config.ServerConfig in project devspaces-images by redhat-developer.
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);
}
Aggregations