New creates and initializes a new containerd server
(ctx context.Context, config *srvconfig.Config)
| 110 | |
| 111 | // New creates and initializes a new containerd server |
| 112 | func 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 |