Update GRPC api to support labels and snapshot updates
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
55c3711fab
commit
efca0c5347
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,8 @@ package containerd.services.snapshots.v1;
|
|||||||
|
|
||||||
import "gogoproto/gogo.proto";
|
import "gogoproto/gogo.proto";
|
||||||
import "google/protobuf/empty.proto";
|
import "google/protobuf/empty.proto";
|
||||||
|
import "google/protobuf/field_mask.proto";
|
||||||
|
import "google/protobuf/timestamp.proto";
|
||||||
import "github.com/containerd/containerd/api/types/mount.proto";
|
import "github.com/containerd/containerd/api/types/mount.proto";
|
||||||
|
|
||||||
option go_package = "github.com/containerd/containerd/api/services/snapshot/v1;snapshot";
|
option go_package = "github.com/containerd/containerd/api/services/snapshot/v1;snapshot";
|
||||||
@ -16,6 +18,7 @@ service Snapshots {
|
|||||||
rpc Commit(CommitSnapshotRequest) returns (google.protobuf.Empty);
|
rpc Commit(CommitSnapshotRequest) returns (google.protobuf.Empty);
|
||||||
rpc Remove(RemoveSnapshotRequest) returns (google.protobuf.Empty);
|
rpc Remove(RemoveSnapshotRequest) returns (google.protobuf.Empty);
|
||||||
rpc Stat(StatSnapshotRequest) returns (StatSnapshotResponse);
|
rpc Stat(StatSnapshotRequest) returns (StatSnapshotResponse);
|
||||||
|
rpc Update(UpdateSnapshotRequest) returns (UpdateSnapshotResponse);
|
||||||
rpc List(ListSnapshotsRequest) returns (stream ListSnapshotsResponse);
|
rpc List(ListSnapshotsRequest) returns (stream ListSnapshotsResponse);
|
||||||
rpc Usage(UsageRequest) returns (UsageResponse);
|
rpc Usage(UsageRequest) returns (UsageResponse);
|
||||||
}
|
}
|
||||||
@ -24,6 +27,9 @@ message PrepareSnapshotRequest {
|
|||||||
string snapshotter = 1;
|
string snapshotter = 1;
|
||||||
string key = 2;
|
string key = 2;
|
||||||
string parent = 3;
|
string parent = 3;
|
||||||
|
|
||||||
|
// Labels are arbitrary data on snapshots.
|
||||||
|
map<string, string> labels = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PrepareSnapshotResponse {
|
message PrepareSnapshotResponse {
|
||||||
@ -34,6 +40,9 @@ message ViewSnapshotRequest {
|
|||||||
string snapshotter = 1;
|
string snapshotter = 1;
|
||||||
string key = 2;
|
string key = 2;
|
||||||
string parent = 3;
|
string parent = 3;
|
||||||
|
|
||||||
|
// Labels are arbitrary data on snapshots.
|
||||||
|
map<string, string> labels = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ViewSnapshotResponse {
|
message ViewSnapshotResponse {
|
||||||
@ -58,6 +67,9 @@ message CommitSnapshotRequest {
|
|||||||
string snapshotter = 1;
|
string snapshotter = 1;
|
||||||
string name = 2;
|
string name = 2;
|
||||||
string key = 3;
|
string key = 3;
|
||||||
|
|
||||||
|
// Labels are arbitrary data on snapshots.
|
||||||
|
map<string, string> labels = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message StatSnapshotRequest {
|
message StatSnapshotRequest {
|
||||||
@ -79,12 +91,38 @@ message Info {
|
|||||||
string name = 1;
|
string name = 1;
|
||||||
string parent = 2;
|
string parent = 2;
|
||||||
Kind kind = 3;
|
Kind kind = 3;
|
||||||
|
|
||||||
|
// CreatedAt provides the time at which the snapshot was created.
|
||||||
|
google.protobuf.Timestamp created_at = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
|
||||||
|
|
||||||
|
// UpdatedAt provides the time the info was last updated.
|
||||||
|
google.protobuf.Timestamp updated_at = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
|
||||||
|
|
||||||
|
// Labels are arbitrary data on snapshots.
|
||||||
|
map<string, string> labels = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message StatSnapshotResponse {
|
message StatSnapshotResponse {
|
||||||
Info info = 1 [(gogoproto.nullable) = false];
|
Info info = 1 [(gogoproto.nullable) = false];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message UpdateSnapshotRequest {
|
||||||
|
string snapshotter = 1;
|
||||||
|
Info info = 2 [(gogoproto.nullable) = false];
|
||||||
|
|
||||||
|
// UpdateMask specifies which fields to perform the update on. If empty,
|
||||||
|
// the operation applies to all fields.
|
||||||
|
//
|
||||||
|
// In info, Name, Parent, Kind, Created are immutable,
|
||||||
|
// other field may be updated using this mask.
|
||||||
|
// If no mask is provided, all mutable field are updated.
|
||||||
|
google.protobuf.FieldMask update_mask = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateSnapshotResponse {
|
||||||
|
Info info = 1 [(gogoproto.nullable) = false];
|
||||||
|
}
|
||||||
|
|
||||||
message ListSnapshotsRequest{
|
message ListSnapshotsRequest{
|
||||||
string snapshotter = 1;
|
string snapshotter = 1;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/mount"
|
"github.com/containerd/containerd/mount"
|
||||||
"github.com/containerd/containerd/snapshot"
|
"github.com/containerd/containerd/snapshot"
|
||||||
|
protobuftypes "github.com/gogo/protobuf/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewSnapshotterFromClient returns a new Snapshotter which communicates
|
// NewSnapshotterFromClient returns a new Snapshotter which communicates
|
||||||
@ -37,6 +38,21 @@ func (r *remoteSnapshotter) Stat(ctx context.Context, key string) (snapshot.Info
|
|||||||
return toInfo(resp.Info), nil
|
return toInfo(resp.Info), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *remoteSnapshotter) Update(ctx context.Context, info snapshot.Info, fieldpaths ...string) (snapshot.Info, error) {
|
||||||
|
resp, err := r.client.Update(ctx,
|
||||||
|
&snapshotapi.UpdateSnapshotRequest{
|
||||||
|
Snapshotter: r.snapshotterName,
|
||||||
|
Info: fromInfo(info),
|
||||||
|
UpdateMask: &protobuftypes.FieldMask{
|
||||||
|
Paths: fieldpaths,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return snapshot.Info{}, errdefs.FromGRPC(err)
|
||||||
|
}
|
||||||
|
return toInfo(resp.Info), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *remoteSnapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, error) {
|
func (r *remoteSnapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, error) {
|
||||||
resp, err := r.client.Usage(ctx, &snapshotapi.UsageRequest{
|
resp, err := r.client.Usage(ctx, &snapshotapi.UsageRequest{
|
||||||
Snapshotter: r.snapshotterName,
|
Snapshotter: r.snapshotterName,
|
||||||
@ -59,11 +75,18 @@ func (r *remoteSnapshotter) Mounts(ctx context.Context, key string) ([]mount.Mou
|
|||||||
return toMounts(resp.Mounts), nil
|
return toMounts(resp.Mounts), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string) ([]mount.Mount, error) {
|
func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||||
|
var local snapshot.Info
|
||||||
|
for _, opt := range opts {
|
||||||
|
if err := opt(&local); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
resp, err := r.client.Prepare(ctx, &snapshotapi.PrepareSnapshotRequest{
|
resp, err := r.client.Prepare(ctx, &snapshotapi.PrepareSnapshotRequest{
|
||||||
Snapshotter: r.snapshotterName,
|
Snapshotter: r.snapshotterName,
|
||||||
Key: key,
|
Key: key,
|
||||||
Parent: parent,
|
Parent: parent,
|
||||||
|
Labels: local.Labels,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errdefs.FromGRPC(err)
|
return nil, errdefs.FromGRPC(err)
|
||||||
@ -71,11 +94,18 @@ func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string) ([]
|
|||||||
return toMounts(resp.Mounts), nil
|
return toMounts(resp.Mounts), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *remoteSnapshotter) View(ctx context.Context, key, parent string) ([]mount.Mount, error) {
|
func (r *remoteSnapshotter) View(ctx context.Context, key, parent string, opts ...snapshot.Opt) ([]mount.Mount, error) {
|
||||||
|
var local snapshot.Info
|
||||||
|
for _, opt := range opts {
|
||||||
|
if err := opt(&local); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
resp, err := r.client.View(ctx, &snapshotapi.ViewSnapshotRequest{
|
resp, err := r.client.View(ctx, &snapshotapi.ViewSnapshotRequest{
|
||||||
Snapshotter: r.snapshotterName,
|
Snapshotter: r.snapshotterName,
|
||||||
Key: key,
|
Key: key,
|
||||||
Parent: parent,
|
Parent: parent,
|
||||||
|
Labels: local.Labels,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errdefs.FromGRPC(err)
|
return nil, errdefs.FromGRPC(err)
|
||||||
@ -83,11 +113,18 @@ func (r *remoteSnapshotter) View(ctx context.Context, key, parent string) ([]mou
|
|||||||
return toMounts(resp.Mounts), nil
|
return toMounts(resp.Mounts), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *remoteSnapshotter) Commit(ctx context.Context, name, key string) error {
|
func (r *remoteSnapshotter) Commit(ctx context.Context, name, key string, opts ...snapshot.Opt) error {
|
||||||
|
var local snapshot.Info
|
||||||
|
for _, opt := range opts {
|
||||||
|
if err := opt(&local); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
_, err := r.client.Commit(ctx, &snapshotapi.CommitSnapshotRequest{
|
_, err := r.client.Commit(ctx, &snapshotapi.CommitSnapshotRequest{
|
||||||
Snapshotter: r.snapshotterName,
|
Snapshotter: r.snapshotterName,
|
||||||
Name: name,
|
Name: name,
|
||||||
Key: key,
|
Key: key,
|
||||||
|
Labels: local.Labels,
|
||||||
})
|
})
|
||||||
return errdefs.FromGRPC(err)
|
return errdefs.FromGRPC(err)
|
||||||
}
|
}
|
||||||
@ -130,6 +167,9 @@ func toKind(kind snapshotapi.Kind) snapshot.Kind {
|
|||||||
if kind == snapshotapi.KindActive {
|
if kind == snapshotapi.KindActive {
|
||||||
return snapshot.KindActive
|
return snapshot.KindActive
|
||||||
}
|
}
|
||||||
|
if kind == snapshotapi.KindView {
|
||||||
|
return snapshot.KindView
|
||||||
|
}
|
||||||
return snapshot.KindCommitted
|
return snapshot.KindCommitted
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,6 +178,9 @@ func toInfo(info snapshotapi.Info) snapshot.Info {
|
|||||||
Name: info.Name,
|
Name: info.Name,
|
||||||
Parent: info.Parent,
|
Parent: info.Parent,
|
||||||
Kind: toKind(info.Kind),
|
Kind: toKind(info.Kind),
|
||||||
|
Created: info.CreatedAt,
|
||||||
|
Updated: info.UpdatedAt,
|
||||||
|
Labels: info.Labels,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,9 +97,12 @@ func (s *service) Prepare(ctx context.Context, pr *snapshotapi.PrepareSnapshotRe
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Apply namespace
|
|
||||||
// TODO: Lookup snapshot id from metadata store
|
var opts []snapshot.Opt
|
||||||
mounts, err := sn.Prepare(ctx, pr.Key, pr.Parent)
|
if pr.Labels != nil {
|
||||||
|
opts = append(opts, snapshot.WithLabels(pr.Labels))
|
||||||
|
}
|
||||||
|
mounts, err := sn.Prepare(ctx, pr.Key, pr.Parent, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errdefs.ToGRPC(err)
|
return nil, errdefs.ToGRPC(err)
|
||||||
}
|
}
|
||||||
@ -121,9 +124,11 @@ func (s *service) View(ctx context.Context, pr *snapshotapi.ViewSnapshotRequest)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Apply namespace
|
var opts []snapshot.Opt
|
||||||
// TODO: Lookup snapshot id from metadata store
|
if pr.Labels != nil {
|
||||||
mounts, err := sn.View(ctx, pr.Key, pr.Parent)
|
opts = append(opts, snapshot.WithLabels(pr.Labels))
|
||||||
|
}
|
||||||
|
mounts, err := sn.View(ctx, pr.Key, pr.Parent, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errdefs.ToGRPC(err)
|
return nil, errdefs.ToGRPC(err)
|
||||||
}
|
}
|
||||||
@ -138,8 +143,7 @@ func (s *service) Mounts(ctx context.Context, mr *snapshotapi.MountsRequest) (*s
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Apply namespace
|
|
||||||
// TODO: Lookup snapshot id from metadata store
|
|
||||||
mounts, err := sn.Mounts(ctx, mr.Key)
|
mounts, err := sn.Mounts(ctx, mr.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errdefs.ToGRPC(err)
|
return nil, errdefs.ToGRPC(err)
|
||||||
@ -155,9 +159,12 @@ func (s *service) Commit(ctx context.Context, cr *snapshotapi.CommitSnapshotRequ
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Apply namespace
|
|
||||||
// TODO: Lookup snapshot id from metadata store
|
var opts []snapshot.Opt
|
||||||
if err := sn.Commit(ctx, cr.Name, cr.Key); err != nil {
|
if cr.Labels != nil {
|
||||||
|
opts = append(opts, snapshot.WithLabels(cr.Labels))
|
||||||
|
}
|
||||||
|
if err := sn.Commit(ctx, cr.Name, cr.Key, opts...); err != nil {
|
||||||
return nil, errdefs.ToGRPC(err)
|
return nil, errdefs.ToGRPC(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,8 +183,7 @@ func (s *service) Remove(ctx context.Context, rr *snapshotapi.RemoveSnapshotRequ
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Apply namespace
|
|
||||||
// TODO: Lookup snapshot id from metadata store
|
|
||||||
if err := sn.Remove(ctx, rr.Key); err != nil {
|
if err := sn.Remove(ctx, rr.Key); err != nil {
|
||||||
return nil, errdefs.ToGRPC(err)
|
return nil, errdefs.ToGRPC(err)
|
||||||
}
|
}
|
||||||
@ -196,7 +202,7 @@ func (s *service) Stat(ctx context.Context, sr *snapshotapi.StatSnapshotRequest)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Apply namespace
|
|
||||||
info, err := sn.Stat(ctx, sr.Key)
|
info, err := sn.Stat(ctx, sr.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errdefs.ToGRPC(err)
|
return nil, errdefs.ToGRPC(err)
|
||||||
@ -205,12 +211,27 @@ func (s *service) Stat(ctx context.Context, sr *snapshotapi.StatSnapshotRequest)
|
|||||||
return &snapshotapi.StatSnapshotResponse{Info: fromInfo(info)}, nil
|
return &snapshotapi.StatSnapshotResponse{Info: fromInfo(info)}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *service) Update(ctx context.Context, sr *snapshotapi.UpdateSnapshotRequest) (*snapshotapi.UpdateSnapshotResponse, error) {
|
||||||
|
log.G(ctx).WithField("key", sr.Info.Name).Debugf("Updating snapshot")
|
||||||
|
sn, err := s.getSnapshotter(sr.Snapshotter)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info, err := sn.Update(ctx, toInfo(sr.Info), sr.UpdateMask.GetPaths()...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errdefs.ToGRPC(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &snapshotapi.UpdateSnapshotResponse{Info: fromInfo(info)}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *service) List(sr *snapshotapi.ListSnapshotsRequest, ss snapshotapi.Snapshots_ListServer) error {
|
func (s *service) List(sr *snapshotapi.ListSnapshotsRequest, ss snapshotapi.Snapshots_ListServer) error {
|
||||||
sn, err := s.getSnapshotter(sr.Snapshotter)
|
sn, err := s.getSnapshotter(sr.Snapshotter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// TODO: Apply namespace
|
|
||||||
var (
|
var (
|
||||||
buffer []snapshotapi.Info
|
buffer []snapshotapi.Info
|
||||||
sendBlock = func(block []snapshotapi.Info) error {
|
sendBlock = func(block []snapshotapi.Info) error {
|
||||||
@ -250,7 +271,7 @@ func (s *service) Usage(ctx context.Context, ur *snapshotapi.UsageRequest) (*sna
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Apply namespace
|
|
||||||
usage, err := sn.Usage(ctx, ur.Key)
|
usage, err := sn.Usage(ctx, ur.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errdefs.ToGRPC(err)
|
return nil, errdefs.ToGRPC(err)
|
||||||
@ -263,6 +284,9 @@ func fromKind(kind snapshot.Kind) snapshotapi.Kind {
|
|||||||
if kind == snapshot.KindActive {
|
if kind == snapshot.KindActive {
|
||||||
return snapshotapi.KindActive
|
return snapshotapi.KindActive
|
||||||
}
|
}
|
||||||
|
if kind == snapshot.KindView {
|
||||||
|
return snapshotapi.KindView
|
||||||
|
}
|
||||||
return snapshotapi.KindCommitted
|
return snapshotapi.KindCommitted
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,6 +295,9 @@ func fromInfo(info snapshot.Info) snapshotapi.Info {
|
|||||||
Name: info.Name,
|
Name: info.Name,
|
||||||
Parent: info.Parent,
|
Parent: info.Parent,
|
||||||
Kind: fromKind(info.Kind),
|
Kind: fromKind(info.Kind),
|
||||||
|
CreatedAt: info.Created,
|
||||||
|
UpdatedAt: info.Updated,
|
||||||
|
Labels: info.Labels,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user