Browse Source

Merge pull request #43689 from thaJeztah/fix_incorrect_warnings

daemon.NewDaemon(): fix network feature detection on first start
Sebastiaan van Stijn 3 years ago
parent
commit
38633e7971
4 changed files with 17 additions and 12 deletions
  1. 11 6
      daemon/daemon.go
  2. 2 2
      daemon/daemon_unix.go
  3. 2 2
      daemon/daemon_unsupported.go
  4. 2 2
      daemon/daemon_windows.go

+ 11 - 6
daemon/daemon.go

@@ -1005,13 +1005,15 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	sysInfo := d.RawSysInfo()
-	for _, w := range sysInfo.Warnings {
-		logrus.Warn(w)
-	}
 	// 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.
-	if runtime.GOOS == "linux" && !sysInfo.CgroupDevicesEnabled && !userns.RunningInUserNS() {
+	//
+	// Important: we call getSysInfo() directly here, without storing the results,
+	// as networking has not yet been set up, so we only have partial system info
+	// at this point.
+	//
+	// TODO(thaJeztah) add a utility to only collect the CgroupDevicesEnabled information
+	if runtime.GOOS == "linux" && !userns.RunningInUserNS() && !getSysInfo(d).CgroupDevicesEnabled {
 		return nil, errors.New("Devices cgroup isn't mounted")
 		return nil, errors.New("Devices cgroup isn't mounted")
 	}
 	}
 
 
@@ -1096,6 +1098,9 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
 	close(d.startupDone)
 	close(d.startupDone)
 
 
 	info := d.SystemInfo()
 	info := d.SystemInfo()
+	for _, w := range info.Warnings {
+		logrus.Warn(w)
+	}
 
 
 	engineInfo.WithValues(
 	engineInfo.WithValues(
 		dockerversion.Version,
 		dockerversion.Version,
@@ -1487,7 +1492,7 @@ func (daemon *Daemon) RawSysInfo() *sysinfo.SysInfo {
 		// We check if sysInfo is not set here, to allow some test to
 		// We check if sysInfo is not set here, to allow some test to
 		// override the actual sysInfo.
 		// override the actual sysInfo.
 		if daemon.sysInfo == nil {
 		if daemon.sysInfo == nil {
-			daemon.loadSysInfo()
+			daemon.sysInfo = getSysInfo(daemon)
 		}
 		}
 	})
 	})
 
 

+ 2 - 2
daemon/daemon_unix.go

@@ -1726,14 +1726,14 @@ func (daemon *Daemon) setupSeccompProfile() error {
 	return nil
 	return nil
 }
 }
 
 
-func (daemon *Daemon) loadSysInfo() {
+func getSysInfo(daemon *Daemon) *sysinfo.SysInfo {
 	var siOpts []sysinfo.Opt
 	var siOpts []sysinfo.Opt
 	if daemon.getCgroupDriver() == cgroupSystemdDriver {
 	if daemon.getCgroupDriver() == cgroupSystemdDriver {
 		if euid := os.Getenv("ROOTLESSKIT_PARENT_EUID"); euid != "" {
 		if euid := os.Getenv("ROOTLESSKIT_PARENT_EUID"); euid != "" {
 			siOpts = append(siOpts, sysinfo.WithCgroup2GroupPath("/user.slice/user-"+euid+".slice"))
 			siOpts = append(siOpts, sysinfo.WithCgroup2GroupPath("/user.slice/user-"+euid+".slice"))
 		}
 		}
 	}
 	}
-	daemon.sysInfo = sysinfo.New(siOpts...)
+	return sysinfo.New(siOpts...)
 }
 }
 
 
 func (daemon *Daemon) initLibcontainerd(ctx context.Context) error {
 func (daemon *Daemon) initLibcontainerd(ctx context.Context) error {

+ 2 - 2
daemon/daemon_unsupported.go

@@ -13,6 +13,6 @@ const platformSupported = false
 func setupResolvConf(config *config.Config) {
 func setupResolvConf(config *config.Config) {
 }
 }
 
 
-func (daemon *Daemon) loadSysInfo() {
-	daemon.sysInfo = sysinfo.New()
+func getSysInfo(daemon *Daemon) *sysinfo.SysInfo {
+	return sysinfo.New()
 }
 }

+ 2 - 2
daemon/daemon_windows.go

@@ -598,8 +598,8 @@ func (daemon *Daemon) loadRuntimes() error {
 
 
 func setupResolvConf(config *config.Config) {}
 func setupResolvConf(config *config.Config) {}
 
 
-func (daemon *Daemon) loadSysInfo() {
-	daemon.sysInfo = sysinfo.New()
+func getSysInfo(daemon *Daemon) *sysinfo.SysInfo {
+	return sysinfo.New()
 }
 }
 
 
 func (daemon *Daemon) initLibcontainerd(ctx context.Context) error {
 func (daemon *Daemon) initLibcontainerd(ctx context.Context) error {