func (cli *DaemonCli) getPlatformRemoteOptions() []libcontainerd.RemoteOption { opts := []libcontainerd.RemoteOption{ libcontainerd.WithDebugLog(cli.Config.Debug), } if cli.Config.ContainerdAddr != "" { opts = append(opts, libcontainerd.WithRemoteAddr(cli.Config.ContainerdAddr)) } else { opts = append(opts, libcontainerd.WithStartDaemon(true)) } if daemon.UsingSystemd(cli.Config) { args := []string{"--systemd-cgroup=true"} opts = append(opts, libcontainerd.WithRuntimeArgs(args)) } if cli.Config.LiveRestore { opts = append(opts, libcontainerd.WithLiveRestore(true)) } opts = append(opts, libcontainerd.WithRuntimePath(daemon.DefaultRuntimeBinary)) return opts }
// Reload reads configuration changes and modifies the // daemon according to those changes. // These are the settings that Reload changes: // - Daemon labels. // - Daemon debug log level. // - Daemon max concurrent downloads // - Daemon max concurrent uploads // - Cluster discovery (reconfigure and restart). // - Daemon live restore func (daemon *Daemon) Reload(config *Config) error { var err error // used to hold reloaded changes attributes := map[string]string{} // We need defer here to ensure the lock is released as // daemon.SystemInfo() will try to get it too defer func() { if err == nil { daemon.LogDaemonEventWithAttributes("reload", attributes) } }() daemon.configStore.reloadLock.Lock() defer daemon.configStore.reloadLock.Unlock() daemon.platformReload(config, &attributes) if err = daemon.reloadClusterDiscovery(config); err != nil { return err } if config.IsValueSet("labels") { daemon.configStore.Labels = config.Labels } if config.IsValueSet("debug") { daemon.configStore.Debug = config.Debug } if config.IsValueSet("live-restore") { daemon.configStore.LiveRestoreEnabled = config.LiveRestoreEnabled if err := daemon.containerdRemote.UpdateOptions(libcontainerd.WithLiveRestore(config.LiveRestoreEnabled)); err != nil { return err } } // If no value is set for max-concurrent-downloads we assume it is the default value // We always "reset" as the cost is lightweight and easy to maintain. if config.IsValueSet("max-concurrent-downloads") && config.MaxConcurrentDownloads != nil { *daemon.configStore.MaxConcurrentDownloads = *config.MaxConcurrentDownloads } else { maxConcurrentDownloads := defaultMaxConcurrentDownloads daemon.configStore.MaxConcurrentDownloads = &maxConcurrentDownloads } logrus.Debugf("Reset Max Concurrent Downloads: %d", *daemon.configStore.MaxConcurrentDownloads) if daemon.downloadManager != nil { daemon.downloadManager.SetConcurrency(*daemon.configStore.MaxConcurrentDownloads) } // If no value is set for max-concurrent-upload we assume it is the default value // We always "reset" as the cost is lightweight and easy to maintain. if config.IsValueSet("max-concurrent-uploads") && config.MaxConcurrentUploads != nil { *daemon.configStore.MaxConcurrentUploads = *config.MaxConcurrentUploads } else { maxConcurrentUploads := defaultMaxConcurrentUploads daemon.configStore.MaxConcurrentUploads = &maxConcurrentUploads } logrus.Debugf("Reset Max Concurrent Uploads: %d", *daemon.configStore.MaxConcurrentUploads) if daemon.uploadManager != nil { daemon.uploadManager.SetConcurrency(*daemon.configStore.MaxConcurrentUploads) } // We emit daemon reload event here with updatable configurations attributes["debug"] = fmt.Sprintf("%t", daemon.configStore.Debug) attributes["live-restore"] = fmt.Sprintf("%t", daemon.configStore.LiveRestoreEnabled) attributes["cluster-store"] = daemon.configStore.ClusterStore if daemon.configStore.ClusterOpts != nil { opts, _ := json.Marshal(daemon.configStore.ClusterOpts) attributes["cluster-store-opts"] = string(opts) } else { attributes["cluster-store-opts"] = "{}" } attributes["cluster-advertise"] = daemon.configStore.ClusterAdvertise if daemon.configStore.Labels != nil { labels, _ := json.Marshal(daemon.configStore.Labels) attributes["labels"] = string(labels) } else { attributes["labels"] = "[]" } attributes["max-concurrent-downloads"] = fmt.Sprintf("%d", *daemon.configStore.MaxConcurrentDownloads) attributes["max-concurrent-uploads"] = fmt.Sprintf("%d", *daemon.configStore.MaxConcurrentUploads) return nil }
// Reload reads configuration changes and modifies the // daemon according to those changes. // These are the settings that Reload changes: // - Daemon labels. // - Daemon debug log level. // - Daemon insecure registries. // - Daemon max concurrent downloads // - Daemon max concurrent uploads // - Cluster discovery (reconfigure and restart). // - Daemon live restore // - Daemon shutdown timeout (in seconds). func (daemon *Daemon) Reload(config *Config) (err error) { daemon.configStore.reloadLock.Lock() attributes := daemon.platformReload(config) defer func() { // we're unlocking here, because // LogDaemonEventWithAttributes() -> SystemInfo() -> GetAllRuntimes() // holds that lock too. daemon.configStore.reloadLock.Unlock() if err == nil { daemon.LogDaemonEventWithAttributes("reload", attributes) } }() if err := daemon.reloadClusterDiscovery(config); err != nil { return err } if config.IsValueSet("labels") { daemon.configStore.Labels = config.Labels } if config.IsValueSet("debug") { daemon.configStore.Debug = config.Debug } if config.IsValueSet("insecure-registries") { daemon.configStore.InsecureRegistries = config.InsecureRegistries if err := daemon.RegistryService.LoadInsecureRegistries(config.InsecureRegistries); err != nil { return err } } if config.IsValueSet("live-restore") { daemon.configStore.LiveRestoreEnabled = config.LiveRestoreEnabled if err := daemon.containerdRemote.UpdateOptions(libcontainerd.WithLiveRestore(config.LiveRestoreEnabled)); err != nil { return err } } // If no value is set for max-concurrent-downloads we assume it is the default value // We always "reset" as the cost is lightweight and easy to maintain. if config.IsValueSet("max-concurrent-downloads") && config.MaxConcurrentDownloads != nil { *daemon.configStore.MaxConcurrentDownloads = *config.MaxConcurrentDownloads } else { maxConcurrentDownloads := defaultMaxConcurrentDownloads daemon.configStore.MaxConcurrentDownloads = &maxConcurrentDownloads } logrus.Debugf("Reset Max Concurrent Downloads: %d", *daemon.configStore.MaxConcurrentDownloads) if daemon.downloadManager != nil { daemon.downloadManager.SetConcurrency(*daemon.configStore.MaxConcurrentDownloads) } // If no value is set for max-concurrent-upload we assume it is the default value // We always "reset" as the cost is lightweight and easy to maintain. if config.IsValueSet("max-concurrent-uploads") && config.MaxConcurrentUploads != nil { *daemon.configStore.MaxConcurrentUploads = *config.MaxConcurrentUploads } else { maxConcurrentUploads := defaultMaxConcurrentUploads daemon.configStore.MaxConcurrentUploads = &maxConcurrentUploads } logrus.Debugf("Reset Max Concurrent Uploads: %d", *daemon.configStore.MaxConcurrentUploads) if daemon.uploadManager != nil { daemon.uploadManager.SetConcurrency(*daemon.configStore.MaxConcurrentUploads) } if config.IsValueSet("shutdown-timeout") { daemon.configStore.ShutdownTimeout = config.ShutdownTimeout logrus.Debugf("Reset Shutdown Timeout: %d", daemon.configStore.ShutdownTimeout) } // We emit daemon reload event here with updatable configurations attributes["debug"] = fmt.Sprintf("%t", daemon.configStore.Debug) attributes["live-restore"] = fmt.Sprintf("%t", daemon.configStore.LiveRestoreEnabled) if daemon.configStore.InsecureRegistries != nil { insecureRegistries, err := json.Marshal(daemon.configStore.InsecureRegistries) if err != nil { return err } attributes["insecure-registries"] = string(insecureRegistries) } else { attributes["insecure-registries"] = "[]" } attributes["cluster-store"] = daemon.configStore.ClusterStore if daemon.configStore.ClusterOpts != nil { opts, err := json.Marshal(daemon.configStore.ClusterOpts) if err != nil { return err } attributes["cluster-store-opts"] = string(opts) } else { attributes["cluster-store-opts"] = "{}" } attributes["cluster-advertise"] = daemon.configStore.ClusterAdvertise if daemon.configStore.Labels != nil { labels, err := json.Marshal(daemon.configStore.Labels) if err != nil { return err } attributes["labels"] = string(labels) } else { attributes["labels"] = "[]" } attributes["max-concurrent-downloads"] = fmt.Sprintf("%d", *daemon.configStore.MaxConcurrentDownloads) attributes["max-concurrent-uploads"] = fmt.Sprintf("%d", *daemon.configStore.MaxConcurrentUploads) attributes["shutdown-timeout"] = fmt.Sprintf("%d", daemon.configStore.ShutdownTimeout) return nil }