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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2021-07-14 16:45:02 +02:00
parent 1fb62f455c
commit 9b795c3e50
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
15 changed files with 33 additions and 45 deletions

View file

@ -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()),

View file

@ -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() {

View file

@ -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 {

View file

@ -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()
}

View file

@ -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()
}

View file

@ -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{

View file

@ -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")
}

View file

@ -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

View file

@ -84,6 +84,6 @@ func overlayFSSupported() bool {
func init() {
if testEnv.IsLocalDaemon() {
SysInfo = sysinfo.New(true)
SysInfo = sysinfo.New()
}
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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)
}

View file

@ -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{}
}

View file

@ -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)

View file

@ -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())
}