X Tutup
Skip to content

Commit 568b5be

Browse files
committed
runtime: add Add/Delete method in PlatformRuntime interface
The two new method Add/Delete can allow custom plugin to add or migrate existing task into major Runtime plugin. close: containerd#2888 Signed-off-by: Wei Fu <fuweid89@gmail.com>
1 parent 06e04bc commit 568b5be

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

runtime/runtime.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ type PlatformRuntime interface {
6969
// Tasks returns all the current tasks for the runtime.
7070
// Any container runs at most one task at a time.
7171
Tasks(context.Context, bool) ([]Task, error)
72+
// Add adds a task into runtime.
73+
Add(context.Context, Task) error
74+
// Delete remove a task.
75+
Delete(context.Context, string)
7276
}

runtime/v1/linux/runtime.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,16 @@ func (r *Runtime) Get(ctx context.Context, id string) (runtime.Task, error) {
305305
return r.tasks.Get(ctx, id)
306306
}
307307

308+
// Add a runtime task
309+
func (r *Runtime) Add(ctx context.Context, task runtime.Task) error {
310+
return r.tasks.Add(ctx, task)
311+
}
312+
313+
// Delete a runtime task
314+
func (r *Runtime) Delete(ctx context.Context, id string) {
315+
r.tasks.Delete(ctx, id)
316+
}
317+
308318
func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
309319
dir, err := ioutil.ReadDir(filepath.Join(r.state, ns))
310320
if err != nil {

runtime/v2/manager.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ func (m *TaskManager) Get(ctx context.Context, id string) (runtime.Task, error)
130130
return m.tasks.Get(ctx, id)
131131
}
132132

133+
// Add a runtime task
134+
func (m *TaskManager) Add(ctx context.Context, task runtime.Task) error {
135+
return m.tasks.Add(ctx, task)
136+
}
137+
138+
// Delete a runtime task
139+
func (m *TaskManager) Delete(ctx context.Context, id string) {
140+
m.tasks.Delete(ctx, id)
141+
}
142+
133143
// Tasks lists all tasks
134144
func (m *TaskManager) Tasks(ctx context.Context, all bool) ([]runtime.Task, error) {
135145
return m.tasks.GetAll(ctx, all)

windows/runtime.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ func (r *windowsRuntime) Tasks(ctx context.Context, all bool) ([]runtime.Task, e
153153
return r.tasks.GetAll(ctx, all)
154154
}
155155

156+
func (r *windowsRuntime) Add(ctx context.Context, task runtime.Task) error {
157+
return r.tasks.Add(ctx, task)
158+
}
159+
160+
func (r *windowsRuntime) Delete(ctx context.Context, id string) {
161+
r.tasks.Delete(ctx, id)
162+
}
163+
156164
func (r *windowsRuntime) newTask(ctx context.Context, namespace, id string, rootfs []mount.Mount, spec *runtimespec.Spec, io runtime.IO, createOpts *hcsshimtypes.CreateOptions) (*task, error) {
157165
var (
158166
err error

0 commit comments

Comments
 (0)
X Tutup