diff --git a/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/codenvy/che.properties b/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/codenvy/che.properties index 0b96f0457c04..904966801713 100644 --- a/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/codenvy/che.properties +++ b/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/codenvy/che.properties @@ -294,8 +294,10 @@ che.openshift.liveness.probe.delay=300 che.openshift.liveness.probe.timeout=1 che.openshift.workspaces.pvc.name=claim-che-workspace che.openshift.workspaces.pvc.quantity=10Gi -che.openshift.workspace.cpu.limit=1 -# Override memory limit used for openshift workspaces. String, e.g. 1300Mi +# The amount of memory required for a workspace container to run e.g. 512Mi +che.openshift.workspace.memory.request=NULL +# The max amount of memory the container can use. +# Overrides memory limit used for openshift workspaces. String, e.g. 1.3Gi che.openshift.workspace.memory.override=NULL # Which implementation of DockerConnector to use in managing containers. In general, diff --git a/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/OpenShiftConnector.java b/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/OpenShiftConnector.java index d7599f148e76..287180ff04e1 100644 --- a/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/OpenShiftConnector.java +++ b/plugins/plugin-docker/che-plugin-openshift-client/src/main/java/org/eclipse/che/plugin/openshift/client/OpenShiftConnector.java @@ -170,8 +170,8 @@ public class OpenShiftConnector extends DockerConnector { private final String cheWorkspaceStorage; private final String cheWorkspaceProjectsStorage; private final String cheServerExternalAddress; - private final String cheWorkspaceCpuLimit; - private final String cheWorkspaceMemory; + private final String cheWorkspaceMemoryLimit; + private final String cheWorkspaceMemoryRequest; @Inject public OpenShiftConnector(DockerConnectorConfiguration connectorConfiguration, @@ -186,8 +186,8 @@ public OpenShiftConnector(DockerConnectorConfiguration connectorConfiguration, @Named("che.openshift.workspaces.pvc.quantity") String workspacesPvcQuantity, @Named("che.workspace.storage") String cheWorkspaceStorage, @Named("che.workspace.projects.storage") String cheWorkspaceProjectsStorage, - @Named("che.openshift.workspace.cpu.limit") String cheWorkspaceCpuLimit, - @Nullable @Named("che.openshift.workspace.memory.override") String cheWorkspaceMemory) { + @Nullable @Named("che.openshift.workspace.memory.request") String cheWorkspaceMemoryRequest, + @Nullable @Named("che.openshift.workspace.memory.override") String cheWorkspaceMemoryLimit) { super(connectorConfiguration, connectionFactory, authResolver, dockerApiVersionPathPrefixProvider); @@ -199,8 +199,8 @@ public OpenShiftConnector(DockerConnectorConfiguration connectorConfiguration, this.workspacesPvcQuantity = workspacesPvcQuantity; this.cheWorkspaceStorage = cheWorkspaceStorage; this.cheWorkspaceProjectsStorage = cheWorkspaceProjectsStorage; - this.cheWorkspaceCpuLimit = cheWorkspaceCpuLimit; - this.cheWorkspaceMemory = cheWorkspaceMemory; + this.cheWorkspaceMemoryRequest = cheWorkspaceMemoryRequest; + this.cheWorkspaceMemoryLimit = cheWorkspaceMemoryLimit; this.openShiftClient = new DefaultOpenShiftClient(); } @@ -260,19 +260,22 @@ public ContainerCreated createContainer(CreateContainerParams createContainerPar Map additionalLabels = createContainerParams.getContainerConfig().getLabels(); - String memoryLimit; - if (!isNullOrEmpty(cheWorkspaceMemory)) { + Map resourceLimits = new HashMap<>(); + if (!isNullOrEmpty(cheWorkspaceMemoryLimit)) { LOG.info("Che property 'che.openshift.workspace.memory.override' " - + "used to override workspace memory limit to {}.", cheWorkspaceMemory); - memoryLimit = cheWorkspaceMemory; + + "used to override workspace memory limit to {}.", cheWorkspaceMemoryLimit); + resourceLimits.put("memory", new Quantity(cheWorkspaceMemoryLimit)); } else { long memoryLimitBytes = createContainerParams.getContainerConfig().getHostConfig().getMemory(); - memoryLimit = Long.toString(memoryLimitBytes / 1048576) + "Mi"; + String memoryLimit = Long.toString(memoryLimitBytes / 1048576) + "Mi"; LOG.info("Creating workspace pod with memory limit of {}.", memoryLimit); + resourceLimits.put("memory", new Quantity(cheWorkspaceMemoryLimit)); + } + + Map resourceRequests = new HashMap<>(); + if (!isNullOrEmpty(cheWorkspaceMemoryRequest)) { + resourceRequests.put("memory", new Quantity(cheWorkspaceMemoryRequest)); } - Map resourceLimits = new HashMap<>(); - resourceLimits.put("memory", new Quantity(memoryLimit)); - resourceLimits.put("cpu", new Quantity(cheWorkspaceCpuLimit)); String containerID; try { @@ -283,7 +286,8 @@ public ContainerCreated createContainer(CreateContainerParams createContainerPar exposedPorts, envVariables, volumes, - resourceLimits); + resourceLimits, + resourceRequests); containerID = waitAndRetrieveContainerID(deploymentName); if (containerID == null) { @@ -1015,7 +1019,8 @@ private String createOpenShiftDeployment(String workspaceID, Set exposedPorts, String[] envVariables, String[] volumes, - Map resourceLimits) { + Map resourceLimits, + Map resourceRequests) { String deploymentName = CHE_OPENSHIFT_RESOURCES_PREFIX + workspaceID; LOG.info("Creating OpenShift deployment {}", deploymentName); @@ -1044,8 +1049,8 @@ private String createOpenShiftDeployment(String workspaceID, selector, command, false, - resourceLimits); - + resourceLimits, + resourceRequests); try { waitAndRetrieveContainerID(deploymentName); } catch (IOException e) { @@ -1070,7 +1075,8 @@ private String createOpenShiftDeployment(String workspaceID, selector, null, true, - resourceLimits); + resourceLimits, + resourceRequests); LOG.info("OpenShift deployment {} created", deploymentName); return deployment.getMetadata().getName(); } @@ -1107,7 +1113,8 @@ private Deployment createOpenShiftDeploymentInternal(String workspaceID, String> selector, String[] command, boolean withSubpath, - Map resourceLimits) { + Map resourceLimits, + Map resourceRequests) { Container container = new ContainerBuilder() .withName(sanitizedContainerName) @@ -1123,6 +1130,7 @@ private Deployment createOpenShiftDeploymentInternal(String workspaceID, .withVolumeMounts(getVolumeMountsFrom(volumes, workspaceID, withSubpath)) .withNewResources() .withLimits(resourceLimits) + .withRequests(resourceRequests) .endResources() .build();