Add volumes support in cheEditor/chePlugin components

7.20.x
Max Shaposhnik 2020-03-23 17:30:01 +02:00 committed by GitHub
parent 31f562144d
commit 267c9c2dfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 30 deletions

View File

@ -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<String, String> resolveMachineAttributes() {
Map<String, String> attributes = new HashMap<>();

View File

@ -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));
}

View File

@ -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",

View File

@ -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: