Add snapshotter key to snapshot events

Consumers of snapshot events require the snapshotter
field to refer to the related snapshot.

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan 2022-06-20 18:09:15 -07:00
parent b56cac143a
commit 4ac1031e0c
No known key found for this signature in database
GPG Key ID: F58C5D0A4405ACDB
5 changed files with 90 additions and 24 deletions

View File

@ -41,8 +41,9 @@ type SnapshotPrepare struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
Parent string `protobuf:"bytes,2,opt,name=parent,proto3" json:"parent,omitempty"` Parent string `protobuf:"bytes,2,opt,name=parent,proto3" json:"parent,omitempty"`
Snapshotter string `protobuf:"bytes,5,opt,name=snapshotter,proto3" json:"snapshotter,omitempty"`
} }
func (x *SnapshotPrepare) Reset() { func (x *SnapshotPrepare) Reset() {
@ -91,13 +92,21 @@ func (x *SnapshotPrepare) GetParent() string {
return "" return ""
} }
func (x *SnapshotPrepare) GetSnapshotter() string {
if x != nil {
return x.Snapshotter
}
return ""
}
type SnapshotCommit struct { type SnapshotCommit struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Snapshotter string `protobuf:"bytes,5,opt,name=snapshotter,proto3" json:"snapshotter,omitempty"`
} }
func (x *SnapshotCommit) Reset() { func (x *SnapshotCommit) Reset() {
@ -146,12 +155,20 @@ func (x *SnapshotCommit) GetName() string {
return "" return ""
} }
func (x *SnapshotCommit) GetSnapshotter() string {
if x != nil {
return x.Snapshotter
}
return ""
}
type SnapshotRemove struct { type SnapshotRemove struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
Snapshotter string `protobuf:"bytes,5,opt,name=snapshotter,proto3" json:"snapshotter,omitempty"`
} }
func (x *SnapshotRemove) Reset() { func (x *SnapshotRemove) Reset() {
@ -193,6 +210,13 @@ func (x *SnapshotRemove) GetKey() string {
return "" return ""
} }
func (x *SnapshotRemove) GetSnapshotter() string {
if x != nil {
return x.Snapshotter
}
return ""
}
var File_github_com_containerd_containerd_api_events_snapshot_proto protoreflect.FileDescriptor var File_github_com_containerd_containerd_api_events_snapshot_proto protoreflect.FileDescriptor
var file_github_com_containerd_containerd_api_events_snapshot_proto_rawDesc = []byte{ var file_github_com_containerd_containerd_api_events_snapshot_proto_rawDesc = []byte{
@ -205,20 +229,27 @@ var file_github_com_containerd_containerd_api_events_snapshot_proto_rawDesc = []
0x61, 0x69, 0x6e, 0x65, 0x72, 0x64, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x64, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72,
0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69,
0x6e, 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x70, 0x61, 0x74, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6e, 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x70, 0x61, 0x74, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x22, 0x3b, 0x0a, 0x0f, 0x53, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x50, 0x72, 0x65, 0x6f, 0x22, 0x5d, 0x0a, 0x0f, 0x53, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x50, 0x72, 0x65,
0x70, 0x61, 0x72, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x70, 0x61, 0x72, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x22, 0x36, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x12, 0x20,
0x0a, 0x0e, 0x53, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x0a, 0x0b, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x18, 0x05, 0x20,
0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x74, 0x65, 0x72,
0x65, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x22, 0x58, 0x0a, 0x0e, 0x53, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x43, 0x6f, 0x6d, 0x6d,
0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x22, 0x0a, 0x0e, 0x53, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x69, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x6f, 0x74, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x42, 0x38, 0x5a, 0x32, 0x67, 0x69, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x6e, 0x61, 0x70,
0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x73, 0x68, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73,
0x65, 0x72, 0x64, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x64, 0x2f, 0x61, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x22, 0x44, 0x0a, 0x0e, 0x53, 0x6e,
0x70, 0x69, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x3b, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x12, 0x10, 0x0a, 0x03,
0xa0, 0xf4, 0x1e, 0x01, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x20,
0x0a, 0x0b, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x18, 0x05, 0x20,
0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x74, 0x65, 0x72,
0x42, 0x38, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63,
0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x64, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69,
0x6e, 0x65, 0x72, 0x64, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x3b,
0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0xa0, 0xf4, 0x1e, 0x01, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
} }
var ( var (

View File

@ -26,13 +26,16 @@ option (containerd.plugin.fieldpath_all) = true;
message SnapshotPrepare { message SnapshotPrepare {
string key = 1; string key = 1;
string parent = 2; string parent = 2;
string snapshotter = 5;
} }
message SnapshotCommit { message SnapshotCommit {
string key = 1; string key = 1;
string name = 2; string name = 2;
string snapshotter = 5;
} }
message SnapshotRemove { message SnapshotRemove {
string key = 1; string key = 1;
string snapshotter = 5;
} }

View File

@ -13,6 +13,8 @@ func (m *SnapshotPrepare) Field(fieldpath []string) (string, bool) {
return string(m.Key), len(m.Key) > 0 return string(m.Key), len(m.Key) > 0
case "parent": case "parent":
return string(m.Parent), len(m.Parent) > 0 return string(m.Parent), len(m.Parent) > 0
case "snapshotter":
return string(m.Snapshotter), len(m.Snapshotter) > 0
} }
return "", false return "", false
} }
@ -28,6 +30,8 @@ func (m *SnapshotCommit) Field(fieldpath []string) (string, bool) {
return string(m.Key), len(m.Key) > 0 return string(m.Key), len(m.Key) > 0
case "name": case "name":
return string(m.Name), len(m.Name) > 0 return string(m.Name), len(m.Name) > 0
case "snapshotter":
return string(m.Snapshotter), len(m.Snapshotter) > 0
} }
return "", false return "", false
} }
@ -41,6 +45,8 @@ func (m *SnapshotRemove) Field(fieldpath []string) (string, bool) {
switch fieldpath[0] { switch fieldpath[0] {
case "key": case "key":
return string(m.Key), len(m.Key) > 0 return string(m.Key), len(m.Key) > 0
case "snapshotter":
return string(m.Snapshotter), len(m.Snapshotter) > 0
} }
return "", false return "", false
} }

