Expose shim process interface

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko 2021-10-08 21:34:10 -07:00
parent 733519677f
commit 8b788d9dfe
2 changed files with 19 additions and 8 deletions

View File

@ -197,7 +197,7 @@ func (m *ShimManager) ID() string {
} }
// Start launches a new shim instance // Start launches a new shim instance
func (m *ShimManager) Start(ctx context.Context, id string, opts runtime.CreateOpts) (_ *shimTask, retErr error) { func (m *ShimManager) Start(ctx context.Context, id string, opts runtime.CreateOpts) (_ ShimProcess, retErr error) {
bundle, err := NewBundle(ctx, m.root, m.state, id, opts.Spec.Value) bundle, err := NewBundle(ctx, m.root, m.state, id, opts.Spec.Value)
if err != nil { if err != nil {
return nil, err return nil, err
@ -275,24 +275,24 @@ func (m *ShimManager) cleanupShim(shim *shim) {
m.list.Delete(dctx, shim.ID()) m.list.Delete(dctx, shim.ID())
} }
func (m *ShimManager) Get(ctx context.Context, id string) (*shim, error) { func (m *ShimManager) Get(ctx context.Context, id string) (ShimProcess, error) {
item, err := m.list.Get(ctx, id) proc, err := m.list.Get(ctx, id)
if err != nil { if err != nil {
return nil, err return nil, err
} }
shimTask := item.(*shimTask) return proc, nil
return shimTask.shim, nil
} }
// Delete a runtime task // Delete a runtime task
func (m *ShimManager) Delete(ctx context.Context, id string) error { func (m *ShimManager) Delete(ctx context.Context, id string) error {
shim, err := m.Get(ctx, id) proc, err := m.list.Get(ctx, id)
if err != nil { if err != nil {
return err return err
} }
err = shim.delete(ctx) shimTask := proc.(*shimTask)
err = shimTask.shim.delete(ctx)
m.list.Delete(ctx, id) m.list.Delete(ctx, id)
return err return err
@ -329,11 +329,12 @@ func (m *TaskManager) ID() string {
// Create launches new shim instance and creates new task // Create launches new shim instance and creates new task
func (m *TaskManager) Create(ctx context.Context, taskID string, opts runtime.CreateOpts) (runtime.Task, error) { func (m *TaskManager) Create(ctx context.Context, taskID string, opts runtime.CreateOpts) (runtime.Task, error) {
shim, err := m.shims.Start(ctx, taskID, opts) process, err := m.shims.Start(ctx, taskID, opts)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to start shim") return nil, errors.Wrap(err, "failed to start shim")
} }
shim := process.(*shimTask)
t, err := shim.Create(ctx, opts) t, err := shim.Create(ctx, opts)
if err != nil { if err != nil {
dctx, cancel := timeout.WithContext(context.Background(), cleanupTimeout) dctx, cancel := timeout.WithContext(context.Background(), cleanupTimeout)

View File

@ -186,6 +186,16 @@ func cleanupAfterDeadShim(ctx context.Context, id, ns string, rt *runtime.TaskLi
}) })
} }
// ShimProcess represents a shim instance managed by the shim service.
type ShimProcess interface {
runtime.Process
// ID of the shim.
ID() string
// Namespace of this shim.
Namespace() string
}
type shim struct { type shim struct {
bundle *Bundle bundle *Bundle
client *ttrpc.Client client *ttrpc.Client