Adds a /workspace-logs folder linked to the persistent volume

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>
6.19.x
Florent BENOIT 2017-07-17 16:55:38 +02:00
parent 8611c99870
commit 4e872e0ed4
2 changed files with 28 additions and 5 deletions

View File

@ -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";
@ -1489,7 +1491,16 @@ public class OpenShiftConnector extends DockerConnector {
.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;

View File

@ -37,6 +37,9 @@ import java.util.List;
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.
@ -104,12 +107,21 @@ public class OpenShiftPvcHelper {
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()
@ -126,8 +138,8 @@ public class OpenShiftPvcHelper {
.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));
@ -169,7 +181,7 @@ public class OpenShiftPvcHelper {
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);