Refactor runtime events into Task* types

This removes the RuntimeEvent super proto with enums into separate
runtime event protos to be inline with the other events that are output
by containerd.

This also renames the runtime events into Task* events.

Fixes #1071

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-07-11 16:12:14 -07:00
parent 8f1c11d862
commit 2b6d790ff4
17 changed files with 1831 additions and 2249 deletions

View File

@@ -1,9 +1,9 @@
package main
import (
"encoding/json"
"fmt"
"os"
"strings"
"text/tabwriter"
eventsapi "github.com/containerd/containerd/api/services/events/v1"
@@ -33,7 +33,11 @@ var eventsCommand = cli.Command{
return err
}
out, err := getEventOutput(e)
v, err := typeurl.UnmarshalAny(e.Event)
if err != nil {
return err
}
out, err := json.Marshal(v)
if err != nil {
return err
}
@@ -54,54 +58,3 @@ var eventsCommand = cli.Command{
}
},
}
func getEventOutput(env *eventsapi.Envelope) (string, error) {
out := ""
v, err := typeurl.UnmarshalAny(env.Event)
if err != nil {
return "", err
}
switch e := v.(type) {
case *eventsapi.ContainerCreate:
out = fmt.Sprintf("id=%s image=%s runtime=%s", e.ID, e.Image, e.Runtime)
case *eventsapi.TaskCreate:
out = "id=" + e.ContainerID
case *eventsapi.TaskStart:
out = "id=" + e.ContainerID
case *eventsapi.TaskDelete:
out = fmt.Sprintf("id=%s pid=%d status=%d", e.ContainerID, e.Pid, e.ExitStatus)
case *eventsapi.ContainerUpdate:
out = "id=" + e.ID
case *eventsapi.ContainerDelete:
out = "id=" + e.ID
case *eventsapi.SnapshotPrepare:
out = fmt.Sprintf("key=%s parent=%s", e.Key, e.Parent)
case *eventsapi.SnapshotCommit:
out = fmt.Sprintf("key=%s name=%s", e.Key, e.Name)
case *eventsapi.SnapshotRemove:
out = "key=" + e.Key
case *eventsapi.ImageUpdate:
out = fmt.Sprintf("name=%s labels=%s", e.Name, e.Labels)
case *eventsapi.ImageDelete:
out = "name=" + e.Name
case *eventsapi.NamespaceCreate:
out = fmt.Sprintf("name=%s labels=%s", e.Name, e.Labels)
case *eventsapi.NamespaceUpdate:
out = fmt.Sprintf("name=%s labels=%s", e.Name, e.Labels)
case *eventsapi.NamespaceDelete:
out = "name=" + e.Name
case *eventsapi.RuntimeCreate:
mounts := []string{}
for _, m := range e.RootFS {
mounts = append(mounts, fmt.Sprintf("type=%s:src=%s", m.Type, m.Source))
}
out = fmt.Sprintf("id=%s bundle=%s rootfs=%s checkpoint=%s", e.ContainerID, e.Bundle, strings.Join(mounts, ","), e.Checkpoint)
case *eventsapi.RuntimeEvent:
out = fmt.Sprintf("id=%s container_id=%s type=%s pid=%d status=%d exited=%s", e.ID, e.ContainerID, e.Type, e.Pid, e.ExitStatus, e.ExitedAt)
case *eventsapi.RuntimeDelete:
out = fmt.Sprintf("id=%s runtime=%s status=%d exited=%s", e.ContainerID, e.Runtime, e.ExitStatus, e.ExitedAt)
default:
out = env.Event.TypeUrl
}
return out, nil
}

View File

@@ -62,7 +62,6 @@ var shimCommand = cli.Command{
shimCreateCommand,
shimStartCommand,
shimDeleteCommand,
shimEventsCommand,
shimStateCommand,
shimExecCommand,
},
@@ -293,28 +292,6 @@ var shimExecCommand = cli.Command{
},
}
var shimEventsCommand = cli.Command{
Name: "events",
Usage: "get events for a shim",
Action: func(context *cli.Context) error {
service, err := getShimService(context)
if err != nil {
return err
}
events, err := service.Stream(gocontext.Background(), &shim.StreamEventsRequest{})
if err != nil {
return err
}
for {
e, err := events.Recv()
if err != nil {
return err
}
fmt.Printf("type=%s id=%s pid=%d status=%d\n", e.Type, e.ID, e.Pid, e.ExitStatus)
}
},
}
func getShimService(context *cli.Context) (shim.ShimClient, error) {
bindSocket := context.GlobalString("socket")
if bindSocket == "" {