use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class PreviewUrlExposerTest method shouldProvisionServiceAndIngressWhenNotFound.
@Test
public void shouldProvisionServiceAndIngressWhenNotFound() throws InternalInfrastructureException {
Mockito.when(externalServiceExposureStrategy.getExternalPath(Mockito.anyString(), Mockito.any())).thenReturn("some-server-path");
final int PORT = 8080;
final String SERVER_PORT_NAME = "server-" + PORT;
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setIngresses(new HashMap<>()).setServices(new HashMap<>()).build();
previewUrlExposer.expose(env);
assertEquals(env.getIngresses().size(), 1);
assertEquals(env.getServices().size(), 1);
Service provisionedService = env.getServices().values().iterator().next();
ServicePort provisionedServicePort = provisionedService.getSpec().getPorts().get(0);
assertEquals(provisionedServicePort.getName(), SERVER_PORT_NAME);
assertEquals(provisionedServicePort.getPort().intValue(), PORT);
Ingress provisionedIngress = env.getIngresses().values().iterator().next();
IngressBackend provisionedIngressBackend = provisionedIngress.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend();
assertEquals(provisionedIngressBackend.getService().getPort().getName(), SERVER_PORT_NAME);
assertEquals(provisionedIngressBackend.getService().getName(), provisionedService.getMetadata().getName());
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment 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.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment 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/");
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class KubernetesServerExposerTest method assertThatExternalServersAreExposed.
@SuppressWarnings("SameParameterValue")
private void assertThatExternalServersAreExposed(String machineName, String portProtocol, Integer port, Map<String, ServerConfig> expectedServers) {
// then
assertThatContainerPortIsExposed(portProtocol, port);
// ensure that service is created
Service service = findContainerRelatedService();
assertNotNull(service);
// ensure that required service port is exposed
ServicePort servicePort = assertThatServicePortIsExposed(port, service);
Annotations.Deserializer serviceAnnotations = Annotations.newDeserializer(service.getMetadata().getAnnotations());
assertEquals(serviceAnnotations.machineName(), machineName);
// check that we did not create servers for public endpoints
assertFalse(serviceAnnotations.servers().keySet().stream().anyMatch(key -> expectedServers.containsKey(key)));
verify(externalServerExposer).expose(eq(kubernetesEnvironment), eq(machineName), eq(service.getMetadata().getName()), any(), eq(servicePort), eq(expectedServers));
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project che-server by eclipse-che.
the class KubernetesServerExposerTest method assertThatSecureServerIsExposed.
@SuppressWarnings("SameParameterValue")
private void assertThatSecureServerIsExposed(String machineName, String portProtocol, Integer port, String serverName, ServerConfig serverConfig) throws Exception {
// then
assertThatContainerPortIsExposed(portProtocol, port);
// ensure that service is created
Service service = findContainerRelatedService();
assertNotNull(service);
// ensure that no service port is exposed
assertTrue(service.getSpec().getPorts().stream().noneMatch(p -> p.getTargetPort().getIntVal().equals(port)));
ServicePort servicePort = new ServicePortBuilder().withName("server-" + port).withPort(port).withProtocol(portProtocol.toUpperCase()).withNewTargetPort(port).build();
verify(secureServerExposer).expose(eq(kubernetesEnvironment), any(), eq(machineName), // no service exists for the backed server
isNull(), // a non-unique server
isNull(), eq(servicePort), eq(ImmutableMap.of(serverName, serverConfig)));
}
Aggregations