From 993b863993e2e7b227c30eee3976a908be9d8712 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Thu, 15 Apr 2021 11:55:24 -0700 Subject: [PATCH] Add shim start opts Signed-off-by: Maksym Pavlenko --- runtime/v2/example/example.go | 2 +- runtime/v2/runc/v1/service.go | 6 +++--- runtime/v2/runc/v2/service.go | 8 ++++---- runtime/v2/shim/shim.go | 18 ++++++++++++++++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/runtime/v2/example/example.go b/runtime/v2/example/example.go index 5708e6f5b..995b3cc47 100644 --- a/runtime/v2/example/example.go +++ b/runtime/v2/example/example.go @@ -42,7 +42,7 @@ type service struct { } // StartShim is a binary call that executes a new shim returning the address -func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (string, error) { +func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (string, error) { return "", nil } diff --git a/runtime/v2/runc/v1/service.go b/runtime/v2/runc/v1/service.go index fac604166..71f2346d3 100644 --- a/runtime/v2/runc/v1/service.go +++ b/runtime/v2/runc/v1/service.go @@ -126,12 +126,12 @@ func newCommand(ctx context.Context, id, containerdBinary, containerdAddress, co return cmd, nil } -func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (_ string, retErr error) { - cmd, err := newCommand(ctx, id, containerdBinary, containerdAddress, containerdTTRPCAddress) +func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (_ string, retErr error) { + cmd, err := newCommand(ctx, opts.ID, opts.ContainerdBinary, opts.Address, opts.TTRPCAddress) if err != nil { return "", err } - address, err := shim.SocketAddress(ctx, containerdAddress, id) + address, err := shim.SocketAddress(ctx, opts.Address, opts.ID) if err != nil { return "", err } diff --git a/runtime/v2/runc/v2/service.go b/runtime/v2/runc/v2/service.go index 9bfffd1e0..317c3f8f0 100644 --- a/runtime/v2/runc/v2/service.go +++ b/runtime/v2/runc/v2/service.go @@ -171,12 +171,12 @@ func readSpec() (*spec, error) { return &s, nil } -func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (_ string, retErr error) { - cmd, err := newCommand(ctx, id, containerdBinary, containerdAddress, containerdTTRPCAddress) +func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (_ string, retErr error) { + cmd, err := newCommand(ctx, opts.ID, opts.ContainerdBinary, opts.Address, opts.TTRPCAddress) if err != nil { return "", err } - grouping := id + grouping := opts.ID spec, err := readSpec() if err != nil { return "", err @@ -187,7 +187,7 @@ func (s *service) StartShim(ctx context.Context, id, containerdBinary, container break } } - address, err := shim.SocketAddress(ctx, containerdAddress, grouping) + address, err := shim.SocketAddress(ctx, opts.Address, grouping) if err != nil { return "", err } diff --git a/runtime/v2/shim/shim.go b/runtime/v2/shim/shim.go index 68c81c9b7..8347968df 100644 --- a/runtime/v2/shim/shim.go +++ b/runtime/v2/shim/shim.go @@ -51,6 +51,14 @@ type Publisher interface { io.Closer } +// StartOpts describes shim start configuration received from containerd +type StartOpts struct { + ID string + ContainerdBinary string + Address string + TTRPCAddress string +} + // Init func for the creation of a shim server type Init func(context.Context, string, Publisher, func()) (Shim, error) @@ -58,7 +66,7 @@ type Init func(context.Context, string, Publisher, func()) (Shim, error) type Shim interface { shimapi.TaskService Cleanup(ctx context.Context) (*shimapi.DeleteResponse, error) - StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (string, error) + StartShim(ctx context.Context, opts StartOpts) (string, error) } // OptsKey is the context key for the Opts value. @@ -219,7 +227,13 @@ func run(id string, initFunc Init, config Config) error { } return nil case "start": - address, err := service.StartShim(ctx, idFlag, containerdBinaryFlag, addressFlag, ttrpcAddress) + opts := StartOpts{ + ID: idFlag, + ContainerdBinary: containerdBinaryFlag, + Address: addressFlag, + TTRPCAddress: ttrpcAddress, + } + address, err := service.StartShim(ctx, opts) if err != nil { return err }