|
@@ -146,6 +146,7 @@ func (daemon *Daemon) restore() error {
|
|
|
|
|
|
var migrateLegacyLinks bool
|
|
var migrateLegacyLinks bool
|
|
restartContainers := make(map[*container.Container]chan struct{})
|
|
restartContainers := make(map[*container.Container]chan struct{})
|
|
|
|
+ activeSandboxes := make(map[string]interface{})
|
|
for _, c := range containers {
|
|
for _, c := range containers {
|
|
if err := daemon.registerName(c); err != nil {
|
|
if err := daemon.registerName(c); err != nil {
|
|
logrus.Errorf("Failed to register container %s: %s", c.ID, err)
|
|
logrus.Errorf("Failed to register container %s: %s", c.ID, err)
|
|
@@ -178,6 +179,16 @@ func (daemon *Daemon) restore() error {
|
|
logrus.Errorf("Failed to restore with containerd: %q", err)
|
|
logrus.Errorf("Failed to restore with containerd: %q", err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ if !c.HostConfig.NetworkMode.IsContainer() {
|
|
|
|
+ options, err := daemon.buildSandboxOptions(c)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.Warnf("Failed build sandbox option to restore container %s: %v", c.ID, err)
|
|
|
|
+ }
|
|
|
|
+ mapLock.Lock()
|
|
|
|
+ activeSandboxes[c.NetworkSettings.SandboxID] = options
|
|
|
|
+ mapLock.Unlock()
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
// fixme: only if not running
|
|
// fixme: only if not running
|
|
// get list of containers we need to restart
|
|
// get list of containers we need to restart
|
|
@@ -209,6 +220,10 @@ func (daemon *Daemon) restore() error {
|
|
}(c)
|
|
}(c)
|
|
}
|
|
}
|
|
wg.Wait()
|
|
wg.Wait()
|
|
|
|
+ daemon.netController, err = daemon.initNetworkController(daemon.configStore, activeSandboxes)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return fmt.Errorf("Error initializing network controller: %v", err)
|
|
|
|
+ }
|
|
|
|
|
|
// migrate any legacy links from sqlite
|
|
// migrate any legacy links from sqlite
|
|
linkdbFile := filepath.Join(daemon.root, "linkgraph.db")
|
|
linkdbFile := filepath.Join(daemon.root, "linkgraph.db")
|
|
@@ -356,6 +371,15 @@ func (daemon *Daemon) SetClusterProvider(clusterProvider cluster.Provider) {
|
|
daemon.netController.SetClusterProvider(clusterProvider)
|
|
daemon.netController.SetClusterProvider(clusterProvider)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// IsSwarmCompatible verifies if the current daemon
|
|
|
|
+// configuration is compatible with the swarm mode
|
|
|
|
+func (daemon *Daemon) IsSwarmCompatible() error {
|
|
|
|
+ if daemon.configStore == nil {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ return daemon.configStore.isSwarmCompatible()
|
|
|
|
+}
|
|
|
|
+
|
|
// NewDaemon sets up everything for the daemon to be able to service
|
|
// NewDaemon sets up everything for the daemon to be able to service
|
|
// requests from the webserver.
|
|
// requests from the webserver.
|
|
func NewDaemon(config *Config, registryService registry.Service, containerdRemote libcontainerd.Remote) (daemon *Daemon, err error) {
|
|
func NewDaemon(config *Config, registryService registry.Service, containerdRemote libcontainerd.Remote) (daemon *Daemon, err error) {
|
|
@@ -530,11 +554,6 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
- d.netController, err = d.initNetworkController(config)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, fmt.Errorf("Error initializing network controller: %v", err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
sysInfo := sysinfo.New(false)
|
|
sysInfo := sysinfo.New(false)
|
|
// Check if Devices cgroup is mounted, it is hard requirement for container security,
|
|
// Check if Devices cgroup is mounted, it is hard requirement for container security,
|
|
// on Linux.
|
|
// on Linux.
|
|
@@ -912,15 +931,17 @@ func (daemon *Daemon) reloadClusterDiscovery(config *Config) error {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if daemon.clusterProvider != nil {
|
|
|
|
+ if err := config.isSwarmCompatible(); err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// check discovery modifications
|
|
// check discovery modifications
|
|
if !modifiedDiscoverySettings(daemon.configStore, newAdvertise, newClusterStore, config.ClusterOpts) {
|
|
if !modifiedDiscoverySettings(daemon.configStore, newAdvertise, newClusterStore, config.ClusterOpts) {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
- if daemon.clusterProvider != nil {
|
|
|
|
- return fmt.Errorf("--cluster-store and --cluster-advertise daemon configurations are incompatible with swarm mode")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// enable discovery for the first time if it was not previously enabled
|
|
// enable discovery for the first time if it was not previously enabled
|
|
if daemon.discoveryWatcher == nil {
|
|
if daemon.discoveryWatcher == nil {
|
|
discoveryWatcher, err := initDiscovery(newClusterStore, newAdvertise, config.ClusterOpts)
|
|
discoveryWatcher, err := initDiscovery(newClusterStore, newAdvertise, config.ClusterOpts)
|
|
@@ -947,7 +968,7 @@ func (daemon *Daemon) reloadClusterDiscovery(config *Config) error {
|
|
if daemon.netController == nil {
|
|
if daemon.netController == nil {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
- netOptions, err := daemon.networkOptions(daemon.configStore)
|
|
|
|
|
|
+ netOptions, err := daemon.networkOptions(daemon.configStore, nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
logrus.Warnf("Failed to reload configuration with network controller: %v", err)
|
|
logrus.Warnf("Failed to reload configuration with network controller: %v", err)
|
|
return nil
|
|
return nil
|
|
@@ -964,7 +985,7 @@ func isBridgeNetworkDisabled(config *Config) bool {
|
|
return config.bridgeConfig.Iface == disableNetworkBridge
|
|
return config.bridgeConfig.Iface == disableNetworkBridge
|
|
}
|
|
}
|
|
|
|
|
|
-func (daemon *Daemon) networkOptions(dconfig *Config) ([]nwconfig.Option, error) {
|
|
|
|
|
|
+func (daemon *Daemon) networkOptions(dconfig *Config, activeSandboxes map[string]interface{}) ([]nwconfig.Option, error) {
|
|
options := []nwconfig.Option{}
|
|
options := []nwconfig.Option{}
|
|
if dconfig == nil {
|
|
if dconfig == nil {
|
|
return options, nil
|
|
return options, nil
|
|
@@ -999,6 +1020,11 @@ func (daemon *Daemon) networkOptions(dconfig *Config) ([]nwconfig.Option, error)
|
|
|
|
|
|
options = append(options, nwconfig.OptionLabels(dconfig.Labels))
|
|
options = append(options, nwconfig.OptionLabels(dconfig.Labels))
|
|
options = append(options, driverOptions(dconfig)...)
|
|
options = append(options, driverOptions(dconfig)...)
|
|
|
|
+
|
|
|
|
+ if daemon.configStore != nil && daemon.configStore.LiveRestore && len(activeSandboxes) != 0 {
|
|
|
|
+ options = append(options, nwconfig.OptionActiveSandboxes(activeSandboxes))
|
|
|
|
+ }
|
|
|
|
+
|
|
return options, nil
|
|
return options, nil
|
|
}
|
|
}
|
|
|
|
|