Skip to content

Commit

Permalink
Gh17540 memory request dockerimage (eclipse-che#18592)
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Vala <mvala@redhat.com>
  • Loading branch information
sparkoo authored Dec 11, 2020
1 parent d32c830 commit 6c987da
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ private List<HasMetadata> createComponentObjects(
buildDeployment(
machineName,
dockerimageComponent.getImage(),
dockerimageComponent.getMemoryRequest(),
dockerimageComponent.getMemoryLimit(),
dockerimageComponent.getCpuRequest(),
dockerimageComponent.getCpuLimit(),
Expand All @@ -190,6 +191,7 @@ private List<HasMetadata> createComponentObjects(
private Deployment buildDeployment(
String name,
String image,
String memoryRequest,
String memoryLimit,
String cpuRequest,
String cpuLimit,
Expand All @@ -207,6 +209,9 @@ private Deployment buildDeployment(
.build();

Containers.addRamLimit(container, memoryLimit);
if (!isNullOrEmpty(memoryRequest)) {
Containers.addRamRequest(container, memoryRequest);
}
if (!isNullOrEmpty(cpuRequest)) {
Containers.addCpuRequest(container, KubernetesSize.toCores(cpuRequest));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,14 @@ public void shouldProvisionSpecifiedEnvVars() throws Exception {
}

@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);
Expand All @@ -271,6 +272,10 @@ public void shouldProvisionContainerWithMemoryLimitSpecified() throws Exception
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -349,7 +313,7 @@
"{\"java.home\": \"/home/user/jdk11\", \"java.jdt.ls.vmargs\": \"-Xmx1G\"}"
],
"additionalProperties": {
"anyOf" : [
"anyOf": [
{
"type": [
"boolean",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ components:
public: 'true'
discoverable: 'false'
memoryLimit: 1536M
memoryRequest: 512M
cpuLimit: 1.5
cpuRequest: 750m
command: ['/bin/sh']
Expand Down

0 comments on commit 6c987da

Please sign in to comment.