api/types: move system info types to api/types/system

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-03 13:14:14 +02:00
parent 98d3da79ef
commit c90229ed9a
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
24 changed files with 329 additions and 260 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/system"
)
// DiskUsageOptions holds parameters for system disk usage query.
@ -26,7 +27,7 @@ type DiskUsageOptions struct {
// Backend is the methods that need to be implemented to provide
// system specific functionality.
type Backend interface {
SystemInfo() *types.Info
SystemInfo() *system.Info
SystemVersion() types.Version
SystemDiskUsage(ctx context.Context, opts DiskUsageOptions) (*types.DiskUsage, error)
SubscribeToEvents(since, until time.Time, ef filters.Args) ([]events.Message, chan interface{})

View file

@ -2,7 +2,7 @@ package system // import "github.com/docker/docker/api/server/router/system"
import (
"github.com/docker/docker/api/server/router"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/system"
buildkit "github.com/docker/docker/builder/builder-next"
"resenje.org/singleflight"
)
@ -19,7 +19,7 @@ type systemRouter struct {
// collectSystemInfo is a single-flight for the /info endpoint,
// unique per API version (as different API versions may return
// a different API response).
collectSystemInfo singleflight.Group[string, *types.Info]
collectSystemInfo singleflight.Group[string, *system.Info]
}
// NewRouter initializes a new system router

View file

@ -15,6 +15,7 @@ import (
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/system"
timetypes "github.com/docker/docker/api/types/time"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/pkg/ioutils"
@ -58,7 +59,7 @@ func (s *systemRouter) swarmStatus() string {
func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
version := httputils.VersionFromContext(ctx)
info, _, _ := s.collectSystemInfo.Do(ctx, version, func(ctx context.Context) (*types.Info, error) {
info, _, _ := s.collectSystemInfo.Do(ctx, version, func(ctx context.Context) (*system.Info, error) {
info := s.backend.SystemInfo()
if s.cluster != nil {
@ -68,7 +69,7 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
if versions.LessThan(version, "1.25") {
// TODO: handle this conversion in engine-api
kvSecOpts, err := types.DecodeSecurityOptions(info.SecurityOptions)
kvSecOpts, err := system.DecodeSecurityOptions(info.SecurityOptions)
if err != nil {
info.Warnings = append(info.Warnings, err.Error())
}

115
api/types/system/info.go Normal file
View file

@ -0,0 +1,115 @@
package system
import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/swarm"
)
// Info contains response of Engine API:
// GET "/info"
type Info struct {
ID string
Containers int
ContainersRunning int
ContainersPaused int
ContainersStopped int
Images int
Driver string
DriverStatus [][2]string
SystemStatus [][2]string `json:",omitempty"` // SystemStatus is only propagated by the Swarm standalone API
Plugins PluginsInfo
MemoryLimit bool
SwapLimit bool
KernelMemory bool `json:",omitempty"` // Deprecated: kernel 5.4 deprecated kmem.limit_in_bytes
KernelMemoryTCP bool `json:",omitempty"` // KernelMemoryTCP is not supported on cgroups v2.
CPUCfsPeriod bool `json:"CpuCfsPeriod"`
CPUCfsQuota bool `json:"CpuCfsQuota"`
CPUShares bool
CPUSet bool
PidsLimit bool
IPv4Forwarding bool
BridgeNfIptables bool
BridgeNfIP6tables bool `json:"BridgeNfIp6tables"`
Debug bool
NFd int
OomKillDisable bool
NGoroutines int
SystemTime string
LoggingDriver string
CgroupDriver string
CgroupVersion string `json:",omitempty"`
NEventsListener int
KernelVersion string
OperatingSystem string
OSVersion string
OSType string
Architecture string
IndexServerAddress string
RegistryConfig *registry.ServiceConfig
NCPU int
MemTotal int64
GenericResources []swarm.GenericResource
DockerRootDir string
HTTPProxy string `json:"HttpProxy"`
HTTPSProxy string `json:"HttpsProxy"`
NoProxy string
Name string
Labels []string
ExperimentalBuild bool
ServerVersion string
Runtimes map[string]Runtime
DefaultRuntime string
Swarm swarm.Info
// LiveRestoreEnabled determines whether containers should be kept
// running when the daemon is shutdown or upon daemon start if
// running containers are detected
LiveRestoreEnabled bool
Isolation container.Isolation
InitBinary string
ContainerdCommit Commit
RuncCommit Commit
InitCommit Commit
SecurityOptions []string
ProductLicense string `json:",omitempty"`
DefaultAddressPools []NetworkAddressPool `json:",omitempty"`
// Legacy API fields for older API versions.
legacyFields
// Warnings contains a slice of warnings that occurred while collecting
// system information. These warnings are intended to be informational
// messages for the user, and are not intended to be parsed / used for
// other purposes, as they do not have a fixed format.
Warnings []string
}
type legacyFields struct {
ExecutionDriver string `json:",omitempty"` // Deprecated: deprecated since API v1.25, but returned for older versions.
}
// PluginsInfo is a temp struct holding Plugins name
// registered with docker daemon. It is used by [Info] struct
type PluginsInfo struct {
// List of Volume plugins registered
Volume []string
// List of Network plugins registered
Network []string
// List of Authorization plugins registered
Authorization []string
// List of Log plugins registered
Log []string
}
// Commit holds the Git-commit (SHA1) that a binary was built from, as reported
// in the version-string of external tools, such as containerd, or runC.
type Commit struct {
ID string // ID is the actual commit ID of external tool.
Expected string // Expected is the commit ID of external tool expected by dockerd as set at build time.
}
// NetworkAddressPool is a temp struct used by [Info] struct.
type NetworkAddressPool struct {
Base string
Size int
}

View file

@ -0,0 +1,14 @@
package system
// Runtime describes an OCI runtime
type Runtime struct {
// "Legacy" runtime configuration for runc-compatible runtimes.
Path string `json:"path,omitempty"`
Args []string `json:"runtimeArgs,omitempty"`
// Shimv2 runtime configuration. Mutually exclusive with the legacy config above.
Type string `json:"runtimeType,omitempty"`
Options map[string]interface{} `json:"options,omitempty"`
}

View file

@ -0,0 +1,48 @@
package system
import (
"errors"
"fmt"
"strings"
)
// SecurityOpt contains the name and options of a security option
type SecurityOpt struct {
Name string
Options []KeyValue
}
// DecodeSecurityOptions decodes a security options string slice to a
// type-safe [SecurityOpt].
func DecodeSecurityOptions(opts []string) ([]SecurityOpt, error) {
so := []SecurityOpt{}
for _, opt := range opts {
// support output from a < 1.13 docker daemon
if !strings.Contains(opt, "=") {
so = append(so, SecurityOpt{Name: opt})
continue
}
secopt := SecurityOpt{}
for _, s := range strings.Split(opt, ",") {
k, v, ok := strings.Cut(s, "=")
if !ok {
return nil, fmt.Errorf("invalid security option %q", s)
}
if k == "" || v == "" {
return nil, errors.New("invalid empty security option")
}
if k == "name" {
secopt.Name = v
continue
}
secopt.Options = append(secopt.Options, KeyValue{Key: k, Value: v})
}
so = append(so, secopt)
}
return so, nil
}
// KeyValue holds a key/value pair.
type KeyValue struct {
Key, Value string
}

View file

@ -1,18 +1,14 @@
package types // import "github.com/docker/docker/api/types"
import (
"errors"
"fmt"
"io"
"os"
"strings"
"time"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/volume"
"github.com/docker/go-connections/nat"
@ -232,155 +228,6 @@ type Version struct {
BuildTime string `json:",omitempty"`
}
// Commit holds the Git-commit (SHA1) that a binary was built from, as reported
// in the version-string of external tools, such as containerd, or runC.
type Commit struct {
ID string // ID is the actual commit ID of external tool.
Expected string // Expected is the commit ID of external tool expected by dockerd as set at build time.
}
// Info contains response of Engine API:
// GET "/info"
type Info struct {
ID string
Containers int
ContainersRunning int
ContainersPaused int
ContainersStopped int
Images int
Driver string
DriverStatus [][2]string
SystemStatus [][2]string `json:",omitempty"` // SystemStatus is only propagated by the Swarm standalone API
Plugins PluginsInfo
MemoryLimit bool
SwapLimit bool
KernelMemory bool `json:",omitempty"` // Deprecated: kernel 5.4 deprecated kmem.limit_in_bytes
KernelMemoryTCP bool `json:",omitempty"` // KernelMemoryTCP is not supported on cgroups v2.
CPUCfsPeriod bool `json:"CpuCfsPeriod"`
CPUCfsQuota bool `json:"CpuCfsQuota"`
CPUShares bool
CPUSet bool
PidsLimit bool
IPv4Forwarding bool
BridgeNfIptables bool
BridgeNfIP6tables bool `json:"BridgeNfIp6tables"`
Debug bool
NFd int
OomKillDisable bool
NGoroutines int
SystemTime string
LoggingDriver string
CgroupDriver string
CgroupVersion string `json:",omitempty"`
NEventsListener int
KernelVersion string
OperatingSystem string
OSVersion string
OSType string
Architecture string
IndexServerAddress string
RegistryConfig *registry.ServiceConfig
NCPU int
MemTotal int64
GenericResources []swarm.GenericResource
DockerRootDir string
HTTPProxy string `json:"HttpProxy"`
HTTPSProxy string `json:"HttpsProxy"`
NoProxy string
Name string
Labels []string
ExperimentalBuild bool
ServerVersion string
Runtimes map[string]Runtime
DefaultRuntime string
Swarm swarm.Info
// LiveRestoreEnabled determines whether containers should be kept
// running when the daemon is shutdown or upon daemon start if
// running containers are detected
LiveRestoreEnabled bool
Isolation container.Isolation
InitBinary string
ContainerdCommit Commit
RuncCommit Commit
InitCommit Commit
SecurityOptions []string
ProductLicense string `json:",omitempty"`
DefaultAddressPools []NetworkAddressPool `json:",omitempty"`
// Legacy API fields for older API versions.
legacyFields
// Warnings contains a slice of warnings that occurred while collecting
// system information. These warnings are intended to be informational
// messages for the user, and are not intended to be parsed / used for
// other purposes, as they do not have a fixed format.
Warnings []string
}
type legacyFields struct {
ExecutionDriver string `json:",omitempty"` // Deprecated: deprecated since API v1.25, but returned for older versions.
}
// KeyValue holds a key/value pair
type KeyValue struct {
Key, Value string
}
// NetworkAddressPool is a temp struct used by Info struct
type NetworkAddressPool struct {
Base string
Size int
}
// SecurityOpt contains the name and options of a security option
type SecurityOpt struct {
Name string
Options []KeyValue
}
// DecodeSecurityOptions decodes a security options string slice to a type safe
// SecurityOpt
func DecodeSecurityOptions(opts []string) ([]SecurityOpt, error) {
so := []SecurityOpt{}
for _, opt := range opts {
// support output from a < 1.13 docker daemon
if !strings.Contains(opt, "=") {
so = append(so, SecurityOpt{Name: opt})
continue
}
secopt := SecurityOpt{}
for _, s := range strings.Split(opt, ",") {
k, v, ok := strings.Cut(s, "=")
if !ok {
return nil, fmt.Errorf("invalid security option %q", s)
}
if k == "" || v == "" {
return nil, errors.New("invalid empty security option")
}
if k == "name" {
secopt.Name = v
continue
}
secopt.Options = append(secopt.Options, KeyValue{Key: k, Value: v})
}
so = append(so, secopt)
}
return so, nil
}
// PluginsInfo is a temp struct holding Plugins name
// registered with docker daemon. It is used by Info struct
type PluginsInfo struct {
// List of Volume plugins registered
Volume []string
// List of Network plugins registered
Network []string
// List of Authorization plugins registered
Authorization []string
// List of Log plugins registered
Log []string
}
// ExecStartCheck is a temp struct used by execStart
// Config fields is part of ExecConfig in runconfig package
type ExecStartCheck struct {
@ -652,19 +499,6 @@ type Checkpoint struct {
Name string // Name is the name of the checkpoint
}
// Runtime describes an OCI runtime
type Runtime struct {
// "Legacy" runtime configuration for runc-compatible runtimes.
Path string `json:"path,omitempty"`
Args []string `json:"runtimeArgs,omitempty"`
// Shimv2 runtime configuration. Mutually exclusive with the legacy config above.
Type string `json:"runtimeType,omitempty"`
Options map[string]interface{} `json:"options,omitempty"`
}
// DiskUsageObject represents an object type used for disk usage query filtering.
type DiskUsageObject string

View file

@ -0,0 +1,49 @@
package types
import "github.com/docker/docker/api/types/system"
// Info contains response of Engine API:
// GET "/info"
//
// Deprecated: use [system.Info].
type Info = system.Info
// Commit holds the Git-commit (SHA1) that a binary was built from, as reported
// in the version-string of external tools, such as containerd, or runC.
//
// Deprecated: use [system.Commit].
type Commit = system.Commit
// PluginsInfo is a temp struct holding Plugins name
// registered with docker daemon. It is used by [system.Info] struct
//
// Deprecated: use [system.PluginsInfo].
type PluginsInfo = system.PluginsInfo
// NetworkAddressPool is a temp struct used by [system.Info] struct.
//
// Deprecated: use [system.NetworkAddressPool].
type NetworkAddressPool = system.NetworkAddressPool
// Runtime describes an OCI runtime.
//
// Deprecated: use [system.Runtime].
type Runtime = system.Runtime
// SecurityOpt contains the name and options of a security option.
//
// Deprecated: use [system.SecurityOpt].
type SecurityOpt = system.SecurityOpt
// KeyValue holds a key/value pair.
//
// Deprecated: use [system.KeyValue].
type KeyValue = system.KeyValue
// DecodeSecurityOptions decodes a security options string slice to a type safe
// [system.SecurityOpt].
//
// Deprecated: use [system.DecodeSecurityOptions].
func DecodeSecurityOptions(opts []string) ([]system.SecurityOpt, error) {
return system.DecodeSecurityOptions(opts)
}

View file

@ -6,12 +6,12 @@ import (
"fmt"
"net/url"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/system"
)
// Info returns information about the docker server.
func (cli *Client) Info(ctx context.Context) (types.Info, error) {
var info types.Info
func (cli *Client) Info(ctx context.Context) (system.Info, error) {
var info system.Info
serverResp, err := cli.get(ctx, "/info", url.Values{}, nil)
defer ensureReaderClosed(serverResp)
if err != nil {

View file

@ -10,7 +10,7 @@ import (
"strings"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/errdefs"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
@ -46,7 +46,7 @@ func TestInfo(t *testing.T) {
if !strings.HasPrefix(req.URL.Path, expectedURL) {
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
}
info := &types.Info{
info := &system.Info{
ID: "daemonID",
Containers: 3,
}

View file

@ -14,6 +14,7 @@ import (
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/api/types/volume"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
@ -165,7 +166,7 @@ type SwarmAPIClient interface {
// SystemAPIClient defines API client methods for the system
type SystemAPIClient interface {
Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error)
Info(ctx context.Context) (types.Info, error)
Info(ctx context.Context) (system.Info, error)
RegistryLogin(ctx context.Context, auth registry.AuthConfig) (registry.AuthenticateOKBody, error)
DiskUsage(ctx context.Context, options types.DiskUsageOptions) (types.DiskUsage, error)
Ping(ctx context.Context) (types.Ping, error)

View file

@ -16,6 +16,7 @@ import (
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/api/types/volume"
containerpkg "github.com/docker/docker/container"
clustertypes "github.com/docker/docker/daemon/cluster/provider"
@ -52,7 +53,7 @@ type Backend interface {
SetContainerDependencyStore(name string, store exec.DependencyGetter) error
SetContainerSecretReferences(name string, refs []*swarm.SecretReference) error
SetContainerConfigReferences(name string, refs []*swarm.ConfigReference) error
SystemInfo() *types.Info
SystemInfo() *system.Info
Containers(ctx context.Context, config *types.ContainerListOptions) ([]*types.Container, error)
SetNetworkBootstrapKeys([]*networktypes.EncryptionKey) error
DaemonJoinsCluster(provider cluster.Provider)

View file

@ -7,8 +7,8 @@ import (
"path/filepath"
"github.com/containerd/cgroups/v3"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/homedir"
"github.com/docker/docker/pkg/rootless"
@ -61,22 +61,22 @@ type Config struct {
CommonConfig
// Fields below here are platform specific.
Runtimes map[string]types.Runtime `json:"runtimes,omitempty"`
DefaultInitBinary string `json:"default-init,omitempty"`
CgroupParent string `json:"cgroup-parent,omitempty"`
EnableSelinuxSupport bool `json:"selinux-enabled,omitempty"`
RemappedRoot string `json:"userns-remap,omitempty"`
Ulimits map[string]*units.Ulimit `json:"default-ulimits,omitempty"`
CPURealtimePeriod int64 `json:"cpu-rt-period,omitempty"`
CPURealtimeRuntime int64 `json:"cpu-rt-runtime,omitempty"`
OOMScoreAdjust int `json:"oom-score-adjust,omitempty"` // Deprecated: configure the daemon's oom-score-adjust using a process manager instead.
Init bool `json:"init,omitempty"`
InitPath string `json:"init-path,omitempty"`
SeccompProfile string `json:"seccomp-profile,omitempty"`
ShmSize opts.MemBytes `json:"default-shm-size,omitempty"`
NoNewPrivileges bool `json:"no-new-privileges,omitempty"`
IpcMode string `json:"default-ipc-mode,omitempty"`
CgroupNamespaceMode string `json:"default-cgroupns-mode,omitempty"`
Runtimes map[string]system.Runtime `json:"runtimes,omitempty"`
DefaultInitBinary string `json:"default-init,omitempty"`
CgroupParent string `json:"cgroup-parent,omitempty"`
EnableSelinuxSupport bool `json:"selinux-enabled,omitempty"`
RemappedRoot string `json:"userns-remap,omitempty"`
Ulimits map[string]*units.Ulimit `json:"default-ulimits,omitempty"`
CPURealtimePeriod int64 `json:"cpu-rt-period,omitempty"`
CPURealtimeRuntime int64 `json:"cpu-rt-runtime,omitempty"`
OOMScoreAdjust int `json:"oom-score-adjust,omitempty"` // Deprecated: configure the daemon's oom-score-adjust using a process manager instead.
Init bool `json:"init,omitempty"`
InitPath string `json:"init-path,omitempty"`
SeccompProfile string `json:"seccomp-profile,omitempty"`
ShmSize opts.MemBytes `json:"default-shm-size,omitempty"`
NoNewPrivileges bool `json:"no-new-privileges,omitempty"`
IpcMode string `json:"default-ipc-mode,omitempty"`
CgroupNamespaceMode string `json:"default-cgroupns-mode,omitempty"`
// ResolvConf is the path to the configuration of the host resolver
ResolvConf string `json:"resolv-conf,omitempty"`
Rootless bool `json:"rootless,omitempty"`
@ -184,7 +184,7 @@ func setPlatformDefaults(cfg *Config) error {
cfg.ShmSize = opts.MemBytes(DefaultShmSize)
cfg.SeccompProfile = SeccompProfileDefault
cfg.IpcMode = string(DefaultIpcMode)
cfg.Runtimes = make(map[string]types.Runtime)
cfg.Runtimes = make(map[string]system.Runtime)
if cgroups.Mode() != cgroups.Unified {
cfg.CgroupNamespaceMode = string(DefaultCgroupV1NamespaceMode)

View file

@ -11,6 +11,7 @@ import (
"github.com/containerd/containerd/log"
"github.com/docker/docker/api"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/cli/debug"
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/daemon/logger"
@ -27,13 +28,13 @@ import (
)
// SystemInfo returns information about the host server the daemon is running on.
func (daemon *Daemon) SystemInfo() *types.Info {
func (daemon *Daemon) SystemInfo() *system.Info {
defer metrics.StartTimer(hostInfoFunctions.WithValues("system_info"))()
sysInfo := daemon.RawSysInfo()
cfg := daemon.config()
v := &types.Info{
v := &system.Info{
ID: daemon.id,
Images: daemon.imageService.CountImages(),
IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled,
@ -122,7 +123,7 @@ func (daemon *Daemon) SystemVersion() types.Version {
return v
}
func (daemon *Daemon) fillDriverInfo(v *types.Info) {
func (daemon *Daemon) fillDriverInfo(v *system.Info) {
v.Driver = daemon.imageService.StorageDriver()
v.DriverStatus = daemon.imageService.LayerStoreStatus()
@ -138,8 +139,8 @@ WARNING: The %s storage-driver is deprecated, and will be removed in a future re
fillDriverWarnings(v)
}
func (daemon *Daemon) fillPluginsInfo(v *types.Info, cfg *config.Config) {
v.Plugins = types.PluginsInfo{
func (daemon *Daemon) fillPluginsInfo(v *system.Info, cfg *config.Config) {
v.Plugins = system.PluginsInfo{
Volume: daemon.volumes.GetDriverList(),
Network: daemon.GetNetworkDriverList(),
@ -150,7 +151,7 @@ func (daemon *Daemon) fillPluginsInfo(v *types.Info, cfg *config.Config) {
}
}
func (daemon *Daemon) fillSecurityOptions(v *types.Info, sysInfo *sysinfo.SysInfo, cfg *config.Config) {
func (daemon *Daemon) fillSecurityOptions(v *system.Info, sysInfo *sysinfo.SysInfo, cfg *config.Config) {
var securityOptions []string
if sysInfo.AppArmor {
securityOptions = append(securityOptions, "name=apparmor")
@ -180,7 +181,7 @@ func (daemon *Daemon) fillSecurityOptions(v *types.Info, sysInfo *sysinfo.SysInf
v.SecurityOptions = securityOptions
}
func (daemon *Daemon) fillContainerStates(v *types.Info) {
func (daemon *Daemon) fillContainerStates(v *system.Info) {
cRunning, cPaused, cStopped := stateCtr.get()
v.Containers = cRunning + cPaused + cStopped
v.ContainersPaused = cPaused
@ -196,14 +197,14 @@ func (daemon *Daemon) fillContainerStates(v *types.Info) {
// this information optional (cli to request "with debugging information"), or
// only collect it if the daemon has debug enabled. For the CLI code, see
// https://github.com/docker/cli/blob/v20.10.12/cli/command/system/info.go#L239-L244
func (daemon *Daemon) fillDebugInfo(v *types.Info) {
func (daemon *Daemon) fillDebugInfo(v *system.Info) {
v.Debug = debug.IsEnabled()
v.NFd = fileutils.GetTotalUsedFds()
v.NGoroutines = runtime.NumGoroutine()
v.NEventsListener = daemon.EventsService.SubscribersCount()
}
func (daemon *Daemon) fillAPIInfo(v *types.Info, cfg *config.Config) {
func (daemon *Daemon) fillAPIInfo(v *system.Info, cfg *config.Config) {
const warn string = `
Access to the remote API is equivalent to root access on the host. Refer
to the 'Docker daemon attack surface' section in the documentation for
@ -226,9 +227,9 @@ func (daemon *Daemon) fillAPIInfo(v *types.Info, cfg *config.Config) {
}
}
func (daemon *Daemon) fillDefaultAddressPools(v *types.Info, cfg *config.Config) {
func (daemon *Daemon) fillDefaultAddressPools(v *system.Info, cfg *config.Config) {
for _, pool := range cfg.DefaultAddressPools.Value() {
v.DefaultAddressPools = append(v.DefaultAddressPools, types.NetworkAddressPool{
v.DefaultAddressPools = append(v.DefaultAddressPools, system.NetworkAddressPool{
Base: pool.Base,
Size: pool.Size,
})

View file

@ -14,6 +14,7 @@ import (
v2runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/pkg/rootless"
"github.com/docker/docker/pkg/sysinfo"
@ -22,7 +23,7 @@ import (
)
// fillPlatformInfo fills the platform related info.
func (daemon *Daemon) fillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo, cfg *configStore) {
func (daemon *Daemon) fillPlatformInfo(v *system.Info, sysInfo *sysinfo.SysInfo, cfg *configStore) {
v.CgroupDriver = cgroupDriver(&cfg.Config)
v.CgroupVersion = "1"
if sysInfo.CgroupUnified {
@ -41,12 +42,12 @@ func (daemon *Daemon) fillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo,
v.CPUSet = sysInfo.Cpuset
v.PidsLimit = sysInfo.PidsLimit
}
v.Runtimes = make(map[string]types.Runtime)
v.Runtimes = make(map[string]system.Runtime)
for n, p := range stockRuntimes() {
v.Runtimes[n] = types.Runtime{Path: p}
v.Runtimes[n] = system.Runtime{Path: p}
}
for n, r := range cfg.Config.Runtimes {
v.Runtimes[n] = types.Runtime{
v.Runtimes[n] = system.Runtime{
Path: r.Path,
Args: append([]string(nil), r.Args...),
}
@ -280,7 +281,7 @@ func getRootlessKitClient() (rkclient.Client, error) {
return rkclient.New(apiSock)
}
func fillDriverWarnings(v *types.Info) {
func fillDriverWarnings(v *system.Info) {
for _, pair := range v.DriverStatus {
if pair[0] == "Extended file attributes" && pair[1] == "best-effort" {
msg := fmt.Sprintf("WARNING: %s: extended file attributes from container images "+

View file

@ -2,17 +2,18 @@ package daemon // import "github.com/docker/docker/daemon"
import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/pkg/sysinfo"
)
// fillPlatformInfo fills the platform related info.
func (daemon *Daemon) fillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo, cfg *configStore) {
func (daemon *Daemon) fillPlatformInfo(v *system.Info, sysInfo *sysinfo.SysInfo, cfg *configStore) {
}
func (daemon *Daemon) fillPlatformVersion(v *types.Version, cfg *configStore) {}
func fillDriverWarnings(v *types.Info) {
func fillDriverWarnings(v *system.Info) {
}
func cgroupNamespacesEnabled(sysInfo *sysinfo.SysInfo, cfg *config.Config) bool {

View file

@ -1,10 +1,10 @@
package daemon // import "github.com/docker/docker/daemon"
import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/dockerversion"
)
func (daemon *Daemon) fillLicense(v *types.Info) {
func (daemon *Daemon) fillLicense(v *system.Info) {
v.ProductLicense = dockerversion.DefaultProductLicense
}

View file

@ -3,13 +3,13 @@ package daemon // import "github.com/docker/docker/daemon"
import (
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/dockerversion"
"gotest.tools/v3/assert"
)
func TestFillLicense(t *testing.T) {
v := &types.Info{}
v := &system.Info{}
d := &Daemon{
root: "/var/lib/docker/",
}

View file

@ -11,13 +11,12 @@ import (
runtimeoptions_v1 "github.com/containerd/containerd/pkg/runtimeoptions/v1"
"github.com/containerd/containerd/plugin"
v2runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/errdefs"
"github.com/imdario/mergo"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"github.com/docker/docker/api/types"
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/errdefs"
)
func TestSetupRuntimes(t *testing.T) {
@ -29,7 +28,7 @@ func TestSetupRuntimes(t *testing.T) {
{
name: "Empty",
config: &config.Config{
Runtimes: map[string]types.Runtime{
Runtimes: map[string]system.Runtime{
"myruntime": {},
},
},
@ -38,7 +37,7 @@ func TestSetupRuntimes(t *testing.T) {
{
name: "ArgsOnly",
config: &config.Config{
Runtimes: map[string]types.Runtime{
Runtimes: map[string]system.Runtime{
"myruntime": {Args: []string{"foo", "bar"}},
},
},
@ -47,7 +46,7 @@ func TestSetupRuntimes(t *testing.T) {
{
name: "OptionsOnly",
config: &config.Config{
Runtimes: map[string]types.Runtime{
Runtimes: map[string]system.Runtime{
"myruntime": {Options: map[string]interface{}{"hello": "world"}},
},
},
@ -56,7 +55,7 @@ func TestSetupRuntimes(t *testing.T) {
{
name: "PathAndType",
config: &config.Config{
Runtimes: map[string]types.Runtime{
Runtimes: map[string]system.Runtime{
"myruntime": {Path: "/bin/true", Type: "io.containerd.runsc.v1"},
},
},
@ -65,7 +64,7 @@ func TestSetupRuntimes(t *testing.T) {
{
name: "PathAndOptions",
config: &config.Config{
Runtimes: map[string]types.Runtime{
Runtimes: map[string]system.Runtime{
"myruntime": {Path: "/bin/true", Options: map[string]interface{}{"a": "b"}},
},
},
@ -74,7 +73,7 @@ func TestSetupRuntimes(t *testing.T) {
{
name: "TypeAndArgs",
config: &config.Config{
Runtimes: map[string]types.Runtime{
Runtimes: map[string]system.Runtime{
"myruntime": {Type: "io.containerd.runsc.v1", Args: []string{"--version"}},
},
},
@ -83,7 +82,7 @@ func TestSetupRuntimes(t *testing.T) {
{
name: "PathArgsOptions",
config: &config.Config{
Runtimes: map[string]types.Runtime{
Runtimes: map[string]system.Runtime{
"myruntime": {
Path: "/bin/true",
Args: []string{"--version"},
@ -96,7 +95,7 @@ func TestSetupRuntimes(t *testing.T) {
{
name: "TypeOptionsArgs",
config: &config.Config{
Runtimes: map[string]types.Runtime{
Runtimes: map[string]system.Runtime{
"myruntime": {
Type: "io.containerd.kata.v2",
Options: map[string]interface{}{"a": "b"},
@ -109,7 +108,7 @@ func TestSetupRuntimes(t *testing.T) {
{
name: "PathArgsTypeOptions",
config: &config.Config{
Runtimes: map[string]types.Runtime{
Runtimes: map[string]system.Runtime{
"myruntime": {
Path: "/bin/true",
Args: []string{"foo"},
@ -123,7 +122,7 @@ func TestSetupRuntimes(t *testing.T) {
{
name: "CannotOverrideStockRuntime",
config: &config.Config{
Runtimes: map[string]types.Runtime{
Runtimes: map[string]system.Runtime{
config.StockRuntimeName: {},
},
},
@ -157,7 +156,7 @@ func TestSetupRuntimes(t *testing.T) {
{
name: "SetDefinedRuntimeAsDefault",
config: &config.Config{
Runtimes: map[string]types.Runtime{
Runtimes: map[string]system.Runtime{
"some-runtime": {
Path: "/usr/local/bin/file-not-found",
},
@ -192,30 +191,30 @@ func TestGetRuntime(t *testing.T) {
// which would not be allowed as implicit runtime names. Explicit takes
// precedence over implicit.
const configuredRtName = "my/custom.runtime.v1"
configuredRuntime := types.Runtime{Path: "/bin/true"}
configuredRuntime := system.Runtime{Path: "/bin/true"}
const rtWithArgsName = "withargs"
rtWithArgs := types.Runtime{
rtWithArgs := system.Runtime{
Path: "/bin/false",
Args: []string{"--version"},
}
const shimWithOptsName = "shimwithopts"
shimWithOpts := types.Runtime{
shimWithOpts := system.Runtime{
Type: plugin.RuntimeRuncV2,
Options: map[string]interface{}{"IoUid": 42},
}
const shimAliasName = "wasmedge"
shimAlias := types.Runtime{Type: "io.containerd.wasmedge.v1"}
shimAlias := system.Runtime{Type: "io.containerd.wasmedge.v1"}
const configuredShimByPathName = "shimwithpath"
configuredShimByPath := types.Runtime{Type: "/path/to/my/shim"}
configuredShimByPath := system.Runtime{Type: "/path/to/my/shim"}
// A runtime configured with the generic 'runtimeoptions/v1.Options' shim configuration options.
// https://gvisor.dev/docs/user_guide/containerd/configuration/#:~:text=to%20the%20shim.-,Containerd%201.3%2B,-Starting%20in%201.3
const gvisorName = "gvisor"
gvisorRuntime := types.Runtime{
gvisorRuntime := system.Runtime{
Type: "io.containerd.runsc.v1",
Options: map[string]interface{}{
"TypeUrl": "io.containerd.runsc.v1.options",
@ -227,7 +226,7 @@ func TestGetRuntime(t *testing.T) {
assert.NilError(t, err)
cfg.Root = t.TempDir()
cfg.Runtimes = map[string]types.Runtime{
cfg.Runtimes = map[string]system.Runtime{
configuredRtName: configuredRuntime,
rtWithArgsName: rtWithArgs,
shimWithOptsName: shimWithOpts,
@ -363,7 +362,7 @@ func TestGetRuntime_PreflightCheck(t *testing.T) {
assert.NilError(t, err)
cfg.Root = t.TempDir()
cfg.Runtimes = map[string]types.Runtime{
cfg.Runtimes = map[string]system.Runtime{
"path-only": {
Path: "/usr/local/bin/file-not-found",
},
@ -393,7 +392,7 @@ func TestRuntimeWrapping(t *testing.T) {
cfg, err := config.New()
assert.NilError(t, err)
cfg.Root = t.TempDir()
cfg.Runtimes = map[string]types.Runtime{
cfg.Runtimes = map[string]system.Runtime{
"change-args": {
Path: "/bin/true",
Args: []string{"foo", "bar"},
@ -431,15 +430,15 @@ func TestRuntimeWrapping(t *testing.T) {
}
}
cfg.Runtimes["change-args"] = types.Runtime{
cfg.Runtimes["change-args"] = system.Runtime{
Path: cfg.Runtimes["change-args"].Path,
Args: []string{"baz", "quux"},
}
cfg.Runtimes["change-path"] = types.Runtime{
cfg.Runtimes["change-path"] = system.Runtime{
Path: "/bin/false",
Args: cfg.Runtimes["change-path"].Args,
}
cfg.Runtimes["drop-args"] = types.Runtime{
cfg.Runtimes["drop-args"] = system.Runtime{
Path: cfg.Runtimes["drop-args"].Path,
}
delete(cfg.Runtimes, "goes-away")

View file

@ -14,6 +14,7 @@ import (
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
"github.com/docker/docker/testutil/request"
@ -71,7 +72,7 @@ func (s *DockerAPISuite) TestAPIStatsStoppedContainerInGoroutines(c *testing.T)
getGoRoutines := func() int {
_, body, err := request.Get("/info")
assert.NilError(c, err)
info := types.Info{}
info := system.Info{}
err = json.NewDecoder(body).Decode(&info)
assert.NilError(c, err)
body.Close()

View file

@ -18,6 +18,7 @@ import (
"github.com/containerd/containerd/remotes/docker"
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/testutil/daemon"
"github.com/docker/docker/testutil/fixtures/plugin"
@ -234,11 +235,11 @@ func TestPluginsWithRuntimes(t *testing.T) {
assert.NilError(t, os.WriteFile(p, []byte(script), 0o777))
type config struct {
Runtimes map[string]types.Runtime `json:"runtimes"`
Runtimes map[string]system.Runtime `json:"runtimes"`
}
cfg, err := json.Marshal(config{
Runtimes: map[string]types.Runtime{
Runtimes: map[string]system.Runtime{
"myrt": {Path: p},
"myrtArgs": {Path: p, Args: []string{"someArg"}},
},

View file

@ -4,20 +4,20 @@ import (
"fmt"
"strings"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/system"
)
// RuntimeOpt defines a map of Runtimes
type RuntimeOpt struct {
name string
stockRuntimeName string
values *map[string]types.Runtime
values *map[string]system.Runtime
}
// NewNamedRuntimeOpt creates a new RuntimeOpt
func NewNamedRuntimeOpt(name string, ref *map[string]types.Runtime, stockRuntime string) *RuntimeOpt {
func NewNamedRuntimeOpt(name string, ref *map[string]system.Runtime, stockRuntime string) *RuntimeOpt {
if ref == nil {
ref = &map[string]types.Runtime{}
ref = &map[string]system.Runtime{}
}
return &RuntimeOpt{name: name, values: ref, stockRuntimeName: stockRuntime}
}
@ -51,7 +51,7 @@ func (o *RuntimeOpt) Set(val string) error {
return fmt.Errorf("runtime '%s' was already defined", k)
}
(*o.values)[k] = types.Runtime{Path: v}
(*o.values)[k] = system.Runtime{Path: v}
return nil
}
@ -67,12 +67,12 @@ func (o *RuntimeOpt) String() string {
}
// GetMap returns a map of Runtimes (name: path)
func (o *RuntimeOpt) GetMap() map[string]types.Runtime {
func (o *RuntimeOpt) GetMap() map[string]system.Runtime {
if o.values != nil {
return *o.values
}
return map[string]types.Runtime{}
return map[string]system.Runtime{}
}
// Type returns the type of the option

View file

@ -13,8 +13,8 @@ import (
"testing"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/client"
"github.com/docker/docker/container"
"github.com/docker/docker/pkg/ioutils"
@ -90,7 +90,7 @@ type Daemon struct {
DataPathPort uint32
OOMScoreAdjust int
// cached information
CachedInfo types.Info
CachedInfo system.Info
}
// NewDaemon returns a Daemon instance to be used for testing.
@ -817,7 +817,7 @@ func (d *Daemon) queryRootDir() (string, error) {
}
// Info returns the info struct for this daemon
func (d *Daemon) Info(t testing.TB) types.Info {
func (d *Daemon) Info(t testing.TB) system.Info {
t.Helper()
c := d.NewClientT(t)
info, err := c.Info(context.Background())

View file

@ -10,6 +10,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/client"
"github.com/docker/docker/testutil/fixtures/load"
"github.com/pkg/errors"
@ -20,7 +21,7 @@ import (
// under test
type Execution struct {
client client.APIClient
DaemonInfo types.Info
DaemonInfo system.Info
PlatformDefaults PlatformDefaults
protectedElements protectedElements
}
@ -57,7 +58,7 @@ func FromClient(c *client.Client) (*Execution, error) {
}, nil
}
func getPlatformDefaults(info types.Info) PlatformDefaults {
func getPlatformDefaults(info system.Info) PlatformDefaults {
volumesPath := filepath.Join(info.DockerRootDir, "volumes")
containersPath := filepath.Join(info.DockerRootDir, "containers")