/
localworker.go
131 lines (109 loc) · 3.65 KB
/
localworker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package worker
import (
"context"
"syscall"
"github.com/containerd/containerd"
"github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/namespaces"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
func NewLocalWorker(id string, pid uint32) *Worker {
ctx := namespaces.WithNamespace(context.Background(), "refunction-worker"+id)
return &Worker{
ID: id,
targetSnapshot: "",
runtime: "",
ctx: ctx,
creator: cio.NullIO,
task: &localTask{
id: id,
pid: pid,
},
}
}
type localTask struct {
id string
pid uint32
}
func (lt *localTask) ID() string {
return lt.id
}
// Pid is the system specific process id
func (lt *localTask) Pid() uint32 {
return lt.pid
}
// Start starts the process executing the user's defined binary
func (lt *localTask) Start(context.Context) error {
return nil
}
// Delete removes the process and any resources allocated returning the exit status
func (lt *localTask) Delete(context.Context, ...containerd.ProcessDeleteOpts) (*containerd.ExitStatus, error) {
return nil, nil
}
// Kill sends the provided signal to the process
func (lt *localTask) Kill(context.Context, syscall.Signal, ...containerd.KillOpts) error {
return nil
}
// Wait asynchronously waits for the process to exit, and sends the exit code to the returned channel
func (lt *localTask) Wait(context.Context) (<-chan containerd.ExitStatus, error) {
c := make(chan containerd.ExitStatus)
return c, nil
}
// CloseIO allows various pipes to be closed on the process
func (lt *localTask) CloseIO(context.Context, ...containerd.IOCloserOpts) error {
return nil
}
// Resize changes the width and heigh of the process's terminal
func (lt *localTask) Resize(ctx context.Context, w, h uint32) error {
return nil
}
// IO returns the io set for the process
func (lt *localTask) IO() cio.IO {
return nil
}
// Status returns the executing status of the process
func (lt *localTask) Status(context.Context) (containerd.Status, error) {
return containerd.Status{
Status: "running",
}, nil
}
// Pause suspends the execution of the task
func (lt *localTask) Pause(context.Context) error {
return nil
}
// Resume the execution of the task
func (lt *localTask) Resume(context.Context) error {
return nil
}
// Exec creates a new process inside the task
func (lt *localTask) Exec(context.Context, string, *specs.Process, cio.Creator) (containerd.Process, error) {
return lt, nil
}
// Pids returns a list of system specific process ids inside the task
func (lt *localTask) Pids(context.Context) ([]containerd.ProcessInfo, error) {
return []containerd.ProcessInfo{}, nil
}
// Checkpoint serializes the runtime and memory information of a task into an
// OCI Index that can be push and pulled from a remote resource.
//
// Additional software like CRIU maybe required to checkpoint and restore tasks
func (lt *localTask) Checkpoint(context.Context, ...containerd.CheckpointTaskOpts) (containerd.Image, error) {
return nil, nil
}
// Update modifies executing tasks with updated settings
func (lt *localTask) Update(context.Context, ...containerd.UpdateTaskOpts) error {
return nil
}
// LoadProcess loads a previously created exec'd process
func (lt *localTask) LoadProcess(context.Context, string, cio.Attach) (containerd.Process, error) {
return lt, nil
}
// Metrics returns task metrics for runtime specific metrics
//
// The metric types are generic to containerd and change depending on the runtime
// For the built in Linux runtime, github.com/containerd/cgroups.Metrics
// are returned in protobuf format
func (lt *localTask) Metrics(context.Context) (*types.Metric, error) {
return nil, nil
}