Refactor differ into separate package

Add differ options and package with interface.
Update optional values on diff interface to use options.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2017-10-10 12:06:15 -07:00
parent 60960e1c17
commit d9db1d112d
14 changed files with 381 additions and 96 deletions

View File

@@ -3,6 +3,7 @@ package diff
import (
diffapi "github.com/containerd/containerd/api/services/diff/v1"
"github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/diff"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/plugin"
@@ -39,7 +40,7 @@ func init() {
}
orderedNames := ic.Config.(*config).Order
ordered := make([]plugin.Differ, len(orderedNames))
ordered := make([]diff.Differ, len(orderedNames))
for i, n := range orderedNames {
differp, ok := differs[n]
if !ok {
@@ -50,7 +51,7 @@ func init() {
return nil, errors.Wrapf(err, "could not load required differ due plugin init error: %s", n)
}
ordered[i] = differ.(plugin.Differ)
ordered[i] = differ.(diff.Differ)
}
return &service{
@@ -61,7 +62,7 @@ func init() {
}
type service struct {
differs []plugin.Differ
differs []diff.Differ
}
func (s *service) Register(gs *grpc.Server) error {
@@ -102,8 +103,19 @@ func (s *service) Diff(ctx context.Context, dr *diffapi.DiffRequest) (*diffapi.D
bMounts = toMounts(dr.Right)
)
var opts []diff.Opt
if dr.MediaType != "" {
opts = append(opts, diff.WithMediaType(dr.MediaType))
}
if dr.Ref != "" {
opts = append(opts, diff.WithReference(dr.Ref))
}
if dr.Labels != nil {
opts = append(opts, diff.WithLabels(dr.Labels))
}
for _, differ := range s.differs {
ocidesc, err = differ.DiffMounts(ctx, aMounts, bMounts, dr.MediaType, dr.Ref)
ocidesc, err = differ.DiffMounts(ctx, aMounts, bMounts, opts...)
if !errdefs.IsNotImplemented(err) {
break
}