diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/MachineResolver.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/MachineResolver.java index 0b55991013..659589db5d 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/MachineResolver.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/MachineResolver.java @@ -81,12 +81,20 @@ public class MachineResolver { emptyMap(), resolveMachineAttributes(), toWorkspaceVolumes(cheContainer)); - + applyDevfileVolumes(machineConfig); normalizeMemory(container, machineConfig); normalizeCpu(container, machineConfig); return machineConfig; } + private void applyDevfileVolumes(InternalMachineConfig machineConfig) { + for (org.eclipse.che.api.core.model.workspace.devfile.Volume volume : component.getVolumes()) { + machineConfig + .getVolumes() + .put(volume.getName(), new VolumeImpl().withPath(volume.getContainerPath())); + } + } + private Map resolveMachineAttributes() { Map attributes = new HashMap<>(); diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/MachineResolverTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/MachineResolverTest.java index c08d4d7946..ca166b5f65 100644 --- a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/MachineResolverTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/wsplugins/MachineResolverTest.java @@ -277,6 +277,22 @@ public class MachineResolverTest { PROJECTS_MOUNT_PATH, config.getVolumes().get(Constants.PROJECTS_VOLUME_NAME).getPath()); } + @Test + public void shouldAddVolumesFromDevfileComponent() throws InfrastructureException { + + component.setVolumes( + asList( + new org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl("foo", "/bar"), + new org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl( + "test", "/foo/test"))); + + InternalMachineConfig config = resolver.resolve(); + + assertEquals(2, config.getVolumes().size()); + assertEquals("/bar", config.getVolumes().get("foo").getPath()); + assertEquals("/foo/test", config.getVolumes().get("test").getPath()); + } + private static String toBytesString(String k8sMemorySize) { return Long.toString(KubernetesSize.toBytes(k8sMemorySize)); } diff --git a/wsmaster/che-core-api-workspace/src/main/resources/schema/1.0.0/devfile.json b/wsmaster/che-core-api-workspace/src/main/resources/schema/1.0.0/devfile.json index 05f30aa715..181c3da50f 100644 --- a/wsmaster/che-core-api-workspace/src/main/resources/schema/1.0.0/devfile.json +++ b/wsmaster/che-core-api-workspace/src/main/resources/schema/1.0.0/devfile.json @@ -340,6 +340,7 @@ "alias": {}, "id": {}, "env": {}, + "volumes": {}, "reference": {}, "registryUrl": {}, "memoryLimit": {}, @@ -366,6 +367,7 @@ "alias": {}, "id": {}, "env": {}, + "volumes": {}, "memoryLimit": {}, "memoryRequest": {}, "cpuLimit": {}, @@ -508,6 +510,7 @@ "alias": {}, "mountSources": {}, "env": {}, + "volumes": {}, "memoryLimit": { "anyOf": [ { @@ -555,35 +558,6 @@ "['-R', '-f']" ] }, - "volumes": { - "type": "array", - "description": "Describes volumes which should be mount to component", - "items": { - "type": "object", - "description": "Describe volume that should be mount to component", - "required": [ - "name", - "containerPath" - ], - "properties": { - "name": { - "type": "string", - "title": "The Volume Name", - "description": "The volume name. If several components mount the same volume then they will reuse the volume and will be able to access to the same files", - "examples": [ - "my-data" - ] - }, - "containerPath": { - "type": "string", - "title": "The path where volume should be mount to container", - "examples": [ - "/home/user/data" - ] - } - } - } - }, "endpoints": { "type": "array", "description": "Describes dockerimage component endpoints", @@ -669,6 +643,35 @@ "description": "Describes whether projects sources should be mount to the component. `CHE_PROJECTS_ROOT` environment variable should contains a path where projects sources are mount", "default": "false" }, + "volumes": { + "type": "array", + "description": "Describes volumes which should be mount to component", + "items": { + "type": "object", + "description": "Describe volume that should be mount to component", + "required": [ + "name", + "containerPath" + ], + "properties": { + "name": { + "type": "string", + "title": "The Volume Name", + "description": "The volume name. If several components mount the same volume then they will reuse the volume and will be able to access to the same files", + "examples": [ + "my-data" + ] + }, + "containerPath": { + "type": "string", + "title": "The path where volume should be mount to container", + "examples": [ + "/home/user/data" + ] + } + } + } + }, "env": { "type": "array", "description": "The environment variables list that should be set to docker container", diff --git a/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_plugins.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_plugins.yaml index 7c7373bb12..08672c5d33 100644 --- a/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_plugins.yaml +++ b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/editor_plugin_component/devfile_editor_plugins.yaml @@ -25,6 +25,9 @@ components: env: - name: ENV_VAR value: value + volumes: + - name: maven-repo + containerPath: /root/.m2 - alias: mvn-stack type: chePlugin id: eclipse/chemaven-jdk8/1.0.0 @@ -33,6 +36,9 @@ components: env: - name: ENV_VAR value: value + volumes: + - name: maven-repo + containerPath: /root/.m2 commands: - name: build actions: