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 2017/06/16 00:11:39 UTC

[3/3] mesos git commit: Added `MESOS_CONTAINER_IP` to tasks launched by `DefaultExecutor`.

Added `MESOS_CONTAINER_IP` to tasks launched by `DefaultExecutor`.

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


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

Branch: refs/heads/master
Commit: 39be533337b58ee1a68dcd0e8d89b4776e38fa34
Parents: 20e1c74
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Thu Jun 15 14:25:12 2017 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Jun 15 17:11:33 2017 -0700

----------------------------------------------------------------------
 src/launcher/default_executor.cpp | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/39be5333/src/launcher/default_executor.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/default_executor.cpp b/src/launcher/default_executor.cpp
index 91a4e1e..c25cc94 100644
--- a/src/launcher/default_executor.cpp
+++ b/src/launcher/default_executor.cpp
@@ -81,6 +81,9 @@ using std::vector;
 namespace mesos {
 namespace internal {
 
+constexpr char MESOS_CONTAINER_IP[] = "MESOS_CONTAINER_IP";
+
+
 class DefaultExecutor : public ProtobufProcess<DefaultExecutor>
 {
 private:
@@ -366,6 +369,26 @@ protected:
     CHECK_EQ(SUBSCRIBED, state);
     CHECK_SOME(executorContainerId);
 
+    // Determine the container IP in order to set `MESOS_CONTAINER_IP`
+    // environment variable for each of the tasks being launched.
+    // Libprocess has already determined the IP address associated
+    // with this container network namespace in `process::initialize`
+    // and hence we can just use the IP assigned to the PID of this
+    // process as the IP address of the container.
+    //
+    // TODO(asridharan): This won't work when the framework sets the
+    // `LIBPROCESS_ADVERTISE_IP` which will end up overriding the IP
+    // address learnt during `process::initialize`, either through
+    // `LIBPROCESS_IP` or through hostname resolution. The correct
+    // approach would be to learn the allocated IP address directly
+    // from the agent and not rely on the resolution logic implemented
+    // in `process::initialize`.
+    Environment::Variable containerIP;
+    containerIP.set_name(MESOS_CONTAINER_IP);
+    containerIP.set_value(stringify(self().address.ip));
+
+    LOG(INFO) << "Setting 'MESOS_CONTAINER_IP' to: " << containerIP.value();
+
     list<ContainerID> containerIds;
     list<Future<Response>> responses;
 
@@ -427,6 +450,13 @@ protected:
         sandboxPath->set_path(executorVolume.container_path());
       }
 
+      // Set the `MESOS_CONTAINER_IP` for the task.
+      //
+      // TODO(asridharan): Document this API for consumption by tasks
+      // in the Mesos CNI and default-executor documentation.
+      CommandInfo *command = launch->mutable_command();
+      command->mutable_environment()->add_variables()->CopyFrom(containerIP);
+
       responses.push_back(post(connection.get(), call));
     }