美文网首页
Containerd Server学习 Part 2

Containerd Server学习 Part 2

作者: llitfk_DockOne | 来源:发表于2018-02-02 16:47 被阅读45次

    【编者的话】containerd v1.0.0的源码分析,以docker-containerd --config /var/run/docker/containerd/containerd.toml为入口,看大神们如何组织Go语言代码

    分析

    程序信号处理
    • 位置:cmd/containerd/main.go
    ...
    var (
      signals = make(chan os.Signal, 2048)
      ctx     = log.WithModule(gocontext.Background(), "containerd")
    )
    done := handleSignals(ctx, signals, serverC)
    ...
    signal.Notify(signals, handledSignals...)
    
    ...
    
    <-done
    ...
    
    初始化服务
    • 位置:cmd/containerd/main.go
    ...
    server, err := server.New(ctx, config)
    if err != nil {
        return err
    }
    ...
    
    开启debug / metrics / grpc服务
    ...
    if config.Debug.Address != "" {
        l, err := sys.GetLocalListener(config.Debug.Address, config.Debug.UID, config.Debug.GID)
        if err != nil {
            return errors.Wrapf(err, "failed to get listener for debug endpoint")
        }
        serve(log.WithModule(ctx, "debug"), l, server.ServeDebug)
    }
    
    if config.Metrics.Address != "" {
        l, err := net.Listen("tcp", config.Metrics.Address)
        if err != nil {
            return errors.Wrapf(err, "failed to get listener for metrics endpoint")
        }
        serve(log.WithModule(ctx, "metrics"), l, server.ServeMetrics)
    }
    l, err := sys.GetLocalListener(address, config.GRPC.UID, config.GRPC.GID)
    if err != nil {
        return errors.Wrapf(err, "failed to get listener for main endpoint")
    }
    serve(log.WithModule(ctx, "grpc"), l, server.ServeGRPC)
    ...
    
    containerd架构

    初始化服务解析

    载入插件
    • 位置:server/server.go
    plugins, err := loadPlugins(config)
    if err != nil {
      return nil, err
    }
    
    初始化 grpc服务 和 传输服务
    • 位置:server/server.go
    type Server struct {
        rpc    *grpc.Server
        events *exchange.Exchange
    }
    
    grpc服务
    rpc := grpc.NewServer(
        grpc.UnaryInterceptor(interceptor),
        grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor),
    )
    
    
    传输服务
    // Exchange broadcasts events
    type Exchange struct {
        broadcaster *goevents.Broadcaster
    }
    

    整理:

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

    相关文章

      网友评论

          本文标题:Containerd Server学习 Part 2

          本文链接:https://www.haomeiwen.com/subject/jdukzxtx.html