Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method called by the containerd source code interface

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is the method of calling containerd source code interface". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the method of calling the containerd source interface?"

Source code API call details call containerd-api from ctr

# checkpoint (for snapshots, the function of docker is not perfect) | 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

Task processing from containerd-api to supervisor

Note: 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 |

From supervisor to runtime (runC)

# checkpoint | supervisor | runtime | |-| | getContainers |-| | createCheckpoint | (runtime) CheckPoint-- > exec.Command (c.runtimemilitary 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.shimforce c.idrec.bundlerec.runtime) | | addProcess | (runtime) exec-- > exec.Command (c.shimjournal c.bundlerec.runtime) | | updateProcess |-| signal |-|

# # take createContainer as an example to read the code # deamon starts listening to tasks and startTasks process # enter the main.go main method and call the daemon method

App.Action = func (context * cli.Context) {if err: = daemon (context); err! = nil {logrus.Fatal (err)}}

# enter main.go daemon method

For I: = 0; I < 10; iTunes + {wg.Add (1) w: = supervisor.NewWorker (sv, wg) go w.Start ()} if err: = sv.Start (); err! = nil {return err}

# initialize supervisor/worker.go NewWorker and start listening startTask and processing

Func NewWorker (s * Supervisor, wg * sync.WaitGroup) Worker {return & worker {s: s, wg: wg,}} func (w * worker) Start () {defer w.wg.Done () for t: = range w.s.startTasks {started: = time.Now () process, err: = t.Container.Start (t.CheckpointPath, runtime.NewStdio (t.Stdin) T.Stdout, t.Stderr) if err! = nil {logrus.WithFields (logrus.Fields {"error": err, "id": t.Container.ID (),}) .Error ("containerd: start container") t.Err

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report