use of org.eclipse.che.workspace.infrastructure.kubernetes.Annotations in project che-server by eclipse-che.
the class TraefikGatewayRouteConfigGeneratorTest method failWhenMultipleServersInConfigmapAnnotations.
@Test(expectedExceptions = InfrastructureException.class)
public void failWhenMultipleServersInConfigmapAnnotations() throws InfrastructureException {
ServerConfigImpl serverConfig = new ServerConfigImpl("123", "https", "/", ImmutableMap.of(SERVICE_NAME_ATTRIBUTE, "service-url", SERVICE_PORT_ATTRIBUTE, "1234", ServerConfig.ENDPOINT_ORIGIN, "/blabol-cesta"));
Map<String, String> annotations = new Annotations.Serializer().server("s1", serverConfig).server("s2", serverConfig).annotations();
ConfigMap routeConfig = new ConfigMapBuilder().withNewMetadata().withName("route").withAnnotations(annotations).endMetadata().build();
gatewayConfigGenerator.addRouteConfig("c1", routeConfig);
gatewayConfigGenerator.generate("che-namespace");
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.Annotations in project che-server by eclipse-che.
the class GatewayRouterProvisionerTest method testProvision.
@Test
public void testProvision() throws InfrastructureException {
// given
Map<String, String> annotationsWith2Servers = new Annotations.Serializer().server("s1", serverConfig).annotations();
ConfigMap gatewayRouteConfigMap = new ConfigMapBuilder().withNewMetadata().withName("route").withAnnotations(annotationsWith2Servers).endMetadata().build();
when(env.getConfigMaps()).thenReturn(Collections.singletonMap("route", gatewayRouteConfigMap));
Map<String, String> expectedData = Collections.singletonMap("data.yml", "this is for sure generated configuration");
when(gatewayRouteConfigGenerator.generate(NAMESPACE)).thenReturn(expectedData);
// when
gatewayRouterProvisioner.provision(env, identity);
// then
verify(configGeneratorFactory).create();
verify(gatewayRouteConfigGenerator).addRouteConfig("route", gatewayRouteConfigMap);
verify(gatewayRouteConfigGenerator).generate(NAMESPACE);
Map<String, ServerConfigImpl> serverConfigsAfterProvisioning = new Annotations.Deserializer(gatewayRouteConfigMap.getMetadata().getAnnotations()).servers();
assertEquals(serverConfigsAfterProvisioning.size(), 1);
ServerConfigImpl server = serverConfigsAfterProvisioning.get(serverConfigsAfterProvisioning.keySet().iterator().next());
// verify that provisioner removes the internal attributes
assertFalse(server.getAttributes().containsKey(SERVICE_NAME_ATTRIBUTE));
assertFalse(server.getAttributes().containsKey(SERVICE_PORT_ATTRIBUTE));
// verify that provisioner included the data info configmap
Map<String, String> actualData = gatewayRouteConfigMap.getData();
assertEquals(actualData, expectedData);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.Annotations in project devspaces-images by redhat-developer.
the class GatewayRouterProvisionerTest method testFailWhenMoreThanOneServerInConfigmapAnnotations.
@Test(expectedExceptions = InfrastructureException.class)
public void testFailWhenMoreThanOneServerInConfigmapAnnotations() throws InfrastructureException {
// given
Map<String, String> annotationsWith2Servers = new Annotations.Serializer().server("s1", serverConfigWithoutAttributes).server("s2", serverConfigWithoutAttributes).annotations();
ConfigMap gatewayRouteConfigMap = new ConfigMapBuilder().withNewMetadata().withName("route").withAnnotations(annotationsWith2Servers).endMetadata().build();
when(env.getConfigMaps()).thenReturn(Collections.singletonMap("route", gatewayRouteConfigMap));
// when
gatewayRouterProvisioner.provision(env, identity);
// then exception
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.Annotations in project devspaces-images by redhat-developer.
the class TraefikGatewayRouteConfigGeneratorTest method failWhenMultipleServersInConfigmapAnnotations.
@Test(expectedExceptions = InfrastructureException.class)
public void failWhenMultipleServersInConfigmapAnnotations() throws InfrastructureException {
ServerConfigImpl serverConfig = new ServerConfigImpl("123", "https", "/", ImmutableMap.of(SERVICE_NAME_ATTRIBUTE, "service-url", SERVICE_PORT_ATTRIBUTE, "1234", ServerConfig.ENDPOINT_ORIGIN, "/blabol-cesta"));
Map<String, String> annotations = new Annotations.Serializer().server("s1", serverConfig).server("s2", serverConfig).annotations();
ConfigMap routeConfig = new ConfigMapBuilder().withNewMetadata().withName("route").withAnnotations(annotations).endMetadata().build();
gatewayConfigGenerator.addRouteConfig("c1", routeConfig);
gatewayConfigGenerator.generate("che-namespace");
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.Annotations 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/");
}
Aggregations