You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/06/23 16:12:55 UTC
[1/3] mesos git commit: Checkpointed CNI network config for container
in the container dir.
Repository: mesos
Updated Branches:
refs/heads/master 87c8c25bb -> 037c85b05
Checkpointed CNI network config for container in the container dir.
Review: https://reviews.apache.org/r/49069/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/af37e581
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/af37e581
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/af37e581
Branch: refs/heads/master
Commit: af37e581abab12aebdd86a5f18709a3547592f0d
Parents: 87c8c25
Author: Qian Zhang <zh...@cn.ibm.com>
Authored: Thu Jun 23 09:12:40 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Jun 23 09:12:40 2016 -0700
----------------------------------------------------------------------
.../mesos/isolators/network/cni/cni.cpp | 36 +++++++-------------
.../mesos/isolators/network/cni/paths.cpp | 11 ++++++
.../mesos/isolators/network/cni/paths.hpp | 8 +++++
3 files changed, 32 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/af37e581/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp b/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
index 3e7c107..74b36ef 100644
--- a/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
+++ b/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
@@ -968,25 +968,20 @@ Future<Nothing> NetworkCniIsolatorProcess::attach(
args.values["org.apache.mesos"] = mesos;
networkConfigJson.values["args"] = args;
- // TODO(jieyu): Checkpoint the network configuration JSON so that we
- // can use the same JSON during cleanup. Currently, we write it to a
- // temporary file.
- Try<std::string> temp = os::mktemp();
- if (temp.isError()) {
- return Failure(
- "Failed to create the temp file for the "
- "CNI network configuration: " + temp.error());
- }
+ // Checkpoint the network configuration JSON. We will use
+ // the same JSON during cleanup.
+ const string networkConfigPath = paths::getNetworkConfigPath(
+ rootDir.get(),
+ containerId.value(),
+ networkName);
- Try<Nothing> write = os::write(
- temp.get(),
- stringify(networkConfigJson));
+ Try<Nothing> write =
+ os::write(networkConfigPath, stringify(networkConfigJson));
if (write.isError()) {
- os::rm(temp.get());
return Failure(
- "Failed to write the CNI network configuration "
- "to the temp file: " + write.error());
+ "Failed to checkpoint the CNI network configuration '" +
+ stringify(networkConfigJson) + "': " + write.error());
}
// Invoke the CNI plugin.
@@ -999,7 +994,7 @@ Future<Nothing> NetworkCniIsolatorProcess::attach(
Try<Subprocess> s = subprocess(
path::join(pluginDir.get(), plugin),
{plugin},
- Subprocess::PATH(temp.get()),
+ Subprocess::PATH(networkConfigPath),
Subprocess::PIPE(),
Subprocess::PATH("/dev/null"),
NO_SETSID,
@@ -1007,7 +1002,6 @@ Future<Nothing> NetworkCniIsolatorProcess::attach(
environment);
if (s.isError()) {
- os::rm(temp.get());
return Failure(
"Failed to execute the CNI plugin '" + plugin + "': " + s.error());
}
@@ -1019,11 +1013,7 @@ Future<Nothing> NetworkCniIsolatorProcess::attach(
containerId,
networkName,
plugin,
- lambda::_1))
- .onAny([temp]() {
- os::rm(temp.get());
- return Nothing();
- });
+ lambda::_1));
}
@@ -1102,7 +1092,7 @@ Future<Nothing> NetworkCniIsolatorProcess::_attach(
Try<Nothing> write = os::write(networkInfoPath, output.get());
if (write.isError()) {
return Failure(
- "Failed to checkpoint the output of CNI plugin'" +
+ "Failed to checkpoint the output of CNI plugin '" +
output.get() + "': " + write.error());
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/af37e581/src/slave/containerizer/mesos/isolators/network/cni/paths.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/network/cni/paths.cpp b/src/slave/containerizer/mesos/isolators/network/cni/paths.cpp
index b3fb0a3..f9056c9 100644
--- a/src/slave/containerizer/mesos/isolators/network/cni/paths.cpp
+++ b/src/slave/containerizer/mesos/isolators/network/cni/paths.cpp
@@ -75,6 +75,17 @@ Try<list<string>> getNetworkNames(
}
+string getNetworkConfigPath(
+ const string& rootDir,
+ const string& containerId,
+ const string& networkName)
+{
+ return path::join(
+ getNetworkDir(rootDir, containerId, networkName),
+ "network.conf");
+}
+
+
string getInterfaceDir(
const string& rootDir,
const string& containerId,
http://git-wip-us.apache.org/repos/asf/mesos/blob/af37e581/src/slave/containerizer/mesos/isolators/network/cni/paths.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/network/cni/paths.hpp b/src/slave/containerizer/mesos/isolators/network/cni/paths.hpp
index 8af50c1..7678a7c 100644
--- a/src/slave/containerizer/mesos/isolators/network/cni/paths.hpp
+++ b/src/slave/containerizer/mesos/isolators/network/cni/paths.hpp
@@ -32,9 +32,11 @@ namespace paths {
// |- <ID of Container1>/
// | |-- ns -> /proc/<pid>/ns/net (bind mount)
// | |-- <Name of CNI network 1>/
+// | | |-- network.conf (JSON file to keep the CNI network configuration)
// | | |-- ifname1/
// | | |-- network.info (JSON file to keep the output of CNI plugin)
// | |-- <Name of CNI network 2>/
+// | | |-- network.conf
// | |-- ifname2/
// | |-- network.info
// |-- <ID of ContainerID 2>/
@@ -59,6 +61,12 @@ Try<list<string>> getNetworkNames(
const string& containerId);
+string getNetworkConfigPath(
+ const string& rootDir,
+ const string& containerId,
+ const string& networkName);
+
+
string getInterfaceDir(
const string& rootDir,
const string& containerId,
[2/3] mesos git commit: Used checkpointed CNI network config during
cleanup.
Posted by ji...@apache.org.
Used checkpointed CNI network config during cleanup.
Review: https://reviews.apache.org/r/49070/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e97df19d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e97df19d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e97df19d
Branch: refs/heads/master
Commit: e97df19d5d97dfff8fe08333b30d1ff4a4a9e4e1
Parents: af37e58
Author: Qian Zhang <zh...@cn.ibm.com>
Authored: Thu Jun 23 09:12:43 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Jun 23 09:12:43 2016 -0700
----------------------------------------------------------------------
.../mesos/isolators/network/cni/cni.cpp | 22 +++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/e97df19d/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp b/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
index 74b36ef..92b3311 100644
--- a/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
+++ b/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
@@ -988,8 +988,9 @@ Future<Nothing> NetworkCniIsolatorProcess::attach(
const string& plugin = networkConfig.config.type();
VLOG(1) << "Invoking CNI plugin '" << plugin
- << "' with network configuration '"
- << stringify(networkConfigJson) << "'";
+ << "' with network configuration '" << stringify(networkConfigJson)
+ << "' to attach container " << containerId << " to network '"
+ << networkName << "'";
Try<Subprocess> s = subprocess(
path::join(pluginDir.get(), plugin),
@@ -1265,14 +1266,25 @@ Future<Nothing> NetworkCniIsolatorProcess::detach(
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
}
- const NetworkConfigInfo& networkConfig = networkConfigs[networkName];
+ // Use the checkpointed CNI network configuration to call the
+ // CNI plugin to detach the container from the CNI network.
+ const string networkConfigPath = paths::getNetworkConfigPath(
+ rootDir.get(),
+ containerId.value(),
+ networkName);
// Invoke the CNI plugin.
- const string& plugin = networkConfig.config.type();
+ const string& plugin = networkConfigs[networkName].config.type();
+
+ VLOG(1) << "Invoking CNI plugin '" << plugin
+ << "' with network configuration '" << networkConfigPath
+ << "' to detach container " << containerId << " from network '"
+ << networkName << "'";
+
Try<Subprocess> s = subprocess(
path::join(pluginDir.get(), plugin),
{plugin},
- Subprocess::PATH(networkConfig.path),
+ Subprocess::PATH(networkConfigPath),
Subprocess::PIPE(),
Subprocess::PATH("/dev/null"),
NO_SETSID,
[3/3] mesos git commit: Updated CNI test to verify the checkpointed
CNI network config.
Posted by ji...@apache.org.
Updated CNI test to verify the checkpointed CNI network config.
Review: https://reviews.apache.org/r/49071/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/037c85b0
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/037c85b0
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/037c85b0
Branch: refs/heads/master
Commit: 037c85b057c15892967c4b2c05091f94f2f854cb
Parents: e97df19
Author: Qian Zhang <zh...@cn.ibm.com>
Authored: Thu Jun 23 09:12:46 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Jun 23 09:12:46 2016 -0700
----------------------------------------------------------------------
src/tests/containerizer/cni_isolator_tests.cpp | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/037c85b0/src/tests/containerizer/cni_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/cni_isolator_tests.cpp b/src/tests/containerizer/cni_isolator_tests.cpp
index 6367e6a..991823b 100644
--- a/src/tests/containerizer/cni_isolator_tests.cpp
+++ b/src/tests/containerizer/cni_isolator_tests.cpp
@@ -310,6 +310,9 @@ TEST_F(CniIsolatorTest, ROOT_VerifyCheckpointedInfo)
EXPECT_TRUE(os::exists(paths::getNetworkDir(
paths::ROOT_DIR, containerId.value(), "__MESOS_TEST__")));
+ EXPECT_TRUE(os::exists(paths::getNetworkConfigPath(
+ paths::ROOT_DIR, containerId.value(), "__MESOS_TEST__")));
+
EXPECT_TRUE(os::exists(paths::getInterfaceDir(
paths::ROOT_DIR, containerId.value(), "__MESOS_TEST__", "eth0")));