mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ji...@apache.org
Subject [mesos] 07/09: Fixed the CNI_NETNS handling in port mapper CNI plugin.
Date Sat, 12 Jan 2019 01:40:16 GMT
This is an automated email from the ASF dual-hosted git repository.

jieyu pushed a commit to branch 1.5.x
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit d9d8f2178783f77f7a36bccb75f77928ab6febd6
Author: Jie Yu <yujie.jay@gmail.com>
AuthorDate: Thu Jan 10 22:12:02 2019 -0800

    Fixed the CNI_NETNS handling in port mapper CNI plugin.
    
    According CNI spec, it is possible that the container runtime does not
    set CNI_NETNS environment variable when it is not available. This is
    possible in scenarios like a host reboot. In that case, the CNI plugin
    should do best effort cleanup, instead of failing.
    
    Review: https://reviews.apache.org/r/69715
    (cherry picked from commit 594ea4c79f28832e4b40fb0804dca24a7ba11c07)
---
 .../network/cni/plugins/port_mapper/port_mapper.cpp         | 13 +++++++++----
 .../network/cni/plugins/port_mapper/port_mapper.hpp         |  6 +++---
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
index a5216cd..5f05669 100644
--- a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
+++ b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
@@ -16,6 +16,7 @@
 
 #include <stout/os.hpp>
 #include <stout/protobuf.hpp>
+#include <stout/stringify.hpp>
 
 #include <stout/os/which.hpp>
 
@@ -70,9 +71,10 @@ Try<Owned<PortMapper>, PluginError> PortMapper::create(const
string& _cniConfig)
   }
 
   Option<string> cniNetNs = os::getenv("CNI_NETNS");
-  if (cniNetNs.isNone()) {
+  if (cniNetNs.isNone() && cniCommand.get() != spec::CNI_CMD_DEL) {
     return PluginError(
-        "Unable to find environment variable 'CNI_NETNS'",
+        "Unable to find environment variable 'CNI_NETNS' for "
+        "non-'" + stringify(spec::CNI_CMD_DEL) + "' command",
         ERROR_BAD_ARGS);
   }
 
@@ -234,7 +236,7 @@ Try<Owned<PortMapper>, PluginError> PortMapper::create(const
string& _cniConfig)
       new PortMapper(
           cniCommand.get(),
           cniContainerId.get(),
-          cniNetNs.get(),
+          cniNetNs,
           cniIfName.get(),
           cniArgs,
           cniPath.get(),
@@ -525,10 +527,13 @@ Result<spec::NetworkInfo> PortMapper::delegate(const string&
command)
 
   environment["CNI_COMMAND"] = command;
   environment["CNI_IFNAME"] = cniIfName;
-  environment["CNI_NETNS"] = cniNetNs;
   environment["CNI_PATH"] = cniPath;
   environment["CNI_CONTAINERID"] = cniContainerId;
 
+  if (cniNetNs.isSome()) {
+    environment["CNI_NETNS"] = cniNetNs.get();
+  }
+
   if (cniArgs.isSome()) {
     environment["CNI_ARGS"] = cniArgs.get();
   }
diff --git a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.hpp
b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.hpp
index 25f49f4..db51db2 100644
--- a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.hpp
+++ b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.hpp
@@ -100,8 +100,8 @@ protected:
 private:
   PortMapper(
       const std::string& _cniCommand,       // ADD, DEL or VERSION.
-      const std::string& _cniContainerId, // Container ID.
-      const std::string& _cniNetNs,         // Path to network namespace file.
+      const std::string& _cniContainerId,   // Container ID.
+      const Option<std::string>& _cniNetNs, // Path to network namespace file.
       const std::string& _cniIfName,        // Interface name to set up.
       const Option<std::string>& _cniArgs,  // Extra arguments.
       const std::string& _cniPath,          // Paths to search for CNI plugins.
@@ -142,7 +142,7 @@ private:
 
   const std::string cniCommand;
   const std::string cniContainerId;
-  const std::string cniNetNs;
+  const Option<std::string> cniNetNs;
   const std::string cniIfName;
   const Option<std::string> cniArgs;
   const std::string cniPath;


Mime
View raw message