From 9b795c3e502906bb042e207db6b7583c9bfa34e5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 14 Jul 2021 16:45:02 +0200 Subject: [PATCH] pkg/sysinfo.New(), daemon.RawSysInfo(): remove "quiet" argument The "quiet" argument was only used in a single place (at daemon startup), and every other use had to pass "false" to prevent this function from logging warnings. Now that SysInfo contains the warnings that occurred when collecting the system information, we can make leave it up to the caller to use those warnings (and log them if wanted). Signed-off-by: Sebastiaan van Stijn --- cmd/dockerd/daemon.go | 4 ++-- daemon/daemon.go | 5 ++++- daemon/daemon_unix.go | 6 +++--- daemon/daemon_unsupported.go | 4 ++-- daemon/daemon_windows.go | 4 ++-- daemon/info.go | 2 +- daemon/oci_linux.go | 2 +- integration-cli/docker_cli_run_unix_test.go | 4 ++-- integration-cli/requirements_unix_test.go | 2 +- pkg/sysinfo/cgroup2_linux.go | 7 +------ pkg/sysinfo/sysinfo_linux.go | 16 +++++----------- pkg/sysinfo/sysinfo_linux_test.go | 14 +++++--------- pkg/sysinfo/sysinfo_other.go | 2 +- runconfig/config.go | 2 +- runconfig/config_test.go | 4 ++-- 15 files changed, 33 insertions(+), 45 deletions(-) diff --git a/cmd/dockerd/daemon.go b/cmd/dockerd/daemon.go index 1841253a06..842c948f8a 100644 --- a/cmd/dockerd/daemon.go +++ b/cmd/dockerd/daemon.go @@ -478,14 +478,14 @@ func warnOnDeprecatedConfigOptions(config *config.Config) { func initRouter(opts routerOptions) { decoder := runconfig.ContainerDecoder{ GetSysInfo: func() *sysinfo.SysInfo { - return opts.daemon.RawSysInfo(true) + return opts.daemon.RawSysInfo() }, } routers := []router.Router{ // we need to add the checkpoint router before the container router or the DELETE gets masked checkpointrouter.NewRouter(opts.daemon, decoder), - container.NewRouter(opts.daemon, decoder, opts.daemon.RawSysInfo(true).CgroupUnified), + container.NewRouter(opts.daemon, decoder, opts.daemon.RawSysInfo().CgroupUnified), image.NewRouter(opts.daemon.ImageService()), systemrouter.NewRouter(opts.daemon, opts.cluster, opts.buildkit, opts.features), volume.NewRouter(opts.daemon.VolumesService()), diff --git a/daemon/daemon.go b/daemon/daemon.go index e6c0425e02..ced869a380 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -1050,7 +1050,10 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S return nil, err } - sysInfo := d.RawSysInfo(false) + sysInfo := d.RawSysInfo() + for _, w := range sysInfo.Warnings { + logrus.Warn(w) + } // Check if Devices cgroup is mounted, it is hard requirement for container security, // on Linux. if runtime.GOOS == "linux" && !sysInfo.CgroupDevicesEnabled && !userns.RunningInUserNS() { diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index 4818d06f60..f50497d33f 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -666,7 +666,7 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes. if hostConfig == nil { return nil, nil } - sysInfo := daemon.RawSysInfo(true) + sysInfo := daemon.RawSysInfo() w, err := verifyPlatformContainerResources(&hostConfig.Resources, sysInfo, update) @@ -1718,14 +1718,14 @@ func (daemon *Daemon) setupSeccompProfile() error { } // RawSysInfo returns *sysinfo.SysInfo . -func (daemon *Daemon) RawSysInfo(quiet bool) *sysinfo.SysInfo { +func (daemon *Daemon) RawSysInfo() *sysinfo.SysInfo { var siOpts []sysinfo.Opt if daemon.getCgroupDriver() == cgroupSystemdDriver { if euid := os.Getenv("ROOTLESSKIT_PARENT_EUID"); euid != "" { siOpts = append(siOpts, sysinfo.WithCgroup2GroupPath("/user.slice/user-"+euid+".slice")) } } - return sysinfo.New(quiet, siOpts...) + return sysinfo.New(siOpts...) } func recursiveUnmount(target string) error { diff --git a/daemon/daemon_unsupported.go b/daemon/daemon_unsupported.go index 4c2476edcf..e8bebca3e4 100644 --- a/daemon/daemon_unsupported.go +++ b/daemon/daemon_unsupported.go @@ -13,6 +13,6 @@ func setupResolvConf(config *config.Config) { } // RawSysInfo returns *sysinfo.SysInfo . -func (daemon *Daemon) RawSysInfo(quiet bool) *sysinfo.SysInfo { - return sysinfo.New(quiet) +func (daemon *Daemon) RawSysInfo() *sysinfo.SysInfo { + return sysinfo.New() } diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index 76e3701f8a..a87f700bb0 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -652,6 +652,6 @@ func setupResolvConf(config *config.Config) { } // RawSysInfo returns *sysinfo.SysInfo . -func (daemon *Daemon) RawSysInfo(quiet bool) *sysinfo.SysInfo { - return sysinfo.New(quiet) +func (daemon *Daemon) RawSysInfo() *sysinfo.SysInfo { + return sysinfo.New() } diff --git a/daemon/info.go b/daemon/info.go index 15b78ebe1c..7c9f7e6ab8 100644 --- a/daemon/info.go +++ b/daemon/info.go @@ -30,7 +30,7 @@ import ( func (daemon *Daemon) SystemInfo() *types.Info { defer metrics.StartTimer(hostInfoFunctions.WithValues("system_info"))() - sysInfo := daemon.RawSysInfo(true) + sysInfo := daemon.RawSysInfo() cRunning, cPaused, cStopped := stateCtr.get() v := &types.Info{ diff --git a/daemon/oci_linux.go b/daemon/oci_linux.go index 6358450d37..a5720537b9 100644 --- a/daemon/oci_linux.go +++ b/daemon/oci_linux.go @@ -824,7 +824,7 @@ func WithCgroups(daemon *Daemon, c *container.Container) coci.SpecOpts { } // FIXME this is very expensive way to check if cpu rt is supported - sysInfo := daemon.RawSysInfo(true) + sysInfo := daemon.RawSysInfo() if !sysInfo.CPURealtime { return errors.New("daemon-scoped cpu-rt-period and cpu-rt-runtime are not supported by the kernel") } diff --git a/integration-cli/docker_cli_run_unix_test.go b/integration-cli/docker_cli_run_unix_test.go index e0003396d9..6cb05ea74e 100644 --- a/integration-cli/docker_cli_run_unix_test.go +++ b/integration-cli/docker_cli_run_unix_test.go @@ -699,7 +699,7 @@ func (s *DockerSuite) TestRunSwapLessThanMemoryLimit(c *testing.T) { func (s *DockerSuite) TestRunInvalidCpusetCpusFlagValue(c *testing.T) { testRequires(c, cgroupCpuset, testEnv.IsLocalDaemon) - sysInfo := sysinfo.New(true) + sysInfo := sysinfo.New() cpus, err := parsers.ParseUintList(sysInfo.Cpus) assert.NilError(c, err) var invalid int @@ -718,7 +718,7 @@ func (s *DockerSuite) TestRunInvalidCpusetCpusFlagValue(c *testing.T) { func (s *DockerSuite) TestRunInvalidCpusetMemsFlagValue(c *testing.T) { testRequires(c, cgroupCpuset) - sysInfo := sysinfo.New(true) + sysInfo := sysinfo.New() mems, err := parsers.ParseUintList(sysInfo.Mems) assert.NilError(c, err) var invalid int diff --git a/integration-cli/requirements_unix_test.go b/integration-cli/requirements_unix_test.go index 8c75b26424..7086966a66 100644 --- a/integration-cli/requirements_unix_test.go +++ b/integration-cli/requirements_unix_test.go @@ -84,6 +84,6 @@ func overlayFSSupported() bool { func init() { if testEnv.IsLocalDaemon() { - SysInfo = sysinfo.New(true) + SysInfo = sysinfo.New() } } diff --git a/pkg/sysinfo/cgroup2_linux.go b/pkg/sysinfo/cgroup2_linux.go index f4fdb10be8..e62769a6ee 100644 --- a/pkg/sysinfo/cgroup2_linux.go +++ b/pkg/sysinfo/cgroup2_linux.go @@ -12,7 +12,7 @@ import ( "github.com/sirupsen/logrus" ) -func newV2(quiet bool, options ...Opt) *SysInfo { +func newV2(options ...Opt) *SysInfo { sysInfo := &SysInfo{ CgroupUnified: true, cg2GroupPath: "/", @@ -53,11 +53,6 @@ func newV2(quiet bool, options ...Opt) *SysInfo { for _, o := range ops { o(sysInfo) } - if !quiet { - for _, w := range sysInfo.Warnings { - logrus.Warn(w) - } - } return sysInfo } diff --git a/pkg/sysinfo/sysinfo_linux.go b/pkg/sysinfo/sysinfo_linux.go index 2065d6c3f7..f4a8f32443 100644 --- a/pkg/sysinfo/sysinfo_linux.go +++ b/pkg/sysinfo/sysinfo_linux.go @@ -45,16 +45,15 @@ func WithCgroup2GroupPath(g string) Opt { } // New returns a new SysInfo, using the filesystem to detect which features -// the kernel supports. If `quiet` is `false` info.Warnings are printed in logs -// whenever an error occurs or misconfigurations are present. -func New(quiet bool, options ...Opt) *SysInfo { +// the kernel supports. +func New(options ...Opt) *SysInfo { if cdcgroups.Mode() == cdcgroups.Unified { - return newV2(quiet, options...) + return newV2(options...) } - return newV1(quiet) + return newV1() } -func newV1(quiet bool) *SysInfo { +func newV1() *SysInfo { var ( err error sysInfo = &SysInfo{} @@ -84,11 +83,6 @@ func newV1(quiet bool) *SysInfo { for _, o := range ops { o(sysInfo) } - if !quiet { - for _, w := range sysInfo.Warnings { - logrus.Warn(w) - } - } return sysInfo } diff --git a/pkg/sysinfo/sysinfo_linux_test.go b/pkg/sysinfo/sysinfo_linux_test.go index aa557c9230..8c42cacfe8 100644 --- a/pkg/sysinfo/sysinfo_linux_test.go +++ b/pkg/sysinfo/sysinfo_linux_test.go @@ -55,11 +55,7 @@ func TestCgroupEnabled(t *testing.T) { } func TestNew(t *testing.T) { - sysInfo := New(false) - assert.Assert(t, sysInfo != nil) - checkSysInfo(t, sysInfo) - - sysInfo = New(true) + sysInfo := New() assert.Assert(t, sysInfo != nil) checkSysInfo(t, sysInfo) } @@ -82,7 +78,7 @@ func TestNewAppArmorEnabled(t *testing.T) { t.Skip("App Armor Must be Enabled") } - sysInfo := New(true) + sysInfo := New() assert.Assert(t, sysInfo.AppArmor) } @@ -92,7 +88,7 @@ func TestNewAppArmorDisabled(t *testing.T) { t.Skip("App Armor Must be Disabled") } - sysInfo := New(true) + sysInfo := New() assert.Assert(t, !sysInfo.AppArmor) } @@ -102,7 +98,7 @@ func TestNewCgroupNamespacesEnabled(t *testing.T) { t.Skip("cgroup namespaces must be enabled") } - sysInfo := New(true) + sysInfo := New() assert.Assert(t, sysInfo.CgroupNamespaces) } @@ -112,7 +108,7 @@ func TestNewCgroupNamespacesDisabled(t *testing.T) { t.Skip("cgroup namespaces must be disabled") } - sysInfo := New(true) + sysInfo := New() assert.Assert(t, !sysInfo.CgroupNamespaces) } diff --git a/pkg/sysinfo/sysinfo_other.go b/pkg/sysinfo/sysinfo_other.go index 7ac7cd1850..8ccc7d79bc 100644 --- a/pkg/sysinfo/sysinfo_other.go +++ b/pkg/sysinfo/sysinfo_other.go @@ -3,6 +3,6 @@ package sysinfo // import "github.com/docker/docker/pkg/sysinfo" // New returns an empty SysInfo for non linux for now. -func New(quiet bool, options ...Opt) *SysInfo { +func New(options ...Opt) *SysInfo { return &SysInfo{} } diff --git a/runconfig/config.go b/runconfig/config.go index 3d435f54ae..41f953ac14 100644 --- a/runconfig/config.go +++ b/runconfig/config.go @@ -21,7 +21,7 @@ func (r ContainerDecoder) DecodeConfig(src io.Reader) (*container.Config, *conta if r.GetSysInfo != nil { si = r.GetSysInfo() } else { - si = sysinfo.New(true) + si = sysinfo.New() } return decodeContainerConfig(src, si) diff --git a/runconfig/config_test.go b/runconfig/config_test.go index 8b316e66e7..a2dc64ed0d 100644 --- a/runconfig/config_test.go +++ b/runconfig/config_test.go @@ -47,7 +47,7 @@ func TestDecodeContainerConfig(t *testing.T) { t.Fatal(err) } - c, h, _, err := decodeContainerConfig(bytes.NewReader(b), sysinfo.New(true)) + c, h, _, err := decodeContainerConfig(bytes.NewReader(b), sysinfo.New()) if err != nil { t.Fatal(fmt.Errorf("Error parsing %s: %v", f, err)) } @@ -131,5 +131,5 @@ func callDecodeContainerConfigIsolation(isolation string) (*container.Config, *c if b, err = json.Marshal(w); err != nil { return nil, nil, nil, fmt.Errorf("Error on marshal %s", err.Error()) } - return decodeContainerConfig(bytes.NewReader(b), sysinfo.New(true)) + return decodeContainerConfig(bytes.NewReader(b), sysinfo.New()) }