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

@ -43,6 +43,7 @@ type SnapshotPrepare struct {
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,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() {
@ -91,6 +92,13 @@ func (x *SnapshotPrepare) GetParent() string {
return ""
}
func (x *SnapshotPrepare) GetSnapshotter() string {
if x != nil {
return x.Snapshotter
}
return ""
}
type SnapshotCommit struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -98,6 +106,7 @@ type SnapshotCommit struct {
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,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() {
@ -146,12 +155,20 @@ func (x *SnapshotCommit) GetName() string {
return ""
}
func (x *SnapshotCommit) GetSnapshotter() string {
if x != nil {
return x.Snapshotter
}
return ""
}
type SnapshotRemove struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
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() {
@ -193,6 +210,13 @@ func (x *SnapshotRemove) GetKey() string {
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_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,
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,
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,
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,
0x0a, 0x0e, 0x53, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b,
0x65, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x22, 0x0a, 0x0e, 0x53, 0x6e, 0x61, 0x70, 0x73, 0x68,
0x6f, 0x74, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 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,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 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,
0x22, 0x58, 0x0a, 0x0e, 0x53, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x43, 0x6f, 0x6d, 0x6d,
0x69, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x03, 0x6b, 0x65, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 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, 0x22, 0x44, 0x0a, 0x0e, 0x53, 0x6e,
0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x12, 0x10, 0x0a, 0x03,
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 (

View File

@ -26,13 +26,16 @@ option (containerd.plugin.fieldpath_all) = true;
message SnapshotPrepare {
string key = 1;
string parent = 2;
string snapshotter = 5;
}
message SnapshotCommit {
string key = 1;
string name = 2;
string snapshotter = 5;
}
message SnapshotRemove {
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
case "parent":
return string(m.Parent), len(m.Parent) > 0
case "snapshotter":
return string(m.Snapshotter), len(m.Snapshotter) > 0
}
return "", false
}
@ -28,6 +30,8 @@ func (m *SnapshotCommit) Field(fieldpath []string) (string, bool) {
return string(m.Key), len(m.Key) > 0
case "name":
return string(m.Name), len(m.Name) > 0
case "snapshotter":
return string(m.Snapshotter), len(m.Snapshotter) > 0
}
return "", false
}
@ -41,6 +45,8 @@ func (m *SnapshotRemove) Field(fieldpath []string) (string, bool) {
switch fieldpath[0] {
case "key":
return string(m.Key), len(m.Key) > 0
case "snapshotter":
return string(m.Snapshotter), len(m.Snapshotter) > 0
}
return "", false
}

View File

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

View File

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