You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2017/05/11 10:16:51 UTC
[10/11] mesos git commit: Set the working directory to parent task's
for DEBUG containers.
Set the working directory to parent task's for DEBUG containers.
A DEBUG container's working directory should be set to the parent
task's working directory. For the command executor case, even if
the task itself has a root filesystem, the executor container still
uses the host filesystem, hence
`ContainerLaunchInfo.working_directory`, pointing to the executor's
working directory in the host filesystem, may be different from the
task's working directory in the root filesystem.
Review: https://reviews.apache.org/r/58967
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9bbcbf20
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9bbcbf20
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9bbcbf20
Branch: refs/heads/master
Commit: 9bbcbf20284ceb806e03149bad038fb9ff2d9f34
Parents: 4708694
Author: Alexander Rukletsov <al...@apache.org>
Authored: Wed May 3 15:46:31 2017 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Thu May 11 12:15:55 2017 +0200
----------------------------------------------------------------------
include/mesos/slave/containerizer.proto | 4 ++
src/slave/containerizer/mesos/containerizer.cpp | 51 ++++++++++++++++++--
2 files changed, 52 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/9bbcbf20/include/mesos/slave/containerizer.proto
----------------------------------------------------------------------
diff --git a/include/mesos/slave/containerizer.proto b/include/mesos/slave/containerizer.proto
index 23c179f..0f96334 100644
--- a/include/mesos/slave/containerizer.proto
+++ b/include/mesos/slave/containerizer.proto
@@ -188,6 +188,10 @@ message ContainerLaunchInfo {
// it is set to container sandbox, i.e., Mesos sandbox, unless one of
// the isolators overrides it *and* the container defines an image.
// DEBUG containers inherit working directory from their parent.
+ //
+ // NOTE: For the command executor case, this points to the executor
+ // working directory in the host filesystem, which may be different
+ // from the task working directory when task defines an image.
optional string working_directory = 6;
// (Linux only) The capabilities requested for the container.
http://git-wip-us.apache.org/repos/asf/mesos/blob/9bbcbf20/src/slave/containerizer/mesos/containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/containerizer.cpp b/src/slave/containerizer/mesos/containerizer.cpp
index 9b28b4f..97837c8 100644
--- a/src/slave/containerizer/mesos/containerizer.cpp
+++ b/src/slave/containerizer/mesos/containerizer.cpp
@@ -1499,23 +1499,68 @@ Future<bool> MesosContainerizerProcess::_launch(
// For a non-DEBUG container, working directory is set to container sandbox,
// i.e., MESOS_SANDBOX, unless one of the isolators overrides it. DEBUG
- // containers set their working directory to their parent working directory.
+ // containers set their working directory to their parent working directory,
+ // with the command executor being a special case (see below).
+ //
+ // TODO(alexr): Determining working directory is a convoluted process. We
+ // should either simplify the logic or extract it into a helper routine.
if (container->config.has_container_class() &&
container->config.container_class() == ContainerClass::DEBUG) {
// DEBUG containers must have a parent.
CHECK(containerId.has_parent());
if (containers_[containerId.parent()]->launchInfo.isSome()) {
- launchInfo.set_working_directory(
- containers_[containerId.parent()]->launchInfo->working_directory());
+ // TODO(alexr): Remove this once we no longer support executorless
+ // command tasks in favor of default executor.
+ if (containers_[containerId.parent()]->config.has_task_info()) {
+ // For the command executor case, even if the task itself has a root
+ // filesystem, the executor container still uses the host filesystem,
+ // hence `ContainerLaunchInfo.working_directory`, which points to the
+ // executor working directory in the host filesystem, may be different
+ // from the task working directory when task defines an image. Fall back
+ // to the sandbox directory if task working directory is not present.
+ if (containers_[containerId.parent()]->config.has_rootfs()) {
+ // We can extract the task working directory from the flag being
+ // passed to the command executor.
+ foreach (
+ const string& flag,
+ containers_[containerId.parent()]
+ ->launchInfo->command().arguments()) {
+ if (strings::startsWith(flag, "--working_directory=")) {
+ launchInfo.set_working_directory(strings::remove(
+ flag, "--working_directory=", strings::PREFIX));
+ break;
+ }
+ }
+
+ // If "--working_directory" argument is not found, default to the
+ // sandbox directory.
+ if (!launchInfo.has_working_directory()) {
+ launchInfo.set_working_directory(flags.sandbox_directory);
+ }
+ } else {
+ // Parent is command executor, but the task does not define an image.
+ launchInfo.set_working_directory(containers_[containerId.parent()]
+ ->launchInfo->working_directory());
+ }
+ } else {
+ // Parent is a non-command task.
+ launchInfo.set_working_directory(
+ containers_[containerId.parent()]->launchInfo->working_directory());
+ }
} else {
+ // Working directory cannot be determined, because
+ // parent working directory is unknown.
launchInfo.clear_working_directory();
}
} else if (launchInfo.has_rootfs()) {
+ // Non-DEBUG container which defines an image.
if (!launchInfo.has_working_directory()) {
launchInfo.set_working_directory(flags.sandbox_directory);
}
} else {
+ // Non-DEBUG container which does not define an image.
+ //
// NOTE: If the container shares the host filesystem, we should
// not allow them to 'cd' into an arbitrary directory because
// that'll create security issues.