From commits-return-25920-archive-asf-public=cust-asf.ponee.io@mesos.apache.org Sat Jan 12 02:40:17 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id E3231180679 for ; Sat, 12 Jan 2019 02:40:16 +0100 (CET) Received: (qmail 49678 invoked by uid 500); 12 Jan 2019 01:40:11 -0000 Mailing-List: contact commits-help@mesos.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mesos.apache.org Delivered-To: mailing list commits@mesos.apache.org Received: (qmail 49662 invoked by uid 99); 12 Jan 2019 01:40:11 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 12 Jan 2019 01:40:11 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id A62A98707C; Sat, 12 Jan 2019 01:40:09 +0000 (UTC) Date: Sat, 12 Jan 2019 01:40:16 +0000 To: "commits@mesos.apache.org" Subject: [mesos] 07/09: Fixed the CNI_NETNS handling in port mapper CNI plugin. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: jieyu@apache.org In-Reply-To: <154725720938.10845.11466550077513052814@gitbox.apache.org> References: <154725720938.10845.11466550077513052814@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: mesos X-Git-Refname: refs/heads/1.5.x X-Git-Reftype: branch X-Git-Rev: d9d8f2178783f77f7a36bccb75f77928ab6febd6 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20190112014009.A62A98707C@gitbox.apache.org> 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 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 #include +#include #include @@ -70,9 +71,10 @@ Try, PluginError> PortMapper::create(const string& _cniConfig) } Option 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, 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 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& _cniNetNs, // Path to network namespace file. const std::string& _cniIfName, // Interface name to set up. const Option& _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 cniNetNs; const std::string cniIfName; const Option cniArgs; const std::string cniPath;