use of org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldThrowExceptionWhenDevfileVolumeNameExists.
@Test(expectedExceptions = DevfileException.class, expectedExceptionsMessageRegExp = "Conflicting volume with same name \\('foo_volume'\\) but different path \\('/foo1'\\) found for component 'foo' and its container 'server'.")
public void shouldThrowExceptionWhenDevfileVolumeNameExists() throws Exception {
// given
String yamlRecipeContent = getResource("devfile/petclinic.yaml");
List<HasMetadata> k8sList = toK8SList(yamlRecipeContent).getItems();
doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
component.setVolumes(Collections.singletonList(new VolumeImpl("foo_volume", "/foo1")));
// when
applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl in project che-server by eclipse-che.
the class DockerimageComponentToWorkspaceApplierTest method shouldProvisionMachineConfigWithConfiguredVolumes.
@Test
public void shouldProvisionMachineConfigWithConfiguredVolumes() throws Exception {
// given
ComponentImpl dockerimageComponent = new ComponentImpl();
dockerimageComponent.setAlias("jdk");
dockerimageComponent.setType(DOCKERIMAGE_COMPONENT_TYPE);
dockerimageComponent.setImage("eclipse/ubuntu_jdk8:latest");
dockerimageComponent.setMemoryLimit("1G");
dockerimageComponent.setVolumes(singletonList(new VolumeImpl("data", "/tmp/data/")));
// when
dockerimageComponentApplier.apply(workspaceConfig, dockerimageComponent, null);
// then
verify(k8sEnvProvisioner).provision(eq(workspaceConfig), eq(KubernetesEnvironment.TYPE), objectsCaptor.capture(), machinesCaptor.capture());
MachineConfigImpl machineConfig = machinesCaptor.getValue().get("jdk");
assertNotNull(machineConfig);
org.eclipse.che.api.workspace.server.model.impl.VolumeImpl volume = machineConfig.getVolumes().get("data");
assertNotNull(volume);
assertEquals(volume.getPath(), "/tmp/data/");
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl in project che-server by eclipse-che.
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());
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl 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());
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl in project devspaces-images by redhat-developer.
the class KubernetesComponentToWorkspaceApplierTest method shouldProvisionDevfileVolumesIfSpecifiedIntoMachineConfig.
@Test
public void shouldProvisionDevfileVolumesIfSpecifiedIntoMachineConfig() throws Exception {
// given
String yamlRecipeContent = getResource("devfile/petclinic.yaml");
List<HasMetadata> k8sList = toK8SList(yamlRecipeContent).getItems();
doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
component.setVolumes(asList(new VolumeImpl("foo", "/foo1"), new VolumeImpl("bar", "/bar1")));
ArgumentCaptor<Map<String, MachineConfigImpl>> mapCaptor = ArgumentCaptor.forClass(Map.class);
// when
applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
// then
verify(k8sEnvProvisioner).provision(any(), any(), any(), mapCaptor.capture());
Map<String, MachineConfigImpl> configMaps = mapCaptor.getValue();
for (MachineConfig config : configMaps.values()) {
assertEquals(config.getVolumes().size(), 2);
assertTrue(config.getVolumes().entrySet().stream().anyMatch(entry -> entry.getKey().equals("foo") && entry.getValue().getPath().equals("/foo1")));
assertTrue(config.getVolumes().entrySet().stream().anyMatch(entry -> entry.getKey().equals("bar") && entry.getValue().getPath().equals("/bar1")));
}
}
Aggregations