Search in sources :

Example 1 with Annotations

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");
}
Also used : Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Test(org.testng.annotations.Test)

Example 2 with Annotations

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);
}
Also used : Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Test(org.testng.annotations.Test)

Example 3 with Annotations

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
}
Also used : Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Test(org.testng.annotations.Test)

Example 4 with Annotations

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");
}
Also used : Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Test(org.testng.annotations.Test)

Example 5 with Annotations

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/");
}
Also used : ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Test(org.testng.annotations.Test)

Aggregations

ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)10 Annotations (org.eclipse.che.workspace.infrastructure.kubernetes.Annotations)10 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)8 Test (org.testng.annotations.Test)8 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)6 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 ServerConfig (org.eclipse.che.api.core.model.workspace.config.ServerConfig)2 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)2 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)2 GatewayRouteConfigGenerator (org.eclipse.che.workspace.infrastructure.kubernetes.server.external.GatewayRouteConfigGenerator)2