View File

@ -400,6 +400,13 @@ file {
type: TYPE_STRING type: TYPE_STRING
json_name: "parent" json_name: "parent"
} }
field {
name: "snapshotter"
number: 5
label: LABEL_OPTIONAL
type: TYPE_STRING
json_name: "snapshotter"
}
} }
message_type { message_type {
name: "SnapshotCommit" name: "SnapshotCommit"
@ -417,6 +424,13 @@ file {
type: TYPE_STRING type: TYPE_STRING
json_name: "name" json_name: "name"
} }
field {
name: "snapshotter"
number: 5
label: LABEL_OPTIONAL
type: TYPE_STRING
json_name: "snapshotter"
}
} }
message_type { message_type {
name: "SnapshotRemove" name: "SnapshotRemove"
@ -427,6 +441,13 @@ file {
type: TYPE_STRING type: TYPE_STRING
json_name: "key" json_name: "key"
} }
field {
name: "snapshotter"
number: 5
label: LABEL_OPTIONAL
type: TYPE_STRING
json_name: "snapshotter"
}
} }
options { options {
go_package: "github.com/containerd/containerd/api/events;events" go_package: "github.com/containerd/containerd/api/events;events"

View File

@ -31,6 +31,7 @@ import (
// snapshotter wraps snapshots.Snapshotter with proper events published. // snapshotter wraps snapshots.Snapshotter with proper events published.
type snapshotter struct { type snapshotter struct {
snapshots.Snapshotter snapshots.Snapshotter
name string
publisher events.Publisher publisher events.Publisher
} }
@ -55,16 +56,17 @@ func init() {
db := m.(*metadata.DB) db := m.(*metadata.DB)
ss := make(map[string]snapshots.Snapshotter) ss := make(map[string]snapshots.Snapshotter)
for n, sn := range db.Snapshotters() { for n, sn := range db.Snapshotters() {
ss[n] = newSnapshotter(sn, ep.(events.Publisher)) ss[n] = newSnapshotter(sn, n, ep.(events.Publisher))
} }
return ss, nil return ss, nil
}, },
}) })
} }
func newSnapshotter(sn snapshots.Snapshotter, publisher events.Publisher) snapshots.Snapshotter { func newSnapshotter(sn snapshots.Snapshotter, name string, publisher events.Publisher) snapshots.Snapshotter {
return &snapshotter{ return &snapshotter{
Snapshotter: sn, Snapshotter: sn,
name: name,
publisher: publisher, publisher: publisher,
} }
} }
@ -75,8 +77,9 @@ func (s *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...s
return nil, err return nil, err
} }
if err := s.publisher.Publish(ctx, "/snapshot/prepare", &eventstypes.SnapshotPrepare{ if err := s.publisher.Publish(ctx, "/snapshot/prepare", &eventstypes.SnapshotPrepare{
Key: key, Key: key,
Parent: parent, Parent: parent,
Snapshotter: s.name,
}); err != nil { }); err != nil {
return nil, err return nil, err
} }
@ -88,8 +91,9 @@ func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
return err return err
} }
return s.publisher.Publish(ctx, "/snapshot/commit", &eventstypes.SnapshotCommit{ return s.publisher.Publish(ctx, "/snapshot/commit", &eventstypes.SnapshotCommit{
Key: key, Key: key,
Name: name, Name: name,
Snapshotter: s.name,
}) })
} }
@ -98,6 +102,7 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
return err return err
} }
return s.publisher.Publish(ctx, "/snapshot/remove", &eventstypes.SnapshotRemove{ return s.publisher.Publish(ctx, "/snapshot/remove", &eventstypes.SnapshotRemove{
Key: key, Key: key,
Snapshotter: s.name,
}) })
} }