leases: support resource management
Add three methods for lease service so that the client can use it to
manage the resource by lease, not just gc.root label. With the following
methods, it is easy for client to maintain their own cache system.
```
- AddResource(context.Context, Lease, Resource) error
- RemoveResource(context.Context, Lease, Resource) error
- ListResources(context.Context, Lease) ([]Resource, error)
```
And the resource is to be
```golang
type Resource {
ID string
Type string
}
```
For the snapshots, the Type field will be formatted by
snapshots/%{type}, like snapshots/overlayfs.
fix: #3295
Signed-off-by: Wei Fu <fuweid89@gmail.com>
This commit is contained in:
@@ -2627,6 +2627,89 @@ file {
|
||||
json_name: "leases"
|
||||
}
|
||||
}
|
||||
message_type {
|
||||
name: "Resource"
|
||||
field {
|
||||
name: "id"
|
||||
number: 1
|
||||
label: LABEL_OPTIONAL
|
||||
type: TYPE_STRING
|
||||
json_name: "id"
|
||||
}
|
||||
field {
|
||||
name: "type"
|
||||
number: 2
|
||||
label: LABEL_OPTIONAL
|
||||
type: TYPE_STRING
|
||||
json_name: "type"
|
||||
}
|
||||
}
|
||||
message_type {
|
||||
name: "AddResourceRequest"
|
||||
field {
|
||||
name: "id"
|
||||
number: 1
|
||||
label: LABEL_OPTIONAL
|
||||
type: TYPE_STRING
|
||||
json_name: "id"
|
||||
}
|
||||
field {
|
||||
name: "resource"
|
||||
number: 2
|
||||
label: LABEL_OPTIONAL
|
||||
type: TYPE_MESSAGE
|
||||
type_name: ".containerd.services.leases.v1.Resource"
|
||||
options {
|
||||
65001: 0
|
||||
}
|
||||
json_name: "resource"
|
||||
}
|
||||
}
|
||||
message_type {
|
||||
name: "DeleteResourceRequest"
|
||||
field {
|
||||
name: "id"
|
||||
number: 1
|
||||
label: LABEL_OPTIONAL
|
||||
type: TYPE_STRING
|
||||
json_name: "id"
|
||||
}
|
||||
field {
|
||||
name: "resource"
|
||||
number: 2
|
||||
label: LABEL_OPTIONAL
|
||||
type: TYPE_MESSAGE
|
||||
type_name: ".containerd.services.leases.v1.Resource"
|
||||
options {
|
||||
65001: 0
|
||||
}
|
||||
json_name: "resource"
|
||||
}
|
||||
}
|
||||
message_type {
|
||||
name: "ListResourcesRequest"
|
||||
field {
|
||||
name: "id"
|
||||
number: 1
|
||||
label: LABEL_OPTIONAL
|
||||
type: TYPE_STRING
|
||||
json_name: "id"
|
||||
}
|
||||
}
|
||||
message_type {
|
||||
name: "ListResourcesResponse"
|
||||
field {
|
||||
name: "resources"
|
||||
number: 1
|
||||
label: LABEL_REPEATED
|
||||
type: TYPE_MESSAGE
|
||||
type_name: ".containerd.services.leases.v1.Resource"
|
||||
options {
|
||||
65001: 0
|
||||
}
|
||||
json_name: "resources"
|
||||
}
|
||||
}
|
||||
service {
|
||||
name: "Leases"
|
||||
method {
|
||||
@@ -2644,6 +2727,21 @@ file {
|
||||
input_type: ".containerd.services.leases.v1.ListRequest"
|
||||
output_type: ".containerd.services.leases.v1.ListResponse"
|
||||
}
|
||||
method {
|
||||
name: "AddResource"
|
||||
input_type: ".containerd.services.leases.v1.AddResourceRequest"
|
||||
output_type: ".google.protobuf.Empty"
|
||||
}
|
||||
method {
|
||||
name: "DeleteResource"
|
||||
input_type: ".containerd.services.leases.v1.DeleteResourceRequest"
|
||||
output_type: ".google.protobuf.Empty"
|
||||
}
|
||||
method {
|
||||
name: "ListResources"
|
||||
input_type: ".containerd.services.leases.v1.ListResourcesRequest"
|
||||
output_type: ".containerd.services.leases.v1.ListResourcesResponse"
|
||||
}
|
||||
}
|
||||
options {
|
||||
go_package: "github.com/containerd/containerd/api/services/leases/v1;leases"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -22,6 +22,15 @@ service Leases {
|
||||
// List lists all active leases, returning the full list of
|
||||
// leases and optionally including the referenced resources.
|
||||
rpc List(ListRequest) returns (ListResponse);
|
||||
|
||||
// AddResource references the resource by the provided lease.
|
||||
rpc AddResource(AddResourceRequest) returns (google.protobuf.Empty);
|
||||
|
||||
// DeleteResource dereferences the resource by the provided lease.
|
||||
rpc DeleteResource(DeleteResourceRequest) returns (google.protobuf.Empty);
|
||||
|
||||
// ListResources lists all the resources referenced by the lease.
|
||||
rpc ListResources(ListResourcesRequest) returns (ListResourcesResponse);
|
||||
}
|
||||
|
||||
// Lease is an object which retains resources while it exists.
|
||||
@@ -62,3 +71,32 @@ message ListRequest {
|
||||
message ListResponse {
|
||||
repeated Lease leases = 1;
|
||||
}
|
||||
|
||||
message Resource {
|
||||
string id = 1;
|
||||
|
||||
// For snapshotter resource, there are many snapshotter types here, like
|
||||
// overlayfs, devmapper etc. The type will be formatted with type,
|
||||
// like "snapshotter/overlayfs".
|
||||
string type = 2;
|
||||
}
|
||||
|
||||
message AddResourceRequest {
|
||||
string id = 1;
|
||||
|
||||
Resource resource = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message DeleteResourceRequest {
|
||||
string id = 1;
|
||||
|
||||
Resource resource = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
message ListResourcesRequest {
|
||||
string id = 1;
|
||||
}
|
||||
|
||||
message ListResourcesResponse {
|
||||
repeated Resource resources = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user