MCPcopy Index your code
hub / github.com/containerd/containerd / New

Function New

cmd/containerd/server/server.go:112–221  ·  view source on GitHub ↗

New creates and initializes a new containerd server

(ctx context.Context, config *srvconfig.Config)

Source from the content-addressed store, hash-verified

110
111// New creates and initializes a new containerd server
112func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
113 if err := apply(ctx, config); err != nil {
114 return nil, err
115 }
116 for key, sec := range config.Timeouts {
117 d, err := time.ParseDuration(sec)
118 if err != nil {
119 return nil, fmt.Errorf("unable to parse %s into a time duration", sec)
120 }
121 timeout.Set(key, d)
122 }
123 loaded, err := LoadPlugins(ctx, config)
124 if err != nil {
125 return nil, err
126 }
127 for id, p := range config.StreamProcessors {
128 diff.RegisterProcessor(diff.BinaryHandler(id, p.Returns, p.Accepts, p.Path, p.Args, p.Env))
129 }
130 var (
131 s = &Server{
132 config: config,
133 }
134 initialized = plugin.NewPluginSet()
135 required = make(map[string]struct{})
136 grpcAddress = readString(config.Plugins, "io.containerd.server.v1.grpc", "address")
137 ttrpcAddress = readString(config.Plugins, "io.containerd.server.v1.ttrpc", "address")
138 )
139 if grpcAddress == "" {
140 grpcAddress = defaults.DefaultAddress
141 }
142 if ttrpcAddress == "" {
143 ttrpcAddress = defaults.DefaultAddress + ".ttrpc"
144 }
145 for _, r := range config.RequiredPlugins {
146 required[r] = struct{}{}
147 }
148
149 for _, p := range loaded {
150 id := p.URI()
151 log.G(ctx).WithFields(log.Fields{"id": id, "type": p.Type}).Info("loading plugin")
152 var mustSucceed atomic.Int32
153
154 initContext := plugin.NewContext(
155 ctx,
156 initialized,
157 map[string]string{
158 plugins.PropertyRootDir: filepath.Join(config.Root, id),
159 plugins.PropertyStateDir: filepath.Join(config.State, id),
160 plugins.PropertyGRPCAddress: grpcAddress,
161 plugins.PropertyTTRPCAddress: ttrpcAddress,
162 },
163 )
164 initContext.RegisterReadiness = func() func() {
165 mustSucceed.Store(1)
166 return s.RegisterReadiness()
167 }
168
169 // load the plugin specific configuration if it is provided

Callers 2

startDaemonFunction · 0.92
TestMigrationFunction · 0.70

Calls 14

SetFunction · 0.92
RegisterProcessorFunction · 0.92
BinaryHandlerFunction · 0.92
LoadPluginsFunction · 0.85
readStringFunction · 0.85
recordConfigDeprecationsFunction · 0.85
RegisterReadinessMethod · 0.80
DecodeMethod · 0.80
InitMethod · 0.80
LoadMethod · 0.80
applyFunction · 0.70
InfoMethod · 0.65

Tested by 1

TestMigrationFunction · 0.56