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/07/18 16:45:25 UTC

[1/3] mesos git commit: Handled systems that miss /etc/hostname in CNI isolator.

Repository: mesos
Updated Branches:
  refs/heads/master cca92ceac -> f1f3851ef


Handled systems that miss /etc/hostname in CNI isolator.

Review: https://reviews.apache.org/r/50108


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f1f3851e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f1f3851e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f1f3851e

Branch: refs/heads/master
Commit: f1f3851efb41d2869dd7f1ae01247450a4acac2f
Parents: d8665b3
Author: Jie Yu <yu...@gmail.com>
Authored: Fri Jul 15 22:20:19 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Jul 18 09:45:20 2016 -0700

----------------------------------------------------------------------
 .../mesos/isolators/network/cni/cni.cpp         | 28 +++++++++++++-------
 1 file changed, 18 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f1f3851e/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 122e2a8..81121a6 100644
--- a/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
+++ b/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
@@ -660,9 +660,14 @@ Future<Nothing> NetworkCniIsolatorProcess::isolate(
     setup.flags.pid = pid;
     setup.flags.rootfs = infos[containerId]->rootfs;
     setup.flags.etc_hosts_path = "/etc/hosts";
-    setup.flags.etc_hostname_path = "/etc/hostname";
     setup.flags.etc_resolv_conf = "/etc/resolv.conf";
 
+    // NOTE: On some Linux distributions, `/etc/hostname` might not
+    // exist, but hostname is still accessible by `getHostname()`.
+    if (os::exists("/etc/hostname")) {
+      setup.flags.etc_hostname_path = "/etc/hostname";
+    }
+
     return __isolate(setup);
   }
 
@@ -1447,20 +1452,28 @@ int NetworkCniIsolatorSetup::execute()
     return EXIT_FAILURE;
   }
 
+  // Initialize the host path and container path for the set of files
+  // that need to be setup in the container file system.
+  hashmap<string, string> files;
+
   if (flags.etc_hosts_path.isNone()) {
     cerr << "Path to 'hosts' not specified" <<endl;
     return EXIT_FAILURE;
   } else if (!os::exists(flags.etc_hosts_path.get())) {
     cerr << "Unable to find '" << flags.etc_hosts_path.get() << "'" << endl;
     return EXIT_FAILURE;
+  } else {
+    files["/etc/hosts"] = flags.etc_hosts_path.get();
   }
 
   if (flags.etc_hostname_path.isNone()) {
-    cerr << "Path to 'hostname' not specified" << endl;
-    return EXIT_FAILURE;
+    // This is the case where host network is used, container has an
+    // image, and `/etc/hostname` does not exist in the system.
   } else if (!os::exists(flags.etc_hostname_path.get())) {
     cerr << "Unable to find '" << flags.etc_hostname_path.get() << "'" << endl;
     return EXIT_FAILURE;
+  } else {
+    files["/etc/hostname"] = flags.etc_hostname_path.get();
   }
 
   if (flags.etc_resolv_conf.isNone()) {
@@ -1469,6 +1482,8 @@ int NetworkCniIsolatorSetup::execute()
   } else if (!os::exists(flags.etc_resolv_conf.get())) {
     cerr << "Unable to find '" << flags.etc_resolv_conf.get() << "'" << endl;
     return EXIT_FAILURE;
+  } else {
+    files["/etc/resolv.conf"] = flags.etc_resolv_conf.get();
   }
 
   // Enter the mount namespace.
@@ -1502,13 +1517,6 @@ int NetworkCniIsolatorSetup::execute()
     return EXIT_FAILURE;
   }
 
