You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by gi...@apache.org on 2017/12/27 17:34:31 UTC

[1/2] mesos git commit: Added `excluded_images` parameter to `PRUNE_IMAGES` agent API.

Repository: mesos
Updated Branches:
  refs/heads/1.5.x 30eb22161 -> d85cd885f


Added `excluded_images` parameter to `PRUNE_IMAGES` agent API.

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


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

Branch: refs/heads/1.5.x
Commit: d85cd885ff30625e490180d1e92fa39f8394c3f6
Parents: 4f4e0f2
Author: Zhitao Li <zh...@gmail.com>
Authored: Thu Dec 28 01:17:37 2017 +0800
Committer: Gilbert Song <so...@gmail.com>
Committed: Thu Dec 28 01:34:33 2017 +0800

----------------------------------------------------------------------
 include/mesos/agent/agent.proto    | 10 ++++++++++
 include/mesos/v1/agent/agent.proto | 10 ++++++++++
 src/slave/http.cpp                 | 11 ++++++++++-
 3 files changed, 30 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d85cd885/include/mesos/agent/agent.proto
----------------------------------------------------------------------
diff --git a/include/mesos/agent/agent.proto b/include/mesos/agent/agent.proto
index 756ea6e..3158200 100644
--- a/include/mesos/agent/agent.proto
+++ b/include/mesos/agent/agent.proto
@@ -349,6 +349,14 @@ message Call {
     required string name = 2;
   }
 
+  // Prune unused container images from image store.
+  //
+  // Images and layers referenced by active containers as well as
+  // image references specified in `excluded_images` will not be pruned.
+  message PruneImages {
+    repeated Image excluded_images = 1;
+  }
+
   optional Type type = 1;
 
   optional GetMetrics get_metrics = 2;
