Search in sources :

Example 31 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project devspaces-images by redhat-developer.

the class EnvironmentVariableSecretApplierTest method shouldProvisionContainersWithAutomountOverrideTrue.

@Test
public void shouldProvisionContainersWithAutomountOverrideTrue() throws Exception {
    Container container_match1 = new ContainerBuilder().withName("maven").build();
    Container container_match2 = new ContainerBuilder().withName("other").build();
    DevfileImpl mock_defvile = mock(DevfileImpl.class);
    ComponentImpl component = new ComponentImpl();
    component.setAlias("maven");
    component.setAutomountWorkspaceSecrets(true);
    when(podSpec.getContainers()).thenReturn(ImmutableList.of(container_match1, container_match2));
    InternalMachineConfig internalMachineConfig = new InternalMachineConfig();
    internalMachineConfig.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, "maven");
    when(environment.getMachines()).thenReturn(ImmutableMap.of("maven", internalMachineConfig));
    when(environment.getDevfile()).thenReturn(mock_defvile);
    when(mock_defvile.getComponents()).thenReturn(singletonList(component));
    Secret secret = new SecretBuilder().withData(singletonMap("foo", "random")).withMetadata(new ObjectMetaBuilder().withName("test_secret").withAnnotations(ImmutableMap.of(ANNOTATION_ENV_NAME, "MY_FOO", ANNOTATION_MOUNT_AS, "env", ANNOTATION_AUTOMOUNT, "false")).withLabels(emptyMap()).build()).build();
    secretApplier.applySecret(environment, runtimeIdentity, secret);
    // only first container has env set
    assertEquals(container_match1.getEnv().size(), 1);
    EnvVar var = container_match1.getEnv().get(0);
    assertEquals(var.getName(), "MY_FOO");
    assertEquals(var.getValueFrom().getSecretKeyRef().getName(), "test_secret");
    assertEquals(var.getValueFrom().getSecretKeyRef().getKey(), "foo");
    assertEquals(container_match2.getEnv().size(), 0);
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Test(org.testng.annotations.Test)

Example 32 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project devspaces-images by redhat-developer.

the class FileSecretApplierTest method shouldProvisionAsFilesWithPathOverride.

@Test
public void shouldProvisionAsFilesWithPathOverride() throws Exception {
    Container container = new ContainerBuilder().withName("maven").build();
    DevfileImpl mock_defvile = mock(DevfileImpl.class);
    ComponentImpl component = new ComponentImpl();
    component.setAlias("maven");
    component.getVolumes().add(new VolumeImpl("test_secret", "/path/to/override"));
    InternalMachineConfig internalMachineConfig = new InternalMachineConfig();
    internalMachineConfig.getAttributes().put(DEVFILE_COMPONENT_ALIAS_ATTRIBUTE, "maven");
    when(environment.getMachines()).thenReturn(ImmutableMap.of("maven", internalMachineConfig));
    when(environment.getDevfile()).thenReturn(mock_defvile);
    when(mock_defvile.getComponents()).thenReturn(singletonList(component));
    PodSpec localSpec = new PodSpecBuilder().withContainers(ImmutableList.of(container)).build();
    when(podData.getSpec()).thenReturn(localSpec);
    Secret secret = new SecretBuilder().withData(ImmutableMap.of("settings.xml", "random", "another.xml", "freedom")).withMetadata(new ObjectMetaBuilder().withName("test_secret").withAnnotations(ImmutableMap.of(ANNOTATION_MOUNT_AS, "file", ANNOTATION_MOUNT_PATH, "/home/user/.m2", ANNOTATION_AUTOMOUNT, "true")).withLabels(emptyMap()).build()).build();
    secretApplier.applySecret(environment, runtimeIdentity, secret);
    // pod has volume created
    assertEquals(environment.getPodsData().get("pod1").getSpec().getVolumes().size(), 1);
    Volume volume = environment.getPodsData().get("pod1").getSpec().getVolumes().get(0);
    assertEquals(volume.getName(), "test_secret");
    assertEquals(volume.getSecret().getSecretName(), "test_secret");
    // both containers has mounts set
    assertEquals(environment.getPodsData().get("pod1").getSpec().getContainers().get(0).getVolumeMounts().size(), 2);
    VolumeMount mount1 = environment.getPodsData().get("pod1").getSpec().getContainers().get(0).getVolumeMounts().get(0);
    assertEquals(mount1.getName(), "test_secret");
    assertEquals(mount1.getMountPath(), "/path/to/override/settings.xml");
    assertTrue(mount1.getReadOnly());
}
Also used : PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Volume(io.fabric8.kubernetes.api.model.Volume) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) Test(org.testng.annotations.Test)

