Return event publish errors.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu
2019-04-04 14:54:52 -07:00
parent 4edc7336a2
commit 74eb0dc812
2 changed files with 26 additions and 5 deletions

View File

@@ -59,6 +59,12 @@ var (
criuFlag string
systemdCgroupFlag bool
containerdBinaryFlag string
bufPool = sync.Pool{
New: func() interface{} {
return bytes.NewBuffer(nil)
},
}
)
func init() {
@@ -275,16 +281,20 @@ func (l *remoteEventsPublisher) Publish(ctx context.Context, topic string, event
}
cmd := exec.CommandContext(ctx, containerdBinaryFlag, "--address", l.address, "publish", "--topic", topic, "--namespace", ns)
cmd.Stdin = bytes.NewReader(data)
b := bufPool.Get().(*bytes.Buffer)
defer bufPool.Put(b)
cmd.Stdout = b
cmd.Stderr = b
c, err := shim.Default.Start(cmd)
if err != nil {
return err
}
status, err := shim.Default.Wait(cmd, c)
if err != nil {
return err
return errors.Wrapf(err, "failed to publish event: %s", b.String())
}
if status != 0 {
return errors.New("failed to publish event")
return errors.Errorf("failed to publish event: %s", b.String())
}
return nil
}