@@ -377,6 +385,8 @@ message Call {
   optional AddResourceProviderConfig add_resource_provider_config = 17;
   optional UpdateResourceProviderConfig update_resource_provider_config = 18;
   optional RemoveResourceProviderConfig remove_resource_provider_config = 19;
+
+  optional PruneImages prune_images = 21;
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/d85cd885/include/mesos/v1/agent/agent.proto
----------------------------------------------------------------------
diff --git a/include/mesos/v1/agent/agent.proto b/include/mesos/v1/agent/agent.proto
index 9c8d3cb..9e8b49d 100644
--- a/include/mesos/v1/agent/agent.proto
+++ b/include/mesos/v1/agent/agent.proto
@@ -349,6 +349,14 @@ message Call {
     required string name = 2;
   }
 
+  // Prune unused container images from image store.
+  //
+  // Images and layers referenced by active containers as well as
+  // image references specified in `excluded_images` will not be pruned.
+  message PruneImages {
+    repeated Image excluded_images = 1;
+  }
+
   optional Type type = 1;
 
   optional GetMetrics get_metrics = 2;
@@ -377,6 +385,8 @@ message Call {
   optional AddResourceProviderConfig add_resource_provider_config = 17;
   optional UpdateResourceProviderConfig update_resource_provider_config = 18;
   optional RemoveResourceProviderConfig remove_resource_provider_config = 19;
+
+  optional PruneImages prune_images = 21;
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/d85cd885/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index d0c1a0c..446be55 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -2447,7 +2447,16 @@ Future<Response> Http::pruneImages(
   // TODO(zhitao): Add AuthN/AuthZ.
 
   LOG(INFO) << "Processing PRUNE_IMAGES call";
-  vector<Image> excludedImages;
+  vector<Image> excludedImages(call.prune_images().excluded_images().begin(),
+                               call.prune_images().excluded_images().end());
+
+  // Include any `excluded_images` from agent flag's `image_gc_config`
+  // if not empty.
+  if (slave->flags.image_gc_config.isSome()) {
+    std::copy(slave->flags.image_gc_config->excluded_images().begin(),
+              slave->flags.image_gc_config->excluded_images().end(),
+              std::back_inserter(excludedImages));
+  }
 
   return slave->containerizer->pruneImages(excludedImages)
       .then([acceptType](const Future<Nothing>& result)


[2/2] mesos git commit: Added a new operator API for `PRUNE_IMAGES`.

Posted by gi...@apache.org.
Added a new operator API for `PRUNE_IMAGES`.

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


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

Branch: refs/heads/1.5.x
Commit: 4f4e0f257d43e9edb042e6b0ec07baf0a82c83fc
Parents: 30eb221
Author: Zhitao Li <zh...@gmail.com>
Authored: Thu Dec 28 01:17:23 2017 +0800
Committer: Gilbert Song <so...@gmail.com>
Committed: Thu Dec 28 01:34:33 2017 +0800

----------------------------------------------------------------------
 include/mesos/agent/agent.proto    |  3 +++
 include/mesos/v1/agent/agent.proto |  3 +++
 src/slave/http.cpp                 | 37 +++++++++++++++++++++++++++++++++
 src/slave/http.hpp                 |  6 ++++++
 src/slave/validation.cpp           |  4 ++++
 5 files changed, 53 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4f4e0f25/include/mesos/agent/agent.proto
----------------------------------------------------------------------
diff --git a/include/mesos/agent/agent.proto b/include/mesos/agent/agent.proto
index 25af6dc..756ea6e 100644
--- a/include/mesos/agent/agent.proto
+++ b/include/mesos/agent/agent.proto
@@ -93,6 +93,9 @@ message Call {
     ADD_RESOURCE_PROVIDER_CONFIG = 27;    // See 'AddResourceProviderConfig' below. // NOLINT
     UPDATE_RESOURCE_PROVIDER_CONFIG = 28; // See 'UpdateResourceProviderConfig' below. // NOLINT
     REMOVE_RESOURCE_PROVIDER_CONFIG = 29; // See 'RemoveResourceProviderConfig' below. // NOLINT
+
+    // Prune unused container images.
+    PRUNE_IMAGES = 30;
   }
 
   // Provides a snapshot of the current metrics tracked by the agent.

http://git-wip-us.apache.org/repos/asf/mesos/blob/4f4e0f25/include/mesos/v1/agent/agent.proto
----------------------------------------------------------------------
diff --git a/include/mesos/v1/agent/agent.proto b/include/mesos/v1/agent/agent.proto
index 4ae9013..9c8d3cb 100644
--- a/include/mesos/v1/agent/agent.proto
+++ b/include/mesos/v1/agent/agent.proto
@@ -93,6 +93,9 @@ message Call {
     ADD_RESOURCE_PROVIDER_CONFIG = 27;    // See 'AddResourceProviderConfig' below. // NOLINT
     UPDATE_RESOURCE_PROVIDER_CONFIG = 28; // See 'UpdateResourceProviderConfig' below. // NOLINT
     REMOVE_RESOURCE_PROVIDER_CONFIG = 29; // See 'RemoveResourceProviderConfig' below. // NOLINT
+
+    // Prune unused container images.
+    PRUNE_IMAGES = 30;
   }
 
   // Provides a snapshot of the current metrics tracked by the agent.

http://git-wip-us.apache.org/repos/asf/mesos/blob/4f4e0f25/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index 3e20c90..d0c1a0c 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -626,6 +626,9 @@ Future<Response> Http::_api(
 
     case mesos::agent::Call::REMOVE_RESOURCE_PROVIDER_CONFIG:
       return removeResourceProviderConfig(call, principal);
+
+    case mesos::agent::Call::PRUNE_IMAGES:
+      return pruneImages(call, mediaTypes.accept, principal);
   }
 
   UNREACHABLE();
@@ -2434,6 +2437,40 @@ Future<JSON::Array> Http::__containers(
 }
 
 
+Future<Response> Http::pruneImages(
+    const agent::Call& call,
+    ContentType acceptType,
+    const Option<Principal>& principal) const
+{
+  CHECK_EQ(agent::Call::PRUNE_IMAGES, call.type());
+
+  // TODO(zhitao): Add AuthN/AuthZ.
+
+  LOG(INFO) << "Processing PRUNE_IMAGES call";
+  vector<Image> excludedImages;
+
+  return slave->containerizer->pruneImages(excludedImages)
+      .then([acceptType](const Future<Nothing>& result)
+      ->Future<Response> {
+        if (!result.isReady()) {
+          // TODO(zhitao): Because `containerizer::pruneImages` returns
+          // a `Nothing` now, we cannot distinguish between actual
+          // failure or the case that operator should drain the agent.
+          // Consider returning more information.
+          LOG(WARNING)
+            << "Failed to prune images: "
+            << (result.isFailed() ? result.failure() : "discarded");
+
+          return result.isFailed()
+            ? InternalServerError(result.failure())
+            : InternalServerError();
+        }
+
+        return OK();
+      });
+}
+
+
 Try<string> Http::extractEndpoint(const process::http::URL& url) const
 {
   // Paths are of the form "/slave(n)/endpoint". We're only interested

http://git-wip-us.apache.org/repos/asf/mesos/blob/4f4e0f25/src/slave/http.hpp
----------------------------------------------------------------------
diff --git a/src/slave/http.hpp b/src/slave/http.hpp
index 3cdbf98..1619bb7 100644
--- a/src/slave/http.hpp
+++ b/src/slave/http.hpp
@@ -321,6 +321,12 @@ private:
       const mesos::agent::Call& call,
       const Option<process::http::authentication::Principal>& principal) const;
 
+  process::Future<process::http::Response> pruneImages(
+      const mesos::agent::Call& call,
+      ContentType acceptType,
+      const Option<process::http::authentication::Principal>&
+          principal) const;
+
   Slave* slave;
 
   // Used to rate limit the statistics endpoint.

http://git-wip-us.apache.org/repos/asf/mesos/blob/4f4e0f25/src/slave/validation.cpp
----------------------------------------------------------------------
diff --git a/src/slave/validation.cpp b/src/slave/validation.cpp
index b7243fc..7444d6a 100644
--- a/src/slave/validation.cpp
+++ b/src/slave/validation.cpp
@@ -525,6 +525,10 @@ Option<Error> validate(
 
       return None();
     }
+
+    case mesos::agent::Call::PRUNE_IMAGES: {
+      return None();
+    }
   }
 
   UNREACHABLE();