PouchContainer and RPC

GRPC

PouchContainer Architecture

GRPC Application in PouchContainer

RPC server in CRI Manager

// Start CRI service with CRI version: v1alpha2
func runv1alpha2(daemonconfig *config.Config, containerMgr mgr.ContainerMgr, imageMgr mgr.ImageMgr) error {
······
criMgr, err := criv1alpha2.NewCriManager(daemonconfig, containerMgr, imageMgr)
······
server := grpc.NewServer(),
runtime.RegisterRuntimeServiceServer(server, criMgr)
runtime.RegisterImageServiceServer(server, criMgr)
······
service.Serve()
······
}

RPC Client in ctrd

// NewClient connect to containerd.
func NewClient(homeDir string, opts ...ClientOpt) (APIClient, error) {
// set default value for parameters
copts := clientOpts{
rpcAddr: unixSocketPath,
grpcClientPoolCapacity: defaultGrpcClientPoolCapacity,
maxStreamsClient: defaultMaxStreamsClient,
}
for _, opt := range opts {
if err := opt(&copts); err != nil {
return nil, err
}
}
client := &Client{
lock: &containerLock{
ids: make(map[string]struct{}),
},
watch: &watch{
containers: make(map[string]*containerPack),
},
daemonPid: -1,
homeDir: homeDir,
oomScoreAdjust: copts.oomScoreAdjust,
debugLog: copts.debugLog,
rpcAddr: copts.rpcAddr,
}
// start new containerd instance.
if copts.startDaemon {
if err := client.runContainerdDaemon(homeDir, copts); err != nil {
return nil, err
}
}
for i := 0; i < copts.grpcClientPoolCapacity; i++ {
cli, err := newWrapperClient(copts.rpcAddr, copts.defaultns, copts.maxStreamsClient)
if err != nil {
return nil, fmt.Errorf("failed to create containerd client: %v", err)
}
client.pool = append(client.pool, cli)
}
logrus.Infof("success to create %d containerd clients, connect to: %s", copts.grpcClientPoolCapacity, copts.rpcAddr) scheduler, err := scheduler.NewLRUScheduler(client.pool)
if err != nil {
return nil, fmt.Errorf("failed to create clients pool scheduler")
}
client.scheduler = scheduler
return client, nil
}

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store