1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| func NewCRIService(config criconfig.Config, client *containerd.Client, nri *nri.API) (CRIService, error) { var err error labels := label.NewStore() c := &criService{ config: config, client: client, os: osinterface.RealOS{}, sandboxStore: sandboxstore.NewStore(labels), containerStore: containerstore.NewStore(labels), imageStore: imagestore.NewStore(client), snapshotStore: snapshotstore.NewStore(), sandboxNameIndex: registrar.NewRegistrar(), containerNameIndex: registrar.NewRegistrar(), initialized: atomic.NewBool(false), netPlugin: make(map[string]cni.CNI), unpackDuplicationSuppressor: kmutex.New(), }
c.containerEventsChan = make(chan runtime.ContainerEventResponse, 1000)
if client.SnapshotService(c.config.ContainerdConfig.Snapshotter) == nil { return nil, fmt.Errorf("failed to find snapshotter %q", c.config.ContainerdConfig.Snapshotter) }
c.imageFSPath = imageFSPath(config.ContainerdRootDir, config.ContainerdConfig.Snapshotter) logrus.Infof("Get image filesystem path %q", c.imageFSPath)
if err := c.initPlatform(); err != nil { return nil, fmt.Errorf("initialize platform: %w", err) }
c.streamServer, err = newStreamServer(c, config.StreamServerAddress, config.StreamServerPort, config.StreamIdleTimeout) if err != nil { return nil, fmt.Errorf("failed to create stream server: %w", err) }
c.eventMonitor = newEventMonitor(c)
c.cniNetConfMonitor = make(map[string]*cniNetConfSyncer) for name, i := range c.netPlugin { path := c.config.NetworkPluginConfDir if name != defaultNetworkPlugin { if rc, ok := c.config.Runtimes[name]; ok { path = rc.NetworkPluginConfDir } } if path != "" { m, err := newCNINetConfSyncer(path, i, c.cniLoadOptions()) if err != nil { return nil, fmt.Errorf("failed to create cni conf monitor for %s: %w", name, err) } c.cniNetConfMonitor[name] = m } }
c.baseOCISpecs, err = loadBaseOCISpecs(&config) if err != nil { return nil, err }
c.sandboxControllers[criconfig.ModePodSandbox] = podsandbox.New(config, client, c.sandboxStore, c.os, c, c.baseOCISpecs) c.sandboxControllers[criconfig.ModeShim] = client.SandboxController()
c.nri = nri
return c, nil }
|