Search in sources :

Example 81 with KubernetesEnvironment

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.

the class ProxySettingsProvisionerTest method shouldNotApplyProxySettingsToJWTProxyContainer.

@Test
public void shouldNotApplyProxySettingsToJWTProxyContainer() throws Exception {
    Map<String, Pod> pods = new HashMap<>();
    pods.put(JWT_PROXY_POD_NAME, buildPod(JWT_PROXY_POD_NAME, buildContainers(2)));
    KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().setPods(pods).build();
    provisioner.provision(k8sEnv, runtimeId);
    assertTrue(k8sEnv.getPodsData().values().stream().filter(pod -> pod.getMetadata().getName().equals(JWT_PROXY_POD_NAME)).flatMap(pod -> pod.getSpec().getContainers().stream()).noneMatch(container -> container.getEnv().contains(new EnvVar(HTTP_PROXY, HTTP_PROXY_VALUE, null)) || container.getEnv().contains(new EnvVar(HTTPS_PROXY, HTTPS_PROXY_VALUE, null)) || container.getEnv().contains(new EnvVar(NO_PROXY, NO_PROXY_VALUE, null))));
}
Also used : HTTP_PROXY(org.eclipse.che.workspace.infrastructure.kubernetes.provision.ProxySettingsProvisioner.HTTP_PROXY) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Arrays(java.util.Arrays) NameGenerator.generate(org.eclipse.che.commons.lang.NameGenerator.generate) Listeners(org.testng.annotations.Listeners) Container(io.fabric8.kubernetes.api.model.Container) Mock(org.mockito.Mock) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) Mockito.lenient(org.mockito.Mockito.lenient) ArrayList(java.util.ArrayList) HTTPS_PROXY(org.eclipse.che.workspace.infrastructure.kubernetes.provision.ProxySettingsProvisioner.HTTPS_PROXY) NO_PROXY(org.eclipse.che.workspace.infrastructure.kubernetes.provision.ProxySettingsProvisioner.NO_PROXY) JWT_PROXY_POD_NAME(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.JwtProxyProvisioner.JWT_PROXY_POD_NAME) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Map(java.util.Map) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) BeforeMethod(org.testng.annotations.BeforeMethod) Pod(io.fabric8.kubernetes.api.model.Pod) List(java.util.List) Stream(java.util.stream.Stream) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Assert.assertTrue(org.testng.Assert.assertTrue) Pod(io.fabric8.kubernetes.api.model.Pod) HashMap(java.util.HashMap) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Test(org.testng.annotations.Test)

Example 82 with KubernetesEnvironment

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.

the class GatewayTlsProvisionerTest method provisionTlsForGatewayRouteConfigmaps.

@Test(dataProvider = "tlsProvisionData")
public void provisionTlsForGatewayRouteConfigmaps(ServerConfigImpl server, boolean tlsEnabled, String expectedProtocol) throws Exception {
    // given
    Map<String, String> composedAnnotations = new HashMap<>(annotations);
    composedAnnotations.putAll(Annotations.newSerializer().server("server", server).machineName(machine).annotations());
    ConfigMap routeConfigMap = new ConfigMapBuilder().withNewMetadata().withName("route").withAnnotations(composedAnnotations).endMetadata().build();
    GatewayTlsProvisioner<KubernetesEnvironment> gatewayTlsProvisioner = new GatewayTlsProvisioner<>(tlsEnabled, gatewayConfigmapLabels, tlsProvisionerProvider);
    lenient().when(k8sEnv.getConfigMaps()).thenReturn(singletonMap("route", routeConfigMap));
    // when
    gatewayTlsProvisioner.provision(k8sEnv, runtimeIdentity);
    // then
    Map<String, ServerConfigImpl> servers = Annotations.newDeserializer(routeConfigMap.getMetadata().getAnnotations()).servers();
    assertEquals(servers.get("server").getProtocol(), expectedProtocol);
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Test(org.testng.annotations.Test)

Example 83 with KubernetesEnvironment

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.

the class GatewayTlsProvisionerTest method throwExceptionWhenMultipleServersInGatewayRouteConfigAnnotations.

@Test(expectedExceptions = InfrastructureException.class)
public void throwExceptionWhenMultipleServersInGatewayRouteConfigAnnotations() throws InfrastructureException {
    // given
    Map<String, String> composedAnnotations = new HashMap<>(annotations);
    composedAnnotations.putAll(Annotations.newSerializer().server("server1", httpServer).server("server2", wsServer).machineName(machine).annotations());
    ConfigMap routeConfigMap = new ConfigMapBuilder().withNewMetadata().withName("route").withAnnotations(composedAnnotations).endMetadata().build();
    when(k8sEnv.getConfigMaps()).thenReturn(singletonMap("route", routeConfigMap));
    GatewayTlsProvisioner<KubernetesEnvironment> gatewayTlsProvisioner = new GatewayTlsProvisioner<>(true, gatewayConfigmapLabels, tlsProvisionerProvider);
    // when
    gatewayTlsProvisioner.provision(k8sEnv, runtimeIdentity);
// then exception
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test)

Example 84 with KubernetesEnvironment

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment in project devspaces-images by redhat-developer.

the class PreviewUrlExposerTest method shouldDoNothingWhenNoCommandsDefined.

@Test
public void shouldDoNothingWhenNoCommandsDefined() throws InternalInfrastructureException {
    KubernetesEnvironment env = KubernetesEnvironment.builder().build();
    previewUrlExposer.expose(env);
    assertTrue(env.getCommands().isEmpty());
    assertTrue(env.getServices().isEmpty());
    assertTrue(env.getIngresses().isEmpty());
}
Also used : KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test)

Example 85 with KubernetesEnvironment

use of org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment 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/");
}
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

KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)94 Test (org.testng.annotations.Test)68 Map (java.util.Map)30 HashMap (java.util.HashMap)28 Service (io.fabric8.kubernetes.api.model.Service)26 Container (io.fabric8.kubernetes.api.model.Container)24 Pod (io.fabric8.kubernetes.api.model.Pod)24 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)22 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)20 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)20 ArrayList (java.util.ArrayList)19 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)18 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)18 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)18 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)18 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)18 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)14 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)14 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)14 InternalRecipe (org.eclipse.che.api.workspace.server.spi.environment.InternalRecipe)14