Example 33 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project devspaces-images by redhat-developer.

the class KubernetesPluginsToolingApplierTest method createsPodAndAddToolingIfNoPodIsPresent.

@Test
public void createsPodAndAddToolingIfNoPodIsPresent() throws Exception {
    internalEnvironment = spy(KubernetesEnvironment.builder().build());
    internalEnvironment.setDevfile(new DevfileImpl());
    Map<String, InternalMachineConfig> machines = new HashMap<>();
    machines.put(USER_MACHINE_NAME, userMachineConfig);
    internalEnvironment.getMachines().putAll(machines);
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(createChePlugin()));
    verifyPodAndContainersNumber(1);
    Container toolingContainer = getOneAndOnlyNonUserContainer(internalEnvironment);
    verifyContainer(toolingContainer);
}
Also used : InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Container(io.fabric8.kubernetes.api.model.Container) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) HashMap(java.util.HashMap) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) Test(org.testng.annotations.Test)

Example 34 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project devspaces-images by redhat-developer.

the class KubernetesPluginsToolingApplierTest method addsMachinesWithVolumesToAllToolingContainer.

@Test
public void addsMachinesWithVolumesToAllToolingContainer() throws Exception {
    // given
    ChePlugin chePluginWithNonDefaultVolume = createChePlugin();
    String anotherVolumeName = VOLUME_NAME + "1";
    String anotherVolumeMountPath = VOLUME_MOUNT_PATH + "/something";
    List<Volume> volumes = singletonList(new Volume().name(anotherVolumeName).mountPath(anotherVolumeMountPath));
    CheContainer toolingContainer = chePluginWithNonDefaultVolume.getContainers().get(0);
    toolingContainer.setVolumes(volumes);
    ChePlugin chePlugin = createChePlugin();
    // when
    applier.apply(runtimeIdentity, internalEnvironment, asList(chePlugin, chePluginWithNonDefaultVolume));
    // then
    Collection<InternalMachineConfig> machineConfigs = getNonUserMachines(internalEnvironment);
    assertEquals(machineConfigs.size(), 2);
    verify(chePluginsVolumeApplier).applyVolumes(any(PodData.class), any(Container.class), eq(chePlugin.getContainers().get(0).getVolumes()), eq(internalEnvironment));
}
Also used : InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) Container(io.fabric8.kubernetes.api.model.Container) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) Volume(org.eclipse.che.api.workspace.server.wsplugins.model.Volume) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) Test(org.testng.annotations.Test)

Example 35 with InternalMachineConfig

use of org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig in project devspaces-images by redhat-developer.

the class KubernetesPluginsToolingApplierTest method setsDefaultMemoryLimitForMachineAssociatedWithContainer.

@Test
public void setsDefaultMemoryLimitForMachineAssociatedWithContainer() throws Exception {
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(createChePlugin()));
    InternalMachineConfig machineConfig = getOneAndOnlyNonUserMachine(internalEnvironment);
    String memoryLimitAttribute = machineConfig.getAttributes().get(MEMORY_LIMIT_ATTRIBUTE);
    assertEquals(memoryLimitAttribute, Integer.toString(MEMORY_LIMIT_MB * 1024 * 1024));
}
Also used : InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Test(org.testng.annotations.Test)

Aggregations

InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)88 Test (org.testng.annotations.Test)64 Container (io.fabric8.kubernetes.api.model.Container)36 ChePlugin (org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin)18 PodData (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData)16 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)14 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)12 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)12 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)12 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)10 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)10 Pod (io.fabric8.kubernetes.api.model.Pod)10 Secret (io.fabric8.kubernetes.api.model.Secret)10 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)10 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)10 HashMap (java.util.HashMap)8 CheContainer (org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer)8 Traced (org.eclipse.che.commons.annotation.Traced)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)6 PodSpecBuilder (io.fabric8.kubernetes.api.model.PodSpecBuilder)6