events: move types into service package
When using events, it was found to be fairly unwieldy with a number of extra packages. For the most part, when interacting with the events service, we want types of the same version of the service. This has been accomplished by moving all events types into the events package. In addition, several fixes to the way events are marshaled have been included. Specifically, we defer to the protobuf type registration system to assemble events and type urls, with a little bit sheen on top of add a containerd.io oriented namespace. This has resulted in much cleaner event consumption and has removed the reliance on error prone type urls, in favor of concrete types. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
18
process.go
18
process.go
@@ -7,9 +7,8 @@ import (
|
||||
|
||||
eventsapi "github.com/containerd/containerd/api/services/events/v1"
|
||||
"github.com/containerd/containerd/api/services/tasks/v1"
|
||||
"github.com/containerd/containerd/api/types/event"
|
||||
tasktypes "github.com/containerd/containerd/api/types/task"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/containerd/containerd/events"
|
||||
protobuf "github.com/gogo/protobuf/types"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
@@ -74,24 +73,27 @@ func (p *process) Kill(ctx context.Context, s syscall.Signal) error {
|
||||
|
||||
func (p *process) Wait(ctx context.Context) (uint32, error) {
|
||||
// TODO (ehazlett): add filtering for specific event
|
||||
events, err := p.task.client.EventService().Stream(ctx, &eventsapi.StreamEventsRequest{})
|
||||
eventstream, err := p.task.client.EventService().Stream(ctx, &eventsapi.StreamEventsRequest{})
|
||||
if err != nil {
|
||||
return UnknownExitStatus, err
|
||||
}
|
||||
<-p.pidSync
|
||||
evloop:
|
||||
for {
|
||||
evt, err := events.Recv()
|
||||
evt, err := eventstream.Recv()
|
||||
if err != nil {
|
||||
return UnknownExitStatus, err
|
||||
}
|
||||
if evt.Event.TypeUrl == "types.containerd.io/containerd.v1.types.event.RuntimeEvent" {
|
||||
e := &event.RuntimeEvent{}
|
||||
if err := proto.Unmarshal(evt.Event.Value, e); err != nil {
|
||||
|
||||
switch {
|
||||
case events.Is(evt.Event, &eventsapi.RuntimeEvent{}):
|
||||
var e eventsapi.RuntimeEvent
|
||||
if err := events.UnmarshalEvent(evt.Event, &e); err != nil {
|
||||
return UnknownExitStatus, err
|
||||
}
|
||||
|
||||
if e.Type != tasktypes.Event_EXIT {
|
||||
continue
|
||||
continue evloop
|
||||
}
|
||||
|
||||
if e.ID == p.task.containerID && e.Pid == p.pid {
|
||||
|
Reference in New Issue
Block a user