Skip to content

Commit

Permalink
Adds a /workspace-logs folder linked to the persistent volume
Browse files Browse the repository at this point in the history
Each pod has a dedicated folder matching the workspace id

for the project's source, it is currently using :

/projects ---> <PV>/<workspace-name>

and for the logs it's now using as well
/workspace-logs ---> <PR>/<workspace-name>-logs/

example : /workspace-logs/dev-machine-ws-agent/logs/catalina.log  for the log of the dev-machine workspace agent.

Change-Id: I2b9d533ba3df2cf55857d8c30d2de5df463a5902
Signed-off-by: Florent BENOIT <fbenoit@redhat.com>
  • Loading branch information
benoitf committed Jul 18, 2017
1 parent 8611c99 commit 4e872e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ public class OpenShiftConnector extends DockerConnector {
private static final Logger LOG = LoggerFactory.getLogger(OpenShiftConnector.class);
public static final String CHE_OPENSHIFT_RESOURCES_PREFIX = "che-ws-";
public static final String OPENSHIFT_DEPLOYMENT_LABEL = "deployment";
public static final String CHE_MOUNTED_WORKSPACE_FOLDER = "/workspace-logs";
public static final String WORKSPACE_LOGS_FOLDER_SUFFIX = "-logs";

private static final String CHE_CONTAINER_IDENTIFIER_LABEL_KEY = "cheContainerIdentifier";
private static final String CHE_DEFAULT_EXTERNAL_ADDRESS = "172.17.0.1";
Expand Down Expand Up @@ -1489,7 +1491,16 @@ private List<VolumeMount> getVolumeMountsFrom(String[] volumes) {
.withName(workspacesPersistentVolumeClaim)
.withSubPath(subPath)
.build();

// add a mount from PVC for the logs
VolumeMount logsVm = new VolumeMountBuilder()
.withMountPath(CHE_MOUNTED_WORKSPACE_FOLDER)
.withName(workspacesPersistentVolumeClaim)
.withSubPath(subPath + WORKSPACE_LOGS_FOLDER_SUFFIX)
.build();

vms.add(vm);
vms.add(logsVm);
}
}
return vms;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import static org.eclipse.che.plugin.openshift.client.OpenShiftConnector.WORKSPACE_LOGS_FOLDER_SUFFIX;

/**
* Helper class for executing simple commands in a Persistent Volume on Openshift.
Expand Down Expand Up @@ -104,12 +107,21 @@ protected boolean createJobPod(String workspacesPvcName,
return true;
}

List<String> logsDirs = Arrays.asList(workspaceDirs);
logsDirs = logsDirs.stream().map(dir -> dir + WORKSPACE_LOGS_FOLDER_SUFFIX).collect(Collectors.toList());

List<String> allDirs = new ArrayList<>();
allDirs.addAll(Arrays.asList(workspaceDirs));
allDirs.addAll(logsDirs);
String[] allDirsArray = allDirs.toArray(new String[allDirs.size()]);


if (Command.MAKE.equals(command)) {
String[] dirsToCreate = filterDirsToCreate(workspaceDirs);
String[] dirsToCreate = filterDirsToCreate(allDirsArray);
if (dirsToCreate.length == 0) {
return true;
}
workspaceDirs = dirsToCreate;
allDirsArray = dirsToCreate;
}

VolumeMount vm = new VolumeMountBuilder()
Expand All @@ -126,8 +138,8 @@ protected boolean createJobPod(String workspacesPvcName,
.withName(workspacesPvcName)
.build();

String[] jobCommand = getCommand(command, "/projects/", workspaceDirs);
LOG.info("Executing command {} in PVC {} for {} dirs", jobCommand[0], workspacesPvcName, workspaceDirs.length);
String[] jobCommand = getCommand(command, "/projects/", allDirsArray);
LOG.info("Executing command {} in PVC {} for {} dirs", jobCommand[0], workspacesPvcName, allDirs.size());

Map<String, Quantity> limit = Collections.singletonMap("memory", new Quantity(jobMemoryLimit));

Expand Down Expand Up @@ -169,7 +181,7 @@ protected boolean createJobPod(String workspacesPvcName,
LOG.info("Pod command {} failed", Arrays.toString(jobCommand));
case POD_PHASE_SUCCEEDED:
openShiftClient.resource(pod).delete();
updateCreatedDirs(command, phase, workspaceDirs);
updateCreatedDirs(command, phase, allDirsArray);
return POD_PHASE_SUCCEEDED.equals(phase);
default:
Thread.sleep(1000);
Expand Down

0 comments on commit 4e872e0

Please sign in to comment.