-
Notifications
You must be signed in to change notification settings - Fork 881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow pass global datastore config after boot #908
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,9 @@ type NetworkController interface { | |
|
||
// Stop network controller | ||
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. | ||
|
@@ -129,7 +132,6 @@ type ipamData struct { | |
} | ||
|
||
type driverTable map[string]*driverData | ||
|
||
type ipamTable map[string]*ipamData | ||
type sandboxTable map[string]*sandbox | ||
|
||
|
@@ -153,22 +155,9 @@ type controller struct { | |
|
||
// 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, | ||
cfg: config.ParseConfigOptions(cfgOptions...), | ||
sandboxes: sandboxTable{}, | ||
drivers: driverTable{}, | ||
ipamDrivers: ipamTable{}, | ||
|
@@ -179,8 +168,8 @@ func New(cfgOptions ...config.Option) (NetworkController, error) { | |
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. | ||
// But it cannot fail creating the Controller | ||
log.Errorf("Failed to Initialize Discovery : %v", err) | ||
|
@@ -206,6 +195,83 @@ func New(cfgOptions ...config.Option) (NetworkController, error) { | |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can avoid adding a new flag here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, it is needed to detect config change. |
||
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 || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you replace this with
By doing this, you can remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot refactor that way, the config comes with up to 2 datastores configs |
||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this result in localscoped store being initialized twice ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is not an issue. It simply replaces the local ds client with an exact copy in the |
||
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 { | ||
return c.id | ||
} | ||
|
@@ -726,6 +792,26 @@ func (c *controller) getIpamDriver(name string) (ipamapi.Ipam, error) { | |
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() { | ||
c.closeStores() | ||
c.stopExternalKeyListener() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we protect this function with the buffered channel to make sure only one caller is active at a given time ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done