Containerd Server学习 Part 3

【编者的话】containerd v1.0.0的源码分析,以docker-containerd --config /var/run/docker/containerd/containerd.toml为入口

初始化Snapshot插件
  • 位置:cmd/containerd/builtins_xxx.go
package main

import (
    _ "github.com/llitfkitfk/containerd/snapshots/naive"
)

# `snapshots/naive/naive.go`
func init() {
    plugin.Register(&plugin.Registration{
        Type: plugin.SnapshotPlugin,
        ID:   "naive",
        InitFn: func(ic *plugin.InitContext) (interface{}, error) {
            ic.Meta.Platforms = append(ic.Meta.Platforms, platforms.DefaultSpec())
            return NewSnapshotter(ic.Root)
        },
    })
}
初始化Content插件
  • 位置:server/server.go
plugin.Register(&plugin.Registration{
    Type: plugin.ContentPlugin,
    ID:   "content",
    InitFn: func(ic *plugin.InitContext) (interface{}, error) {
        ic.Meta.Exports["root"] = ic.Root
        return local.NewStore(ic.Root)
    },
})

初始化Metadata插件
  • 位置:server/server.go
  • 依赖:github.com/boltdb/bolt

          plugin.Register(&plugin.Registration{
        Type: plugin.MetadataPlugin,
        ID:   "bolt",
        Requires: []plugin.Type{
            plugin.ContentPlugin,
            plugin.SnapshotPlugin,
        },

grpc服务拦截器
  • 位置:server/server.go
func interceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
    ctx = log.WithModule(ctx, "containerd")
    switch info.Server.(type) {
    case tasks.TasksServer:
        ctx = log.WithModule(ctx, "tasks")
    case containers.ContainersServer:
        ctx = log.WithModule(ctx, "containers")
    case contentapi.ContentServer:
        ctx = log.WithModule(ctx, "content")
    case images.ImagesServer:
        ctx = log.WithModule(ctx, "images")
    case grpc_health_v1.HealthServer:
        // No need to change the context
    case version.VersionServer:
        ctx = log.WithModule(ctx, "version")
    case snapshotsapi.SnapshotsServer:
        ctx = log.WithModule(ctx, "snapshot")
    case diff.DiffServer:
        ctx = log.WithModule(ctx, "diff")
    case namespaces.NamespacesServer:
        ctx = log.WithModule(ctx, "namespaces")
    case eventsapi.EventsServer:
        ctx = log.WithModule(ctx, "events")
    case introspection.IntrospectionServer:
        ctx = log.WithModule(ctx, "introspection")
    case leasesapi.LeasesServer:
        ctx = log.WithModule(ctx, "leases")
    default:
        log.G(ctx).Warnf("unknown GRPC server type: %#v\n", info.Server)
    }
    return grpc_prometheus.UnaryServerInterceptor(ctx, req, info, handler)
}

整理:

github.com/llitfkitfk/containerd/tree/part-3

你可能感兴趣的:(Containerd Server学习 Part 3)