Skip to content

Commit c90229e

Browse files
committed
api/types: move system info types to api/types/system
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 98d3da7 commit c90229e

24 files changed

Lines changed: 329 additions & 260 deletions

File tree

api/server/router/system/backend.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/docker/docker/api/types/filters"
1010
"github.com/docker/docker/api/types/registry"
1111
"github.com/docker/docker/api/types/swarm"
12+
"github.com/docker/docker/api/types/system"
1213
)
1314

1415
// DiskUsageOptions holds parameters for system disk usage query.
@@ -26,7 +27,7 @@ type DiskUsageOptions struct {
2627
// Backend is the methods that need to be implemented to provide
2728
// system specific functionality.
2829
type Backend interface {
29-
SystemInfo() *types.Info
30+
SystemInfo() *system.Info
3031
SystemVersion() types.Version
3132
SystemDiskUsage(ctx context.Context, opts DiskUsageOptions) (*types.DiskUsage, error)
3233
SubscribeToEvents(since, until time.Time, ef filters.Args) ([]events.Message, chan interface{})

api/server/router/system/system.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package system // import "github.com/docker/docker/api/server/router/system"
22

33
import (
44
"github.com/docker/docker/api/server/router"
5-
"github.com/docker/docker/api/types"
5+
"github.com/docker/docker/api/types/system"
66
buildkit "github.com/docker/docker/builder/builder-next"
77
"resenje.org/singleflight"
88
)
@@ -19,7 +19,7 @@ type systemRouter struct {
1919
// collectSystemInfo is a single-flight for the /info endpoint,
2020
// unique per API version (as different API versions may return
2121
// a different API response).
22-
collectSystemInfo singleflight.Group[string, *types.Info]
22+
collectSystemInfo singleflight.Group[string, *system.Info]
2323
}
2424

2525
// NewRouter initializes a new system router

api/server/router/system/system_routes.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/docker/docker/api/types/filters"
1616
"github.com/docker/docker/api/types/registry"
1717
"github.com/docker/docker/api/types/swarm"
18+
"github.com/docker/docker/api/types/system"
1819
timetypes "github.com/docker/docker/api/types/time"
1920
"github.com/docker/docker/api/types/versions"
2021
"github.com/docker/docker/pkg/ioutils"
@@ -58,7 +59,7 @@ func (s *systemRouter) swarmStatus() string {
5859

5960
func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
6061
version := httputils.VersionFromContext(ctx)
61-
info, _, _ := s.collectSystemInfo.Do(ctx, version, func(ctx context.Context) (*types.Info, error) {
62+
info, _, _ := s.collectSystemInfo.Do(ctx, version, func(ctx context.Context) (*system.Info, error) {
6263
info := s.backend.SystemInfo()
6364

6465
if s.cluster != nil {
@@ -68,7 +69,7 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
6869

6970
if versions.LessThan(version, "1.25") {
7071
// TODO: handle this conversion in engine-api
71-
kvSecOpts, err := types.DecodeSecurityOptions(info.SecurityOptions)
72+
kvSecOpts, err := system.DecodeSecurityOptions(info.SecurityOptions)
7273
if err != nil {
7374
info.Warnings = append(info.Warnings, err.Error())
7475
}

api/types/system/info.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package system
2+
3+
import (
4+
"github.com/docker/docker/api/types/container"
5+
"github.com/docker/docker/api/types/registry"
6+
"github.com/docker/docker/api/types/swarm"
7+
)
8+
9+
// Info contains response of Engine API:
10+
// GET "/info"
11+
type Info struct {
12+
ID string
13+
Containers int
14+
ContainersRunning int
15+
ContainersPaused int
16+
ContainersStopped int
17+
Images int
18+
Driver string
19+
DriverStatus [][2]string
20+
SystemStatus [][2]string `json:",omitempty"` // SystemStatus is only propagated by the Swarm standalone API
21+
Plugins PluginsInfo
22+
MemoryLimit bool
23+
SwapLimit bool
24+
KernelMemory bool `json:",omitempty"` // Deprecated: kernel 5.4 deprecated kmem.limit_in_bytes
25+
KernelMemoryTCP bool `json:",omitempty"` // KernelMemoryTCP is not supported on cgroups v2.
26+
CPUCfsPeriod bool `json:"CpuCfsPeriod"`
27+
CPUCfsQuota bool `json:"CpuCfsQuota"`
28+
CPUShares bool
29+
CPUSet bool
30+
PidsLimit bool
31+
IPv4Forwarding bool
32+
BridgeNfIptables bool
33+
BridgeNfIP6tables bool `json:"BridgeNfIp6tables"`
34+
Debug bool
35+
NFd int
36+
OomKillDisable bool
37+
NGoroutines int
38+
SystemTime string
39+
LoggingDriver string
40+
CgroupDriver string
41+
CgroupVersion string `json:",omitempty"`
42+
NEventsListener int
43+
KernelVersion string
44+
OperatingSystem string
45+
OSVersion string
46+
OSType string
47+
Architecture string
48+
IndexServerAddress string
49+
RegistryConfig *registry.ServiceConfig
50+
NCPU int
51+
MemTotal int64
52+
GenericResources []swarm.GenericResource
53+
DockerRootDir string
54+
HTTPProxy string `json:"HttpProxy"`
55+
HTTPSProxy string `json:"HttpsProxy"`
56+
NoProxy string
57+
Name string
58+
Labels []string
59+
ExperimentalBuild bool
60+
ServerVersion string
61+
Runtimes map[string]Runtime
62+
DefaultRuntime string
63+
Swarm swarm.Info
64+
// LiveRestoreEnabled determines whether containers should be kept
65+
// running when the daemon is shutdown or upon daemon start if
66+
// running containers are detected
67+
LiveRestoreEnabled bool
68+
Isolation container.Isolation
69+
InitBinary string
70+
ContainerdCommit Commit
71+
RuncCommit Commit
72+
InitCommit Commit
73+
SecurityOptions []string
74+
ProductLicense string `json:",omitempty"`
75+
DefaultAddressPools []NetworkAddressPool `json:",omitempty"`
76+
77+
// Legacy API fields for older API versions.
78+
legacyFields
79+
80+
// Warnings contains a slice of warnings that occurred while collecting
81+
// system information. These warnings are intended to be informational
82+
// messages for the user, and are not intended to be parsed / used for
83+
// other purposes, as they do not have a fixed format.
84+
Warnings []string
85+
}
86+
87+
type legacyFields struct {
88+
ExecutionDriver string `json:",omitempty"` // Deprecated: deprecated since API v1.25, but returned for older versions.
89+
}
90+
91+
// PluginsInfo is a temp struct holding Plugins name
92+
// registered with docker daemon. It is used by [Info] struct
93+
type PluginsInfo struct {
94+
// List of Volume plugins registered
95+
Volume []string
96+
// List of Network plugins registered
97+
Network []string
98+
// List of Authorization plugins registered
99+
Authorization []string
100+
// List of Log plugins registered
101+
Log []string
102+
}
103+
104+
// Commit holds the Git-commit (SHA1) that a binary was built from, as reported
105+
// in the version-string of external tools, such as containerd, or runC.
106+
type Commit struct {
107+
ID string // ID is the actual commit ID of external tool.
108+
Expected string // Expected is the commit ID of external tool expected by dockerd as set at build time.
109+
}
110+
111+
// NetworkAddressPool is a temp struct used by [Info] struct.
112+
type NetworkAddressPool struct {
113+
Base string
114+
Size int
115+
}

api/types/system/runtime.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package system
2+
3+
// Runtime describes an OCI runtime
4+
type Runtime struct {
5+
// "Legacy" runtime configuration for runc-compatible runtimes.
6+
7+
Path string `json:"path,omitempty"`
8+
Args []string `json:"runtimeArgs,omitempty"`
9+
10+
// Shimv2 runtime configuration. Mutually exclusive with the legacy config above.
11+
12+
Type string `json:"runtimeType,omitempty"`
13+
Options map[string]interface{} `json:"options,omitempty"`
14+
}

api/types/system/security_opts.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package system
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"strings"
7+
)
8+
9+
// SecurityOpt contains the name and options of a security option
10+
type SecurityOpt struct {
11+
Name string
12+
Options []KeyValue
13+
}
14+
15+
// DecodeSecurityOptions decodes a security options string slice to a
16+
// type-safe [SecurityOpt].
17+
func DecodeSecurityOptions(opts []string) ([]SecurityOpt, error) {
18+
so := []SecurityOpt{}
19+
for _, opt := range opts {
20+
// support output from a < 1.13 docker daemon
21+
if !strings.Contains(opt, "=") {
22+
so = append(so, SecurityOpt{Name: opt})
23+
continue
24+
}
25+
secopt := SecurityOpt{}
26+
for _, s := range strings.Split(opt, ",") {
27+
k, v, ok := strings.Cut(s, "=")
28+
if !ok {
29+
return nil, fmt.Errorf("invalid security option %q", s)
30+
}
31+
if k == "" || v == "" {
32+
return nil, errors.New("invalid empty security option")
33+
}
34+
if k == "name" {
35+
secopt.Name = v
36+
continue
37+
}
38+
secopt.Options = append(secopt.Options, KeyValue{Key: k, Value: v})
39+
}
40+
so = append(so, secopt)
41+
}
42+
return so, nil
43+
}
44+
45+
// KeyValue holds a key/value pair.
46+
type KeyValue struct {
47+
Key, Value string
48+
}

0 commit comments

Comments
 (0)