-  // Initialize the host path and container path for the set of files
-  // that need to be setup in the container file system.
-  hashmap<string, string> files;
-  files["/etc/hosts"] = flags.etc_hosts_path.get();
-  files["/etc/hostname"] = flags.etc_hostname_path.get();
-  files["/etc/resolv.conf"] = flags.etc_resolv_conf.get();
-
   foreachpair (const string& file, const string& source, files) {
     // Do the bind mount in the host filesystem since no process in
     // the new network namespace should be seeing the original network


[3/3] mesos git commit: Ignored /etc/* mounts to host filesystems if host network is used.

Posted by ji...@apache.org.
Ignored /etc/* mounts to host filesystems if host network is used.

Review: https://reviews.apache.org/r/50102


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0bf29fac
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0bf29fac
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0bf29fac

Branch: refs/heads/master
Commit: 0bf29fac911912cd89192f01aebd11ba7fc7605d
Parents: cca92ce
Author: Jie Yu <yu...@gmail.com>
Authored: Fri Jul 15 18:37:04 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Jul 18 09:45:20 2016 -0700

----------------------------------------------------------------------
 .../mesos/isolators/network/cni/cni.cpp         | 54 +++++++++++---------
 1 file changed, 30 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0bf29fac/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 11b826e..5360781 100644
--- a/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
+++ b/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
@@ -1515,30 +1515,36 @@ int NetworkCniIsolatorSetup::execute()
     // command executor since command executor will be launched with
     // rootfs of host filesystem and will later pivot to the rootfs of
     // the container filesystem, when launching the task.
-    if (!os::exists(file)) {
-      // Make an exception for `/etc/hostname`, because it may not
-      // exist on every system but hostname is still accessible by
-      // `getHostname()`.
-      if (file != "/etc/hostname") {
-        // NOTE: We just fail if the mount point does not exist on the
-        // host filesystem because we don't want to pollute the host
-        // filesystem.
-        cerr << "Mount point '" << file << "' does not exist "
-             << "on the host filesystem" << endl;
-        return EXIT_FAILURE;
-      }
-    } else {
-      mount = fs::mount(
-          source,
-          file,
-          None(),
-          MS_BIND,
-          nullptr);
-
-      if (mount.isError()) {
-        cerr << "Failed to bind mount from '" << source << "' to '"
-             << file << "': " << mount.error() << endl;
-        return EXIT_FAILURE;
+    //
+    // NOTE: We only need to do this if non host network is used.
+    // Currently, we use `flags.hostname1 to distinguish if a host
+    // network is being used or not.
+    if (flags.hostname.isSome()) {
+      if (!os::exists(file)) {
+        // Make an exception for `/etc/hostname`, because it may not
+        // exist on every system but hostname is still accessible by
+        // `getHostname()`.
+        if (file != "/etc/hostname") {
+          // NOTE: We just fail if the mount point does not exist on
+          // the host filesystem because we don't want to pollute the
+          // host filesystem.
+          cerr << "Mount point '" << file << "' does not exist "
+               << "on the host filesystem" << endl;
+          return EXIT_FAILURE;
+        }
+      } else {
+        mount = fs::mount(
+            source,
+            file,
+            None(),
+            MS_BIND,
+            nullptr);
+
+        if (mount.isError()) {
+          cerr << "Failed to bind mount from '" << source << "' to '"
+               << file << "': " << mount.error() << endl;
+          return EXIT_FAILURE;
+        }
       }
     }
 


[2/3] mesos git commit: Handled /etc/* file being dead links in CNI isolator.

Posted by ji...@apache.org.
Handled /etc/* file being dead links in CNI isolator.

Review: https://reviews.apache.org/r/50107


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d8665b34
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d8665b34
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d8665b34

Branch: refs/heads/master
Commit: d8665b3437e4affab9d2890444b4d162af0b8679
Parents: 0bf29fa
Author: Jie Yu <yu...@gmail.com>
Authored: Fri Jul 15 18:55:01 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Jul 18 09:45:20 2016 -0700

----------------------------------------------------------------------
 .../mesos/isolators/network/cni/cni.cpp         | 24 ++++++++++++++++++++
 1 file changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d8665b34/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 5360781..122e2a8 100644
--- a/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
+++ b/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
@@ -24,6 +24,7 @@
 
 #include <stout/adaptor.hpp>
 #include <stout/os.hpp>
+#include <stout/path.hpp>
 #include <stout/net.hpp>
 
 #include "linux/fs.hpp"
@@ -1551,7 +1552,16 @@ int NetworkCniIsolatorSetup::execute()
     // Do the bind mount in the container filesystem.
     if (flags.rootfs.isSome()) {
       const string target = path::join(flags.rootfs.get(), file);
+
       if (!os::exists(target)) {
+        // Create the parent directory of the mount point.
+        Try<Nothing> mkdir = os::mkdir(Path(target).dirname());
+        if (mkdir.isError()) {
+          cerr << "Failed to create directory '" << Path(target).dirname()
+               << "' for the mount point: " << mkdir.error() << endl;
+          return EXIT_FAILURE;
+        }
+
         // Create the mount point in the container filesystem.
         Try<Nothing> touch = os::touch(target);
         if (touch.isError()) {
@@ -1559,6 +1569,20 @@ int NetworkCniIsolatorSetup::execute()
                << "' in the container filesystem" << endl;
           return EXIT_FAILURE;
         }
+      } else if (os::stat::islink(target)) {
+        Try<Nothing> remove = os::rm(target);
+        if (remove.isError()) {
+          cerr << "Failed to remove '" << target << "' "
+               << "as it's a symbolic link" << endl;
+          return EXIT_FAILURE;
+        }
+
+        Try<Nothing> touch = os::touch(target);
+        if (touch.isError()) {
+          cerr << "Failed to create the mount point '" << target
+               << "' in the container filesystem" << endl;
+          return EXIT_FAILURE;
+        }
       }
 
       mount = fs::mount(