Skip to content

Commit 1e5cb4e

Browse files
authored
Merge pull request #5368 from mxpv/runtime_cleanup
Runtime cleanup
2 parents f0890f9 + b83d04f commit 1e5cb4e

6 files changed

Lines changed: 46 additions & 32 deletions

File tree

runtime/runtime.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ type PlatformRuntime interface {
6363
// ID of the runtime
6464
ID() string
6565
// Create creates a task with the provided id and options.
66-
Create(ctx context.Context, id string, opts CreateOpts) (Task, error)
66+
Create(ctx context.Context, taskID string, opts CreateOpts) (Task, error)
6767
// Get returns a task.
68-
Get(context.Context, string) (Task, error)
68+
Get(ctx context.Context, taskID string) (Task, error)
6969
// Tasks returns all the current tasks for the runtime.
7070
// Any container runs at most one task at a time.
71-
Tasks(context.Context, bool) ([]Task, error)
71+
Tasks(ctx context.Context, all bool) ([]Task, error)
7272
// Add adds a task into runtime.
73-
Add(context.Context, Task) error
73+
Add(ctx context.Context, task Task) error
7474
// Delete remove a task.
75-
Delete(context.Context, string)
75+
Delete(ctx context.Context, taskID string)
7676
}

runtime/task.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ type Process interface {
3636
// ID of the process
3737
ID() string
3838
// State returns the process state
39-
State(context.Context) (State, error)
39+
State(ctx context.Context) (State, error)
4040
// Kill signals a container
41-
Kill(context.Context, uint32, bool) error
42-
// Pty resizes the processes pty/console
43-
ResizePty(context.Context, ConsoleSize) error
44-
// CloseStdin closes the processes stdin
45-
CloseIO(context.Context) error
41+
Kill(ctx context.Context, signal uint32, all bool) error
42+
// ResizePty resizes the processes pty/console
43+
ResizePty(ctx context.Context, size ConsoleSize) error
44+
// CloseIO closes the processes IO
45+
CloseIO(ctx context.Context) error
4646
// Start the container's user defined process
47-
Start(context.Context) error
47+
Start(ctx context.Context) error
4848
// Wait for the process to exit
49-
Wait(context.Context) (*Exit, error)
49+
Wait(ctx context.Context) (*Exit, error)
5050
// Delete deletes the process
51-
Delete(context.Context) (*Exit, error)
51+
Delete(ctx context.Context) (*Exit, error)
5252
}
5353

5454
// Task is the runtime object for an executing container
@@ -60,21 +60,21 @@ type Task interface {
6060
// Namespace that the task exists in
6161
Namespace() string
6262
// Pause pauses the container process
63-
Pause(context.Context) error
63+
Pause(ctx context.Context) error
6464
// Resume unpauses the container process
65-
Resume(context.Context) error
65+
Resume(ctx context.Context) error
6666
// Exec adds a process into the container
67-
Exec(context.Context, string, ExecOpts) (Process, error)
67+
Exec(ctx context.Context, id string, opts ExecOpts) (Process, error)
6868
// Pids returns all pids
69-
Pids(context.Context) ([]ProcessInfo, error)
69+
Pids(ctx context.Context) ([]ProcessInfo, error)
7070
// Checkpoint checkpoints a container to an image with live system data
71-
Checkpoint(context.Context, string, *types.Any) error
71+
Checkpoint(ctx context.Context, path string, opts *types.Any) error
7272
// Update sets the provided resources to a running task
73-
Update(context.Context, *types.Any, map[string]string) error
73+
Update(ctx context.Context, resources *types.Any, annotations map[string]string) error
7474
// Process returns a process within the task for the provided id
75-
Process(context.Context, string) (Process, error)
75+
Process(ctx context.Context, id string) (Process, error)
7676
// Stats returns runtime specific metrics for a task
77-
Stats(context.Context) (*types.Any, error)
77+
Stats(ctx context.Context) (*types.Any, error)
7878
}
7979

8080
// ExecOpts provides additional options for additional processes running in a task

runtime/v2/example/example.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type service struct {
4242
}
4343

4444
// StartShim is a binary call that executes a new shim returning the address
45-
func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (string, error) {
45+
func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (string, error) {
4646
return "", nil
4747
}
4848

runtime/v2/runc/v1/service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ func newCommand(ctx context.Context, id, containerdBinary, containerdAddress, co
126126
return cmd, nil
127127
}
128128

129-
func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (_ string, retErr error) {
130-
cmd, err := newCommand(ctx, id, containerdBinary, containerdAddress, containerdTTRPCAddress)
129+
func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (_ string, retErr error) {
130+
cmd, err := newCommand(ctx, opts.ID, opts.ContainerdBinary, opts.Address, opts.TTRPCAddress)
131131
if err != nil {
132132
return "", err
133133
}
134-
address, err := shim.SocketAddress(ctx, containerdAddress, id)
134+
address, err := shim.SocketAddress(ctx, opts.Address, opts.ID)
135135
if err != nil {
136136
return "", err
137137
}

runtime/v2/runc/v2/service.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ func readSpec() (*spec, error) {
171171
return &s, nil
172172
}
173173

174-
func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (_ string, retErr error) {
175-
cmd, err := newCommand(ctx, id, containerdBinary, containerdAddress, containerdTTRPCAddress)
174+
func (s *service) StartShim(ctx context.Context, opts shim.StartOpts) (_ string, retErr error) {
175+
cmd, err := newCommand(ctx, opts.ID, opts.ContainerdBinary, opts.Address, opts.TTRPCAddress)
176176
if err != nil {
177177
return "", err
178178
}
179-
grouping := id
179+
grouping := opts.ID
180180
spec, err := readSpec()
181181
if err != nil {
182182
return "", err
@@ -187,7 +187,7 @@ func (s *service) StartShim(ctx context.Context, id, containerdBinary, container
187187
break
188188
}
189189
}
190-
address, err := shim.SocketAddress(ctx, containerdAddress, grouping)
190+
address, err := shim.SocketAddress(ctx, opts.Address, grouping)
191191
if err != nil {
192192
return "", err
193193
}

runtime/v2/shim/shim.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,22 @@ type Publisher interface {
5151
io.Closer
5252
}
5353

54+
// StartOpts describes shim start configuration received from containerd
55+
type StartOpts struct {
56+
ID string
57+
ContainerdBinary string
58+
Address string
59+
TTRPCAddress string
60+
}
61+
5462
// Init func for the creation of a shim server
5563
type Init func(context.Context, string, Publisher, func()) (Shim, error)
5664

5765
// Shim server interface
5866
type Shim interface {
5967
shimapi.TaskService
6068
Cleanup(ctx context.Context) (*shimapi.DeleteResponse, error)
61-
StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (string, error)
69+
StartShim(ctx context.Context, opts StartOpts) (string, error)
6270
}
6371

6472
// OptsKey is the context key for the Opts value.
@@ -219,7 +227,13 @@ func run(id string, initFunc Init, config Config) error {
219227
}
220228
return nil
221229
case "start":
222-
address, err := service.StartShim(ctx, idFlag, containerdBinaryFlag, addressFlag, ttrpcAddress)
230+
opts := StartOpts{
231+
ID: idFlag,
232+
ContainerdBinary: containerdBinaryFlag,
233+
Address: addressFlag,
234+
TTRPCAddress: ttrpcAddress,
235+
}
236+
address, err := service.StartShim(ctx, opts)
223237
if err != nil {
224238
return err
225239
}

0 commit comments

Comments
 (0)