Repository: mesos
Updated Branches:
  refs/heads/master 6f98b8d6d -> 7b5b728da


Allows port mapper plugin to have optional args.

Mesos port mapper cni plugin is a wrapper around bridge plugin
to add port mapping functionality to bridge plugin. However, in
certain cases the network creator doesn't need port mapping
functionality and just want to access bridge plugin. In this case,
the creator may not supply `args` in cni config which will make
mesos port mapper plugin to fail. This patch makes `args` in cni
config optional for mesos port mapper plugin.

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


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

Branch: refs/heads/master
Commit: 7b5b728da41e0ebecca50a43cba80e680bebb37e
Parents: 6f98b8d
Author: Deepak Goel <deepak.go...@gmail.com>
Authored: Wed Sep 6 09:53:20 2017 +0800
Committer: Qian Zhang <zhq527...@gmail.com>
Committed: Wed Sep 6 10:03:40 2017 +0800

----------------------------------------------------------------------
 .../cni/plugins/port_mapper/port_mapper.cpp        | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/7b5b728d/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
----------------------------------------------------------------------
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 43cf3e4..de64d65 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
@@ -140,13 +140,20 @@ Try<Owned<PortMapper>, PluginError> 
PortMapper::create(const string& _cniConfig)
 
   // While the 'args' field is optional in the CNI spec it is critical
   // to the port-mapper plugin to learn of any port-mappings that the
-  // framework might have requested for this container.
+  // framework might have requested for this container when this plugin
+  // is called in the Mesos context. However, to make the port-mapper
+  // plugin more generic rather than Mesos specific, we will create a
+  // fake 'args` field if it is not filled by the caller.
   Result<JSON::Object> args = cniConfig->find<JSON::Object>("args");
-  if (!args.isSome()) {
+  if (args.isError()) {
     return PluginError(
-        "Failed to get the required field 'args': " +
-        (args.isError() ? args.error() : "Not found"),
-        ERROR_BAD_ARGS);
+        "Failed to get the field 'args': " + args.error(), ERROR_BAD_ARGS);
+  } else if (args.isNone()) {
+    JSON::Object _args;
+    JSON::Object mesos;
+    mesos.values["network_info"] = JSON::Object();
+    _args.values["org.apache.mesos"] = mesos;
+    args = _args;
   }
 
   // NOTE: We can't directly use `find` to check for 'network_info'

Reply via email to