Skip to content

Commit

Permalink
Adding property to set requests for RAM
Browse files Browse the repository at this point in the history
  • Loading branch information
l0rd committed Apr 3, 2017
1 parent e52a5a1 commit 45bfa1a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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();
}
Expand Down Expand Up @@ -260,19 +260,22 @@ public ContainerCreated createContainer(CreateContainerParams createContainerPar

Map<String, String> additionalLabels = createContainerParams.getContainerConfig().getLabels();

String memoryLimit;
if (!isNullOrEmpty(cheWorkspaceMemory)) {
Map<String, Quantity> 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<String, Quantity> resourceRequests = new HashMap<>();
if (!isNullOrEmpty(cheWorkspaceMemoryRequest)) {
resourceRequests.put("memory", new Quantity(cheWorkspaceMemoryRequest));
}
Map<String, Quantity> resourceLimits = new HashMap<>();
resourceLimits.put("memory", new Quantity(memoryLimit));
resourceLimits.put("cpu", new Quantity(cheWorkspaceCpuLimit));

String containerID;
try {
Expand All @@ -283,7 +286,8 @@ public ContainerCreated createContainer(CreateContainerParams createContainerPar
exposedPorts,
envVariables,
volumes,
resourceLimits);
resourceLimits,
resourceRequests);

containerID = waitAndRetrieveContainerID(deploymentName);
if (containerID == null) {
Expand Down Expand Up @@ -1015,7 +1019,8 @@ private String createOpenShiftDeployment(String workspaceID,
Set<String> exposedPorts,
String[] envVariables,
String[] volumes,
Map<String, Quantity> resourceLimits) {
Map<String, Quantity> resourceLimits,
Map<String, Quantity> resourceRequests) {

String deploymentName = CHE_OPENSHIFT_RESOURCES_PREFIX + workspaceID;
LOG.info("Creating OpenShift deployment {}", deploymentName);
Expand Down Expand Up @@ -1044,8 +1049,8 @@ private String createOpenShiftDeployment(String workspaceID,
selector,
command,
false,
resourceLimits);

resourceLimits,
resourceRequests);
try {
waitAndRetrieveContainerID(deploymentName);
} catch (IOException e) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -1107,7 +1113,8 @@ private Deployment createOpenShiftDeploymentInternal(String workspaceID,
String> selector,
String[] command,
boolean withSubpath,
Map<String, Quantity> resourceLimits) {
Map<String, Quantity> resourceLimits,
Map<String, Quantity> resourceRequests) {

Container container = new ContainerBuilder()
.withName(sanitizedContainerName)
Expand All @@ -1123,6 +1130,7 @@ private Deployment createOpenShiftDeploymentInternal(String workspaceID,
.withVolumeMounts(getVolumeMountsFrom(volumes, workspaceID, withSubpath))
.withNewResources()
.withLimits(resourceLimits)
.withRequests(resourceRequests)
.endResources()
.build();

Expand Down

0 comments on commit 45bfa1a

Please sign in to comment.