本文是对containerd v0.2.4的源码分析。
Containerd源码流程图
![这里写图片描述](https://img-blog.csdn.net/20161228200102432?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvV2FsdG9uV2FuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
源码接口调用详情
从ctr调用containerd-api
checkpoint(用于快照,docker目前该功能不完善)
ctr cmd |
containerd-api |
list |
/types.API/ListCheckpoint |
create |
/types.API/CreateCheckpoint |
delete |
/types.API/DeleteCheckpoint |
containers
ctr cmd |
containerd-api |
list、state |
/types.API/State |
pause、resume、update |
/types.API/UpdateContainer |
create |
/types.API/CreateContainer |
stats |
/types.API/Stats |
watch |
/types.API/State, /types.API/Events |
exec |
/types.API/Events, /types.API/AddProcess, /types.API/UpdateProcess |
kill |
/types.API/Signal |
start |
/types.API/Events, /types.API/CreateContainer , /types.API/UpdateProcess |
update |
/types.API/UpdateContainer |
events
/types.API/Events
state
/types.API/State
version
/types.API/GetServerVersion –return result
从containerd-api至supervisor任务处理
注:API–server.go –> daemon – supervisor.go(handleTask func)
checkpoint
containerd-api |
supervisor |
/types.API/ListCheckpoint (supervisor.GetContainersTask) |
getContainers |
/types.API/CreateCheckpoint |
createCheckpoint |
/types.API/DeleteCheckpoint |
deleteCheckpoint |
containers
containerd-api |
supervisor |
/types.API/State /types.API/Stats (supervisor.GetContainersTask) |
getContainers |
/types.API/UpdateContainer (supervisor.UpdateTask) |
updateContainer |
/types.API/CreateContainer (supervisor.StartTask) |
start |
/types.API/Events |
Events |
/types.API/AddProcess |
addProcess |
/types.API/UpdateProcess |
updateProcess |
/types.API/Signal |
signal |
从supervisor至runtime(runC)
checkpoint
supervisor |
runtime |
getContainers |
- |
createCheckpoint |
(runtime)CheckPoint –>exec.Command(c.runtime,arg….) |
deleteCheckpoint |
(runtime)DeleteCheckpoint |
containers
supervisor |
runtime |
getContainers |
- |
updateContainer |
(runtime)Resume Pause UpdateResources–>exec.Command(c.runtime,arg….) |
start |
(runtime supervisor/worker.go) Start –>exec.Command(c.shim,c.id,c.bundle,c.runtime) |
addProcess |
(runtime) exec –> exec.Command(c.shim,c.id,c.bundle,c.runtime) |
updateProcess |
- |
signal |
- |
以createContainer为例走读代码
deamon启动监听tasks及startTasks进程
进入main.go main方法调用daemon方法
app.Action = func(context *cli.Context) {
if err := daemon(context)
logrus.Fatal(err)
}
}
进入main.go daemon方法
for i := 0; i <