Merge pull request #5368 from mxpv/runtime_cleanup

Runtime cleanup
This commit is contained in:
Phil Estes 2021-04-16 14:50:15 -04:00 committed by GitHub
commit 1e5cb4edcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 32 deletions

View File

@ -63,14 +63,14 @@ type PlatformRuntime interface {
// ID of the runtime // ID of the runtime
ID() string ID() string
// Create creates a task with the provided id and options. // Create creates a task with the provided id and options.
Create(ctx context.Context, id string, opts CreateOpts) (Task, error) Create(ctx context.Context, taskID string, opts CreateOpts) (Task, error)
// Get returns a task. // Get returns a task.
Get(context.Context, string) (Task, error) Get(ctx context.Context, taskID string) (Task, error)
// Tasks returns all the current tasks for the runtime. // Tasks returns all the current tasks for the runtime.
// Any container runs at most one task at a time. // Any container runs at most one task at a time.
Tasks(context.Context, bool) ([]Task, error) Tasks(ctx context.Context, all bool) ([]Task, error)
// Add adds a task into runtime. // Add adds a task into runtime.
Add(context.Context, Task) error Add(ctx context.Context, task Task) error
// Delete remove a task. // Delete remove a task.
Delete(context.Context, string) Delete(ctx context.Context, taskID string)
} }

View File

@ -36,19 +36,19 @@ type Process interface {
// ID of the process // ID of the process
ID() string ID() string
// State returns the process state // State returns the process state
State(context.Context) (State, error) State(ctx context.Context) (State, error)
// Kill signals a container // Kill signals a container
Kill(context.Context, uint32, bool) error Kill(ctx context.Context, signal uint32, all bool) error
// Pty resizes the processes pty/console // ResizePty resizes the processes pty/console
ResizePty(context.Context, ConsoleSize) error ResizePty(ctx context.Context, size ConsoleSize) error
// CloseStdin closes the processes stdin // CloseIO closes the processes IO
CloseIO(context.Context) error CloseIO(ctx context.Context) error
// Start the container's user defined process // Start the container's user defined process
Start(context.Context) error Start(ctx context.Context) error
// Wait for the process to exit // Wait for the process to exit
Wait(context.Context) (*Exit, error) Wait(ctx context.Context) (*Exit, error)
// Delete deletes the process // Delete deletes the process
Delete(context.Context) (*Exit, error) Delete(ctx context.Context) (*Exit, error)
} }
// Task is the runtime object for an executing container // Task is the runtime object for an executing container
@ -60,21 +60,21 @@ type Task interface {
// Namespace that the task exists in // Namespace that the task exists in
Namespace() string Namespace() string
// Pause pauses the container process // Pause pauses the container process
Pause(context.Context) error Pause(ctx context.Context) error
// Resume unpauses the container process // Resume unpauses the container process
Resume(context.Context) error Resume(ctx context.Context) error
// Exec adds a process into the container // Exec adds a process into the container
Exec(context.Context, string, ExecOpts) (Process, error) Exec(ctx context.Context, id string, opts ExecOpts) (Process, error)
// Pids returns all pids // Pids returns all pids
Pids(context.Context) ([]ProcessInfo, error) Pids(ctx context.Context) ([]ProcessInfo, error)
// Checkpoint checkpoints a container to an image with live system data // Checkpoint checkpoints a container to an image with live system data
Checkpoint(context.Context, string, *types.Any) error Checkpoint(ctx context.Context, path string, opts *types.Any) error
// Update sets the provided resources to a running task // Update sets the provided resources to a running task
Update(context.Context, *types.Any, map[string]string) error Update(ctx context.Context, resources *types.Any, annotations map[string]string) error
// Process returns a process within the task for the provided id // Process returns a process within the task for the provided id
Process(context.Context, string) (Process, error) Process(ctx context.Context, id string) (Process, error)
// Stats returns runtime specific metrics for a task // Stats returns runtime specific metrics for a task
Stats(context.Context) (*types.Any, error) Stats(ctx context.Context) (*types.Any, error)
} }
// ExecOpts provides additional options for additional processes running in a task // ExecOpts provides additional options for additional processes running in a task

View File

@ -42,7 +42,7 @@ type service struct {
} }
// StartShim is a binary call that executes a new shim returning the address // 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 return "", nil
} }

View File

@ -126,12 +126,12 @@ func newCommand(ctx context.Context, id, containerdBinary, containerdAddress, co
return cmd, nil return cmd, nil
} }
func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (_ string, retErr error) { func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (_ string, retErr error) {
cmd, err := newCommand(ctx, id, containerdBinary, containerdAddress, containerdTTRPCAddress) cmd, err := newCommand(ctx, opts.ID, opts.ContainerdBinary, opts.Address, opts.TTRPCAddress)
if err != nil { if err != nil {
return "", err return "", err
} }
address, err := shim.SocketAddress(ctx, containerdAddress, id) address, err := shim.SocketAddress(ctx, opts.Address, opts.ID)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -171,12 +171,12 @@ func readSpec() (*spec, error) {
return &s, nil return &s, nil
} }
func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (_ string, retErr error) { func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (_ string, retErr error) {
cmd, err := newCommand(ctx, id, containerdBinary, containerdAddress, containerdTTRPCAddress) cmd, err := newCommand(ctx, opts.ID, opts.ContainerdBinary, opts.Address, opts.TTRPCAddress)
if err != nil { if err != nil {
return "", err return "", err
} }
grouping := id grouping := opts.ID
spec, err := readSpec() spec, err := readSpec()
if err != nil { if err != nil {
return "", err return "", err
@ -187,7 +187,7 @@ func (s *service) StartShim(ctx context.Context, id, containerdBinary, container
break break
} }
} }
address, err := shim.SocketAddress(ctx, containerdAddress, grouping) address, err := shim.SocketAddress(ctx, opts.Address, grouping)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -51,6 +51,14 @@ type Publisher interface {
io.Closer 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 // Init func for the creation of a shim server
type Init func(context.Context, string, Publisher, func()) (Shim, error) 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 { type Shim interface {
shimapi.TaskService shimapi.TaskService
Cleanup(ctx context.Context) (*shimapi.DeleteResponse, error) 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. // OptsKey is the context key for the Opts value.
@ -219,7 +227,13 @@ func run(id string, initFunc Init, config Config) error {
} }
return nil return nil
case "start": 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 { if err != nil {
return err return err
} }