You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by qi...@apache.org on 2020/08/19 02:54:10 UTC

[mesos] branch master updated: Exposed Mesos agent ID to managed CSI plugins.

This is an automated email from the ASF dual-hosted git repository.

qianzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git


The following commit(s) were added to refs/heads/master by this push:
     new b1b3ed0  Exposed Mesos agent ID to managed CSI plugins.
b1b3ed0 is described below

commit b1b3ed096e31260a25ba74927786db3f92afb9d3
Author: Qian Zhang <zh...@gmail.com>
AuthorDate: Wed Aug 12 17:25:11 2020 +0800

    Exposed Mesos agent ID to managed CSI plugins.
    
    Review: https://reviews.apache.org/r/72759
---
 src/csi/service_manager.cpp                | 22 ++++++++++++++++++++++
 src/csi/service_manager.hpp                |  1 +
 src/resource_provider/storage/provider.cpp |  1 +
 src/slave/csi_server.cpp                   |  2 ++
 4 files changed, 26 insertions(+)

diff --git a/src/csi/service_manager.cpp b/src/csi/service_manager.cpp
index 7a8d8e5..5b298a1 100644
--- a/src/csi/service_manager.cpp
+++ b/src/csi/service_manager.cpp
@@ -128,6 +128,7 @@ class ServiceManagerProcess : public Process<ServiceManagerProcess>
 {
 public:
   ServiceManagerProcess(
+      const SlaveID& _agentId,
       const http::URL& _agentUrl,
       const string& _rootDir,
       const CSIPluginInfo& _info,
@@ -174,6 +175,7 @@ private:
   // a new container.
   Future<string> getEndpoint(const ContainerID& containerId);
 
+  const SlaveID agentId;
   const http::URL agentUrl;
   const string rootDir;
   const CSIPluginInfo info;
@@ -201,6 +203,7 @@ private:
 
 
 ServiceManagerProcess::ServiceManagerProcess(
+    const SlaveID& _agentId,
     const http::URL& _agentUrl,
     const string& _rootDir,
     const CSIPluginInfo& _info,
@@ -210,6 +213,7 @@ ServiceManagerProcess::ServiceManagerProcess(
     const Runtime& _runtime,
     Metrics* _metrics)
   : ProcessBase(process::ID::generate("csi-service-manager")),
+    agentId(_agentId),
     agentUrl(_agentUrl),
     rootDir(_rootDir),
     info(_info),
@@ -252,6 +256,7 @@ ServiceManagerProcess::ServiceManagerProcess(
     const Runtime& _runtime,
     Metrics* _metrics)
   : ProcessBase(process::ID::generate("csi-service-manager")),
+    agentId(),
     agentUrl(),
     rootDir(),
     info(_info),
@@ -723,9 +728,24 @@ Future<string> ServiceManagerProcess::getEndpoint(
   const string endpoint = "unix://" + endpointPath.get();
   Environment::Variable* endpoint_ =
     commandInfo.mutable_environment()->add_variables();
+
   endpoint_->set_name("CSI_ENDPOINT");
   endpoint_->set_value(endpoint);
 
+  // For some CSI Plugins (like NFS CSI plugin), their node service need
+  // a node ID specified by container orchestrator, so here we expose agent
+  // ID to the plugins, they can use that as the node ID.
+  if (config->services().end() != std::find(
+          config->services().begin(),
+          config->services().end(),
+          NODE_SERVICE)) {
+    Environment::Variable* nodeId =
+      commandInfo.mutable_environment()->add_variables();
+
+    nodeId->set_name("MESOS_AGENT_ID");
+    nodeId->set_value(stringify(agentId));
+  }
+
   ContainerInfo containerInfo;
 
   if (config->has_container()) {
@@ -839,6 +859,7 @@ Future<string> ServiceManagerProcess::getEndpoint(
 
 
 ServiceManager::ServiceManager(
+    const SlaveID& agentId,
     const http::URL& agentUrl,
     const string& rootDir,
     const CSIPluginInfo& info,
@@ -848,6 +869,7 @@ ServiceManager::ServiceManager(
     const Runtime& runtime,
     Metrics* metrics)
   : process(new ServiceManagerProcess(
+        agentId,
         agentUrl,
         rootDir,
         info,
diff --git a/src/csi/service_manager.hpp b/src/csi/service_manager.hpp
index 76a80fb..24356f8 100644
--- a/src/csi/service_manager.hpp
+++ b/src/csi/service_manager.hpp
@@ -54,6 +54,7 @@ public:
   // This is for the managed CSI plugins which will be
   // launched as standalone containers.
   ServiceManager(
+      const SlaveID& agentId,
       const process::http::URL& agentUrl,
       const std::string& rootDir,
       const CSIPluginInfo& info,
diff --git a/src/resource_provider/storage/provider.cpp b/src/resource_provider/storage/provider.cpp
index 0a8dc26..1a202af 100644
--- a/src/resource_provider/storage/provider.cpp
+++ b/src/resource_provider/storage/provider.cpp
@@ -567,6 +567,7 @@ Future<Nothing> StorageLocalResourceProviderProcess::recover()
   CHECK_EQ(RECOVERING, state);
 
   serviceManager.reset(new ServiceManager(
+      slaveId,
       extractParentEndpoint(url),
       slave::paths::getCsiRootDir(workDir),
       info.storage().plugin(),
diff --git a/src/slave/csi_server.cpp b/src/slave/csi_server.cpp
index b435d5d..2ba4f22 100644
--- a/src/slave/csi_server.cpp
+++ b/src/slave/csi_server.cpp
@@ -125,6 +125,7 @@ private:
   SecretResolver* secretResolver;
   Option<string> authToken;
   hashmap<string, CSIPluginInfo> pluginConfigs;
+  Option<SlaveID> agentId;
 };
 
 
@@ -172,6 +173,7 @@ Future<Nothing> CSIServerProcess::start()
 
     if (info.containers_size() > 0) {
       plugins.at(name).serviceManager.reset(new ServiceManager(
+          agentId.get(),
           agentUrl,
           rootDir,
           info,