Add field to Container for client-defined data

This field allows a client to store specialized information in the
container metadata rather than having to store this itself and keep
the data in sync with containerd.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff
2017-08-17 15:22:46 -04:00
parent d0457b2213
commit 3552ce5688
12 changed files with 350 additions and 48 deletions

View File

@@ -127,3 +127,21 @@ func setSnapshotterIfEmpty(c *containers.Container) {
c.Snapshotter = DefaultSnapshotter
}
}
// WithContainerExtension appends extension data to the container object.
// Use this to decorate the container object with additional data for the client
// integration.
//
// Make sure to register the type of `extension` in the typeurl package via
// `typeurl.Register` otherwise the type data will be inferred, including how
// to encode and decode the object.
func WithContainerExtension(extension interface{}) NewContainerOpts {
return func(ctx context.Context, client *Client, c *containers.Container) error {
any, err := typeurl.MarshalAny(extension)
if err != nil {
return err
}
c.Extensions = append(c.Extensions, *any)
return nil
}
}