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:
parent
b56cac143a
commit
4ac1031e0c
@ -41,8 +41,9 @@ type SnapshotPrepare struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
Parent string `protobuf:"bytes,2,opt,name=parent,proto3" json:"parent,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"`
|
||||
Snapshotter string `protobuf:"bytes,5,opt,name=snapshotter,proto3" json:"snapshotter,omitempty"`
|
||||
}
|
||||
|
||||
func (x *SnapshotPrepare) Reset() {
|
||||
@ -91,13 +92,21 @@ 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
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,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"`
|
||||
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"`
|
||||
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 (
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
@ -75,8 +77,9 @@ func (s *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...s
|
||||
return nil, err
|
||||
}
|
||||
if err := s.publisher.Publish(ctx, "/snapshot/prepare", &eventstypes.SnapshotPrepare{
|
||||
Key: key,
|
||||
Parent: parent,
|
||||
Key: key,
|
||||
Parent: parent,
|
||||
Snapshotter: s.name,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -88,8 +91,9 @@ func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
|
||||
return err
|
||||
}
|
||||
return s.publisher.Publish(ctx, "/snapshot/commit", &eventstypes.SnapshotCommit{
|
||||
Key: key,
|
||||
Name: name,
|
||||
Key: key,
|
||||
Name: name,
|
||||
Snapshotter: s.name,
|
||||
})
|
||||
}
|
||||
|
||||
@ -98,6 +102,7 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
|
||||
return err
|
||||
}
|
||||
return s.publisher.Publish(ctx, "/snapshot/remove", &eventstypes.SnapshotRemove{
|
||||
Key: key,
|
||||
Key: key,
|
||||
Snapshotter: s.name,
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user