diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplier.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplier.java index 1c9bfbc717..66ff24ef9f 100644 --- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplier.java +++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplier.java @@ -172,6 +172,7 @@ public class DockerimageComponentToWorkspaceApplier implements ComponentToWorksp buildDeployment( machineName, dockerimageComponent.getImage(), + dockerimageComponent.getMemoryRequest(), dockerimageComponent.getMemoryLimit(), dockerimageComponent.getCpuRequest(), dockerimageComponent.getCpuLimit(), @@ -190,6 +191,7 @@ public class DockerimageComponentToWorkspaceApplier implements ComponentToWorksp private Deployment buildDeployment( String name, String image, + String memoryRequest, String memoryLimit, String cpuRequest, String cpuLimit, @@ -207,6 +209,9 @@ public class DockerimageComponentToWorkspaceApplier implements ComponentToWorksp .build(); Containers.addRamLimit(container, memoryLimit); + if (!isNullOrEmpty(memoryRequest)) { + Containers.addRamRequest(container, memoryRequest); + } if (!isNullOrEmpty(cpuRequest)) { Containers.addCpuRequest(container, KubernetesSize.toCores(cpuRequest)); } diff --git a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplierTest.java b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplierTest.java index a90b6f68a9..c422f765e5 100644 --- a/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplierTest.java +++ b/infrastructures/kubernetes/src/test/java/org/eclipse/che/workspace/infrastructure/kubernetes/devfile/DockerimageComponentToWorkspaceApplierTest.java @@ -243,13 +243,14 @@ public class DockerimageComponentToWorkspaceApplierTest { } @Test - public void shouldProvisionContainerWithMemoryLimitSpecified() throws Exception { + public void shouldProvisionContainerWithMemoryResourcesSpecified() 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.setMemoryRequest("128M"); // when dockerimageComponentApplier.apply(workspaceConfig, dockerimageComponent, null); @@ -271,6 +272,10 @@ public class DockerimageComponentToWorkspaceApplierTest { Quantity memoryLimit = container.getResources().getLimits().get("memory"); assertEquals(memoryLimit.getAmount(), "1"); assertEquals(memoryLimit.getFormat(), "G"); + + Quantity memoryRequest = container.getResources().getRequests().get("memory"); + assertEquals(memoryRequest.getAmount(), "128"); + assertEquals(memoryRequest.getFormat(), "M"); } @Test 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 8b5b7db049..e616ea565e 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 @@ -247,46 +247,10 @@ "examples": [ "https://che-plugin-registry.openshift.io/v3/" ] - }, - "memoryLimit": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "integer", - "exclusiveMinimum": 0 - } - ], - "description": "Describes memory limit for the component. You can express memory as a plain integer or as a fixed-point integer using one of these suffixes: E, P, T, G, M, K. You can also use the power-of-two equivalents: Ei, Pi, Ti, Gi, Mi, Ki", - "examples": [ - "128974848", - "129e6", - "129M", - "123Mi" - ] - }, - "memoryRequest": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "integer", - "exclusiveMinimum": 0 - } - ], - "description": "Describes memory request for the component. You can express memory as a plain integer or as a fixed-point integer using one of these suffixes: E, P, T, G, M, K. You can also use the power-of-two equivalents: Ei, Pi, Ti, Gi, Mi, Ki", - "examples": [ - "128974848", - "129e6", - "129M", - "123Mi" - ] - } } } - }, + } + }, { "if": { "properties": { @@ -349,7 +313,7 @@ "{\"java.home\": \"/home/user/jdk11\", \"java.jdt.ls.vmargs\": \"-Xmx1G\"}" ], "additionalProperties": { - "anyOf" : [ + "anyOf": [ { "type": [ "boolean", @@ -500,24 +464,8 @@ "automountWorkspaceSecrets": {}, "volumes": {}, "endpoints": {}, - "memoryLimit": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "integer", - "exclusiveMinimum": 0 - } - ], - "description": "Describes memory limit for the component. You can express memory as a plain integer or as a fixed-point integer using one of these suffixes: E, P, T, G, M, K. You can also use the power-of-two equivalents: Ei, Pi, Ti, Gi, Mi, Ki", - "examples": [ - "128974848", - "129e6", - "129M", - "123Mi" - ] - }, + "memoryLimit": {}, + "memoryRequest": {}, "image": { "type": "string", "description": "Specifies the docker image that should be used for component", @@ -582,6 +530,42 @@ "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" }, + "memoryLimit": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "integer", + "exclusiveMinimum": 0 + } + ], + "description": "Describes memory limit for the component. You can express memory as a plain integer or as a fixed-point integer using one of these suffixes: E, P, T, G, M, K. You can also use the power-of-two equivalents: Ei, Pi, Ti, Gi, Mi, Ki", + "examples": [ + "128974848", + "129e6", + "129M", + "123Mi" + ] + }, + "memoryRequest": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "integer", + "exclusiveMinimum": 0 + } + ], + "description": "Describes memory request for the component. You can express memory as a plain integer or as a fixed-point integer using one of these suffixes: E, P, T, G, M, K. You can also use the power-of-two equivalents: Ei, Pi, Ti, Gi, Mi, Ki", + "examples": [ + "128974848", + "129e6", + "129M", + "123Mi" + ] + }, "cpuLimit": { "anyOf": [ { diff --git a/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component.yaml b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component.yaml index fff43bd2ee..7818082040 100644 --- a/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component.yaml +++ b/wsmaster/che-core-api-workspace/src/test/resources/devfile/schema_test/dockerimage_component/devfile_dockerimage_component.yaml @@ -32,6 +32,7 @@ components: public: 'true' discoverable: 'false' memoryLimit: 1536M + memoryRequest: 512M cpuLimit: 1.5 cpuRequest: 750m command: ['/bin/sh']