예제 #1
0
// New creates a new instance of network controller.
func New(cfgOptions ...config.Option) (NetworkController, error) {
	var cfg *config.Config
	if len(cfgOptions) > 0 {
		cfg = &config.Config{}
		cfg.ProcessOptions(cfgOptions...)
	}
	c := &controller{
		cfg:       cfg,
		networks:  networkTable{},
		sandboxes: sandboxTable{},
		drivers:   driverTable{}}
	if err := initDrivers(c); err != nil {
		return nil, err
	}

	if cfg != nil {
		if err := c.initDataStore(); err != nil {
			// Failing to initalize datastore is a bad situation to be in.
			// But it cannot fail creating the Controller
			log.Debugf("Failed to Initialize Datastore due to %v. Operating in non-clustered mode", err)
		}
		if err := c.initDiscovery(); err != nil {
			// Failing to initalize discovery is a bad situation to be in.
			// But it cannot fail creating the Controller
			log.Debugf("Failed to Initialize Discovery : %v", err)
		}
	}

	return c, nil
}
예제 #2
0
// New creates a new instance of network controller.
func New(cfgOptions ...config.Option) (NetworkController, error) {
	var cfg *config.Config
	if len(cfgOptions) > 0 {
		cfg = &config.Config{
			Daemon: config.DaemonCfg{
				DriverCfg: make(map[string]interface{}),
			},
		}
		cfg.ProcessOptions(cfgOptions...)
	}
	c := &controller{
		id:          stringid.GenerateRandomID(),
		cfg:         cfg,
		networks:    networkTable{},
		sandboxes:   sandboxTable{},
		drivers:     driverTable{},
		ipamDrivers: ipamTable{}}
	if err := initDrivers(c); err != nil {
		return nil, err
	}

	if cfg != nil {
		if err := c.initGlobalStore(); err != nil {
			// Failing to initalize datastore is a bad situation to be in.
			// But it cannot fail creating the Controller
			log.Debugf("Failed to Initialize Datastore due to %v. Operating in non-clustered mode", err)
		}
		if err := c.initLocalStore(); err != nil {
			log.Debugf("Failed to Initialize LocalDatastore due to %v.", err)
		}
	}

	if err := initIpams(c, c.localStore, c.globalStore); err != nil {
		return nil, err
	}

	if cfg != nil {
		if err := c.restoreFromGlobalStore(); err != nil {
			log.Debugf("Failed to restore from global Datastore due to %v", err)
		}
		if err := c.initDiscovery(cfg.Cluster.Watcher); err != nil {
			// Failing to initalize discovery is a bad situation to be in.
			// But it cannot fail creating the Controller
			log.Debugf("Failed to Initialize Discovery : %v", err)
		}
		if err := c.restoreFromLocalStore(); err != nil {
			log.Debugf("Failed to restore from local Datastore due to %v", err)
		}
	}

	if err := c.startExternalKeyListener(); err != nil {
		return nil, err
	}

	return c, nil
}
예제 #3
0
// New creates a new instance of network controller.
func New(cfgOptions ...config.Option) (NetworkController, error) {
	var cfg *config.Config
	cfg = &config.Config{
		Daemon: config.DaemonCfg{
			DriverCfg: make(map[string]interface{}),
		},
		Scopes: make(map[string]*datastore.ScopeCfg),
	}

	if len(cfgOptions) > 0 {
		cfg.ProcessOptions(cfgOptions...)
	}
	cfg.LoadDefaultScopes(cfg.Daemon.DataDir)

	c := &controller{
		id:          stringid.GenerateRandomID(),
		cfg:         cfg,
		sandboxes:   sandboxTable{},
		drivers:     driverTable{},
		ipamDrivers: ipamTable{},
		svcDb:       make(map[string]svcMap),
	}

	if err := c.initStores(); err != nil {
		return nil, err
	}

	if cfg != nil && cfg.Cluster.Watcher != nil {
		if err := c.initDiscovery(cfg.Cluster.Watcher); err != nil {
			// Failing to initalize discovery is a bad situation to be in.
			// But it cannot fail creating the Controller
			log.Errorf("Failed to Initialize Discovery : %v", err)
		}
	}

	if err := initDrivers(c); err != nil {
		return nil, err
	}

	if err := initIpams(c, c.getStore(datastore.LocalScope),
		c.getStore(datastore.GlobalScope)); err != nil {
		return nil, err
	}

	c.sandboxCleanup()
	c.cleanupLocalEndpoints()

	if err := c.startExternalKeyListener(); err != nil {
		return nil, err
	}

	return c, nil
}