From a27f8aecadcc2df8c3675967b247eb5a27b63d9b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 15 Feb 2022 19:19:30 +0100 Subject: [PATCH] daemon: SystemInfo() extract container counts to a helper function This makes it more inline with other data we collect, and can be used to make some info optional at some point. Signed-off-by: Sebastiaan van Stijn --- daemon/info.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/daemon/info.go b/daemon/info.go index 22afbfafac..4be6ec0c80 100644 --- a/daemon/info.go +++ b/daemon/info.go @@ -30,14 +30,9 @@ func (daemon *Daemon) SystemInfo() *types.Info { defer metrics.StartTimer(hostInfoFunctions.WithValues("system_info"))() sysInfo := daemon.RawSysInfo() - cRunning, cPaused, cStopped := stateCtr.get() v := &types.Info{ ID: daemon.ID, - Containers: cRunning + cPaused + cStopped, - ContainersRunning: cRunning, - ContainersPaused: cPaused, - ContainersStopped: cStopped, Images: daemon.imageService.CountImages(), IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled, BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled, @@ -70,6 +65,7 @@ func (daemon *Daemon) SystemInfo() *types.Info { Isolation: daemon.defaultIsolation, } + daemon.fillContainerStates(v) daemon.fillAPIInfo(v) // Retrieve platform specific info daemon.fillPlatformInfo(v, sysInfo) @@ -181,6 +177,14 @@ func (daemon *Daemon) fillSecurityOptions(v *types.Info, sysInfo *sysinfo.SysInf v.SecurityOptions = securityOptions } +func (daemon *Daemon) fillContainerStates(v *types.Info) { + cRunning, cPaused, cStopped := stateCtr.get() + v.Containers = cRunning + cPaused + cStopped + v.ContainersPaused = cPaused + v.ContainersRunning = cRunning + v.ContainersStopped = cStopped +} + func (daemon *Daemon) fillAPIInfo(v *types.Info) { const warn string = ` Access to the remote API is equivalent to root access on the host. Refer