|
@@ -106,6 +106,9 @@ type NetworkController interface {
|
|
|
|
|
|
// Stop network controller
|
|
// Stop network controller
|
|
Stop()
|
|
Stop()
|
|
|
|
+
|
|
|
|
+ // ReloadCondfiguration updates the controller configuration
|
|
|
|
+ ReloadConfiguration(cfgOptions ...config.Option) error
|
|
}
|
|
}
|
|
|
|
|
|
// NetworkWalker is a client provided function which will be used to walk the Networks.
|
|
// NetworkWalker is a client provided function which will be used to walk the Networks.
|
|
@@ -129,7 +132,6 @@ type ipamData struct {
|
|
}
|
|
}
|
|
|
|
|
|
type driverTable map[string]*driverData
|
|
type driverTable map[string]*driverData
|
|
-
|
|
|
|
type ipamTable map[string]*ipamData
|
|
type ipamTable map[string]*ipamData
|
|
type sandboxTable map[string]*sandbox
|
|
type sandboxTable map[string]*sandbox
|
|
|
|
|
|
@@ -153,22 +155,9 @@ type controller struct {
|
|
|
|
|
|
// New creates a new instance of network controller.
|
|
// New creates a new instance of network controller.
|
|
func New(cfgOptions ...config.Option) (NetworkController, error) {
|
|
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{
|
|
c := &controller{
|
|
id: stringid.GenerateRandomID(),
|
|
id: stringid.GenerateRandomID(),
|
|
- cfg: cfg,
|
|
|
|
|
|
+ cfg: config.ParseConfigOptions(cfgOptions...),
|
|
sandboxes: sandboxTable{},
|
|
sandboxes: sandboxTable{},
|
|
drivers: driverTable{},
|
|
drivers: driverTable{},
|
|
ipamDrivers: ipamTable{},
|
|
ipamDrivers: ipamTable{},
|
|
@@ -179,8 +168,8 @@ func New(cfgOptions ...config.Option) (NetworkController, error) {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
- if cfg != nil && cfg.Cluster.Watcher != nil {
|
|
|
|
- if err := c.initDiscovery(cfg.Cluster.Watcher); err != nil {
|
|
|
|
|
|
+ if c.cfg != nil && c.cfg.Cluster.Watcher != nil {
|
|
|
|
+ if err := c.initDiscovery(c.cfg.Cluster.Watcher); err != nil {
|
|
// Failing to initalize discovery is a bad situation to be in.
|
|
// Failing to initalize discovery is a bad situation to be in.
|
|
// But it cannot fail creating the Controller
|
|
// But it cannot fail creating the Controller
|
|
log.Errorf("Failed to Initialize Discovery : %v", err)
|
|
log.Errorf("Failed to Initialize Discovery : %v", err)
|
|
@@ -206,6 +195,83 @@ func New(cfgOptions ...config.Option) (NetworkController, error) {
|
|
return c, nil
|
|
return c, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+var procReloadConfig = make(chan (bool), 1)
|
|
|
|
+
|
|
|
|
+func (c *controller) ReloadConfiguration(cfgOptions ...config.Option) error {
|
|
|
|
+ procReloadConfig <- true
|
|
|
|
+ defer func() { <-procReloadConfig }()
|
|
|
|
+
|
|
|
|
+ // For now we accept the configuration reload only as a mean to provide a global store config after boot.
|
|
|
|
+ // Refuse the configuration if it alters an existing datastore client configuration.
|
|
|
|
+ update := false
|
|
|
|
+ cfg := config.ParseConfigOptions(cfgOptions...)
|
|
|
|
+ for s := range c.cfg.Scopes {
|
|
|
|
+ if _, ok := cfg.Scopes[s]; !ok {
|
|
|
|
+ return types.ForbiddenErrorf("cannot accept new configuration because it removes an existing datastore client")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for s, nSCfg := range cfg.Scopes {
|
|
|
|
+ if eSCfg, ok := c.cfg.Scopes[s]; ok {
|
|
|
|
+ if eSCfg.Client.Provider != nSCfg.Client.Provider ||
|
|
|
|
+ eSCfg.Client.Address != nSCfg.Client.Address {
|
|
|
|
+ return types.ForbiddenErrorf("cannot accept new configuration because it modifies an existing datastore client")
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ update = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if !update {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ c.Lock()
|
|
|
|
+ c.cfg = cfg
|
|
|
|
+ c.Unlock()
|
|
|
|
+
|
|
|
|
+ if err := c.initStores(); err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if c.discovery == nil && c.cfg.Cluster.Watcher != nil {
|
|
|
|
+ if err := c.initDiscovery(c.cfg.Cluster.Watcher); err != nil {
|
|
|
|
+ log.Errorf("Failed to Initialize Discovery after configuration update: %v", err)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var dsConfig *discoverapi.DatastoreConfigData
|
|
|
|
+ for scope, sCfg := range cfg.Scopes {
|
|
|
|
+ if scope == datastore.LocalScope || !sCfg.IsValid() {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ dsConfig = &discoverapi.DatastoreConfigData{
|
|
|
|
+ Scope: scope,
|
|
|
|
+ Provider: sCfg.Client.Provider,
|
|
|
|
+ Address: sCfg.Client.Address,
|
|
|
|
+ Config: sCfg.Client.Config,
|
|
|
|
+ }
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ if dsConfig == nil {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for nm, id := range c.getIpamDrivers() {
|
|
|
|
+ err := id.driver.DiscoverNew(discoverapi.DatastoreConfig, *dsConfig)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Errorf("Failed to set datastore in driver %s: %v", nm, err)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for nm, id := range c.getNetDrivers() {
|
|
|
|
+ err := id.driver.DiscoverNew(discoverapi.DatastoreConfig, *dsConfig)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Errorf("Failed to set datastore in driver %s: %v", nm, err)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
func (c *controller) ID() string {
|
|
func (c *controller) ID() string {
|
|
return c.id
|
|
return c.id
|
|
}
|
|
}
|
|
@@ -726,6 +792,26 @@ func (c *controller) getIpamDriver(name string) (ipamapi.Ipam, error) {
|
|
return id.driver, nil
|
|
return id.driver, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (c *controller) getIpamDrivers() ipamTable {
|
|
|
|
+ c.Lock()
|
|
|
|
+ defer c.Unlock()
|
|
|
|
+ table := ipamTable{}
|
|
|
|
+ for i, d := range c.ipamDrivers {
|
|
|
|
+ table[i] = d
|
|
|
|
+ }
|
|
|
|
+ return table
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (c *controller) getNetDrivers() driverTable {
|
|
|
|
+ c.Lock()
|
|
|
|
+ defer c.Unlock()
|
|
|
|
+ table := driverTable{}
|
|
|
|
+ for i, d := range c.drivers {
|
|
|
|
+ table[i] = d
|
|
|
|
+ }
|
|
|
|
+ return table
|
|
|
|
+}
|
|
|
|
+
|
|
func (c *controller) Stop() {
|
|
func (c *controller) Stop() {
|
|
c.closeStores()
|
|
c.closeStores()
|
|
c.stopExternalKeyListener()
|
|
c.stopExternalKeyListener()
|