linux/shim: use events.Publisher interface

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day
2017-07-31 13:27:45 -07:00
parent 92d737f4ae
commit 7ed88c1e36
4 changed files with 54 additions and 60 deletions

View File

@@ -3,6 +3,7 @@
package main
import (
"context"
"fmt"
"net"
"os"
@@ -10,18 +11,19 @@ import (
"strings"
"time"
"golang.org/x/sys/unix"
"google.golang.org/grpc"
events "github.com/containerd/containerd/api/services/events/v1"
eventsapi "github.com/containerd/containerd/api/services/events/v1"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/events"
"github.com/containerd/containerd/linux/shim"
shimapi "github.com/containerd/containerd/linux/shim/v1"
"github.com/containerd/containerd/reaper"
"github.com/containerd/containerd/typeurl"
"github.com/containerd/containerd/version"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"golang.org/x/sys/unix"
"google.golang.org/grpc"
)
const usage = `
@@ -82,7 +84,7 @@ func main() {
sv, err := shim.NewService(
path,
context.GlobalString("namespace"),
e,
&remoteEventsPublisher{client: e},
)
if err != nil {
return err
@@ -163,12 +165,12 @@ func dumpStacks() {
logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)
}
func connectEvents(address string) (events.EventsClient, error) {
func connectEvents(address string) (eventsapi.EventsClient, error) {
conn, err := connect(address, dialer)
if err != nil {
return nil, errors.Wrapf(err, "failed to dial %q", address)
}
return events.NewEventsClient(conn), nil
return eventsapi.NewEventsClient(conn), nil
}
func connect(address string, d func(string, time.Duration) (net.Conn, error)) (*grpc.ClientConn, error) {
@@ -194,3 +196,21 @@ func dialer(address string, timeout time.Duration) (net.Conn, error) {
func dialAddress(address string) string {
return fmt.Sprintf("unix://%s", address)
}
type remoteEventsPublisher struct {
client eventsapi.EventsClient
}
func (l *remoteEventsPublisher) Publish(ctx context.Context, topic string, event events.Event) error {
encoded, err := typeurl.MarshalAny(event)
if err != nil {
return err
}
if _, err := l.client.Publish(ctx, &eventsapi.PublishRequest{
Topic: topic,
Event: encoded,
}); err != nil {
return errdefs.FromGRPC(err)
}
return nil
}