Skip to content

Commit e0bf28b

Browse files
authored
Merge pull request #4685 from kolyshkin/smaller-state
Make state.json 25% smaller
2 parents 8b98e82 + 3a33b6a commit e0bf28b

File tree

5 files changed

+76
-76
lines changed

5 files changed

+76
-76
lines changed

libcontainer/configs/config.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -92,69 +92,69 @@ type Syscall struct {
9292
// Config defines configuration options for executing a process inside a contained environment.
9393
type Config struct {
9494
// NoPivotRoot will use MS_MOVE and a chroot to jail the process into the container's rootfs
95-
// This is a common option when the container is running in ramdisk
96-
NoPivotRoot bool `json:"no_pivot_root"`
95+
// This is a common option when the container is running in ramdisk.
96+
NoPivotRoot bool `json:"no_pivot_root,omitempty"`
9797

9898
// ParentDeathSignal specifies the signal that is sent to the container's process in the case
9999
// that the parent process dies.
100-
ParentDeathSignal int `json:"parent_death_signal"`
100+
ParentDeathSignal int `json:"parent_death_signal,omitempty"`
101101

102102
// Path to a directory containing the container's root filesystem.
103103
Rootfs string `json:"rootfs"`
104104

105105
// Umask is the umask to use inside of the container.
106-
Umask *uint32 `json:"umask"`
106+
Umask *uint32 `json:"umask,omitempty"`
107107

108108
// Readonlyfs will remount the container's rootfs as readonly where only externally mounted
109109
// bind mounts are writtable.
110-
Readonlyfs bool `json:"readonlyfs"`
110+
Readonlyfs bool `json:"readonlyfs,omitempty"`
111111

112112
// Specifies the mount propagation flags to be applied to /.
113-
RootPropagation int `json:"rootPropagation"`
113+
RootPropagation int `json:"rootPropagation,omitempty"`
114114

115115
// Mounts specify additional source and destination paths that will be mounted inside the container's
116-
// rootfs and mount namespace if specified
116+
// rootfs and mount namespace if specified.
117117
Mounts []*Mount `json:"mounts"`
118118

119119
// The device nodes that should be automatically created within the container upon container start. Note, make sure that the node is marked as allowed in the cgroup as well!
120120
Devices []*devices.Device `json:"devices"`
121121

122-
MountLabel string `json:"mount_label"`
122+
MountLabel string `json:"mount_label,omitempty"`
123123

124-
// Hostname optionally sets the container's hostname if provided
125-
Hostname string `json:"hostname"`
124+
// Hostname optionally sets the container's hostname if provided.
125+
Hostname string `json:"hostname,omitempty"`
126126

127-
// Domainname optionally sets the container's domainname if provided
128-
Domainname string `json:"domainname"`
127+
// Domainname optionally sets the container's domainname if provided.
128+
Domainname string `json:"domainname,omitempty"`
129129

130130
// Namespaces specifies the container's namespaces that it should setup when cloning the init process
131-
// If a namespace is not provided that namespace is shared from the container's parent process
131+
// If a namespace is not provided that namespace is shared from the container's parent process.
132132
Namespaces Namespaces `json:"namespaces"`
133133

134134
// Capabilities specify the capabilities to keep when executing the process inside the container
135-
// All capabilities not specified will be dropped from the processes capability mask
136-
Capabilities *Capabilities `json:"capabilities"`
135+
// All capabilities not specified will be dropped from the processes capability mask.
136+
Capabilities *Capabilities `json:"capabilities,omitempty"`
137137

138-
// Networks specifies the container's network setup to be created
139-
Networks []*Network `json:"networks"`
138+
// Networks specifies the container's network setup to be created.
139+
Networks []*Network `json:"networks,omitempty"`
140140

141-
// Routes can be specified to create entries in the route table as the container is started
142-
Routes []*Route `json:"routes"`
141+
// Routes can be specified to create entries in the route table as the container is started.
142+
Routes []*Route `json:"routes,omitempty"`
143143

144144
// Cgroups specifies specific cgroup settings for the various subsystems that the container is
145-
// placed into to limit the resources the container has available
145+
// placed into to limit the resources the container has available.
146146
Cgroups *Cgroup `json:"cgroups"`
147147

148148
// AppArmorProfile specifies the profile to apply to the process running in the container and is
149-
// change at the time the process is execed
149+
// change at the time the process is executed.
150150
AppArmorProfile string `json:"apparmor_profile,omitempty"`
151151

152152
// ProcessLabel specifies the label to apply to the process running in the container. It is
153-
// commonly used by selinux
153+
// commonly used by selinux.
154154
ProcessLabel string `json:"process_label,omitempty"`
155155

156156
// Rlimits specifies the resource limits, such as max open files, to set in the container
157-
// If Rlimits are not set, the container will inherit rlimits from the parent process
157+
// If Rlimits are not set, the container will inherit rlimits from the parent process.
158158
Rlimits []Rlimit `json:"rlimits,omitempty"`
159159

160160
// OomScoreAdj specifies the adjustment to be made by the kernel when calculating oom scores
@@ -164,35 +164,35 @@ type Config struct {
164164
// More information about kernel oom score calculation here: https://lwn.net/Articles/317814/
165165
OomScoreAdj *int `json:"oom_score_adj,omitempty"`
166166

167-
// UIDMappings is an array of User ID mappings for User Namespaces
168-
UIDMappings []IDMap `json:"uid_mappings"`
167+
// UIDMappings is an array of User ID mappings for User Namespaces.
168+
UIDMappings []IDMap `json:"uid_mappings,omitempty"`
169169

170-
// GIDMappings is an array of Group ID mappings for User Namespaces
171-
GIDMappings []IDMap `json:"gid_mappings"`
170+
// GIDMappings is an array of Group ID mappings for User Namespaces.
171+
GIDMappings []IDMap `json:"gid_mappings,omitempty"`
172172

173173
// MaskPaths specifies paths within the container's rootfs to mask over with a bind
174174
// mount pointing to /dev/null as to prevent reads of the file.
175-
MaskPaths []string `json:"mask_paths"`
175+
MaskPaths []string `json:"mask_paths,omitempty"`
176176

177177
// ReadonlyPaths specifies paths within the container's rootfs to remount as read-only
178178
// so that these files prevent any writes.
179-
ReadonlyPaths []string `json:"readonly_paths"`
179+
ReadonlyPaths []string `json:"readonly_paths,omitempty"`
180180

181181
// Sysctl is a map of properties and their values. It is the equivalent of using
182182
// sysctl -w my.property.name value in Linux.
183-
Sysctl map[string]string `json:"sysctl"`
183+
Sysctl map[string]string `json:"sysctl,omitempty"`
184184

185185
// Seccomp allows actions to be taken whenever a syscall is made within the container.
186186
// A number of rules are given, each having an action to be taken if a syscall matches it.
187187
// A default action to be taken if no rules match is also given.
188-
Seccomp *Seccomp `json:"seccomp"`
188+
Seccomp *Seccomp `json:"seccomp,omitempty"`
189189

190190
// NoNewPrivileges controls whether processes in the container can gain additional privileges.
191191
NoNewPrivileges bool `json:"no_new_privileges,omitempty"`
192192

193193
// Hooks are a collection of actions to perform at various container lifecycle events.
194194
// CommandHooks are serialized to JSON, but other hooks are not.
195-
Hooks Hooks
195+
Hooks Hooks `json:"Hooks,omitempty"`
196196

197197
// Version is the version of opencontainer specification that is supported.
198198
Version string `json:"version"`
@@ -202,7 +202,7 @@ type Config struct {
202202

203203
// NoNewKeyring will not allocated a new session keyring for the container. It will use the
204204
// callers keyring in this case.
205-
NoNewKeyring bool `json:"no_new_keyring"`
205+
NoNewKeyring bool `json:"no_new_keyring,omitempty"`
206206

207207
// IntelRdt specifies settings for Intel RDT group that the container is placed into
208208
// to limit the resources (e.g., L3 cache, memory bandwidth) the container has available
@@ -445,15 +445,15 @@ func KnownHookNames() []string {
445445

446446
type Capabilities struct {
447447
// Bounding is the set of capabilities checked by the kernel.
448-
Bounding []string
448+
Bounding []string `json:"Bounding,omitempty"`
449449
// Effective is the set of capabilities checked by the kernel.
450-
Effective []string
450+
Effective []string `json:"Effective,omitempty"`
451451
// Inheritable is the capabilities preserved across execve.
452-
Inheritable []string
452+
Inheritable []string `json:"Inheritable,omitempty"`
453453
// Permitted is the limiting superset for effective capabilities.
454-
Permitted []string
454+
Permitted []string `json:"Permitted,omitempty"`
455455
// Ambient is the ambient set of capabilities that are kept.
456-
Ambient []string
456+
Ambient []string `json:"Ambient,omitempty"`
457457
}
458458

459459
// Deprecated: use (Hooks).Run instead.

libcontainer/configs/mount_linux.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "golang.org/x/sys/unix"
44

55
type MountIDMapping struct {
66
// Recursive indicates if the mapping needs to be recursive.
7-
Recursive bool `json:"recursive"`
7+
Recursive bool `json:"recursive,omitempty"`
88

99
// UserNSPath is a path to a user namespace that indicates the necessary
1010
// id-mappings for MOUNT_ATTR_IDMAP. If set to non-"", UIDMappings and
@@ -31,26 +31,26 @@ type Mount struct {
3131
Device string `json:"device"`
3232

3333
// Mount flags.
34-
Flags int `json:"flags"`
34+
Flags int `json:"flags,omitempty"`
3535

3636
// Mount flags that were explicitly cleared in the configuration (meaning
3737
// the user explicitly requested that these flags *not* be set).
38-
ClearedFlags int `json:"cleared_flags"`
38+
ClearedFlags int `json:"cleared_flags,omitempty"`
3939

40-
// Propagation Flags
41-
PropagationFlags []int `json:"propagation_flags"`
40+
// Propagation flags.
41+
PropagationFlags []int `json:"propagation_flags,omitempty"`
4242

4343
// Mount data applied to the mount.
44-
Data string `json:"data"`
44+
Data string `json:"data,omitempty"`
4545

4646
// Relabel source if set, "z" indicates shared, "Z" indicates unshared.
47-
Relabel string `json:"relabel"`
47+
Relabel string `json:"relabel,omitempty"`
4848

4949
// RecAttr represents mount properties to be applied recursively (AT_RECURSIVE), see mount_setattr(2).
50-
RecAttr *unix.MountAttr `json:"rec_attr"`
50+
RecAttr *unix.MountAttr `json:"rec_attr,omitempty"`
5151

5252
// Extensions are additional flags that are specific to runc.
53-
Extensions int `json:"extensions"`
53+
Extensions int `json:"extensions,omitempty"`
5454

5555
// Mapping is the MOUNT_ATTR_IDMAP configuration for the mount. If non-nil,
5656
// the mount is configured to use MOUNT_ATTR_IDMAP-style id mappings.

libcontainer/configs/namespaces_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func NamespaceTypes() []NamespaceType {
8686
// alternate path that is able to be joined via setns.
8787
type Namespace struct {
8888
Type NamespaceType `json:"type"`
89-
Path string `json:"path"`
89+
Path string `json:"path,omitempty"`
9090
}
9191

9292
func (n *Namespace) GetPath(pid int) string {

libcontainer/configs/network.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,49 @@ package configs
55
// The network configuration can be omitted from a container causing the
66
// container to be setup with the host's networking stack
77
type Network struct {
8-
// Type sets the networks type, commonly veth and loopback
8+
// Type sets the networks type, commonly veth and loopback.
99
Type string `json:"type"`
1010

11-
// Name of the network interface
12-
Name string `json:"name"`
11+
// Name of the network interface.
12+
Name string `json:"name,omitempty"`
1313

1414
// The bridge to use.
15-
Bridge string `json:"bridge"`
15+
Bridge string `json:"bridge,omitempty"`
1616

17-
// MacAddress contains the MAC address to set on the network interface
18-
MacAddress string `json:"mac_address"`
17+
// MacAddress contains the MAC address to set on the network interface.
18+
MacAddress string `json:"mac_address,omitempty"`
1919

20-
// Address contains the IPv4 and mask to set on the network interface
21-
Address string `json:"address"`
20+
// Address contains the IPv4 and mask to set on the network interface.
21+
Address string `json:"address,omitempty"`
2222

23-
// Gateway sets the gateway address that is used as the default for the interface
24-
Gateway string `json:"gateway"`
23+
// Gateway sets the gateway address that is used as the default for the interface.
24+
Gateway string `json:"gateway,omitempty"`
2525

26-
// IPv6Address contains the IPv6 and mask to set on the network interface
27-
IPv6Address string `json:"ipv6_address"`
26+
// IPv6Address contains the IPv6 and mask to set on the network interface.
27+
IPv6Address string `json:"ipv6_address,omitempty"`
2828

29-
// IPv6Gateway sets the ipv6 gateway address that is used as the default for the interface
30-
IPv6Gateway string `json:"ipv6_gateway"`
29+
// IPv6Gateway sets the ipv6 gateway address that is used as the default for the interface.
30+
IPv6Gateway string `json:"ipv6_gateway,omitempty"`
3131

3232
// Mtu sets the mtu value for the interface and will be mirrored on both the host and
3333
// container's interfaces if a pair is created, specifically in the case of type veth
3434
// Note: This does not apply to loopback interfaces.
35-
Mtu int `json:"mtu"`
35+
Mtu int `json:"mtu,omitempty"`
3636

3737
// TxQueueLen sets the tx_queuelen value for the interface and will be mirrored on both the host and
3838
// container's interfaces if a pair is created, specifically in the case of type veth
3939
// Note: This does not apply to loopback interfaces.
40-
TxQueueLen int `json:"txqueuelen"`
40+
TxQueueLen int `json:"txqueuelen,omitempty"`
4141

4242
// HostInterfaceName is a unique name of a veth pair that resides on in the host interface of the
4343
// container.
44-
HostInterfaceName string `json:"host_interface_name"`
44+
HostInterfaceName string `json:"host_interface_name,omitempty"`
4545

4646
// HairpinMode specifies if hairpin NAT should be enabled on the virtual interface
4747
// bridge port in the case of type veth
4848
// Note: This is unsupported on some systems.
4949
// Note: This does not apply to loopback interfaces.
50-
HairpinMode bool `json:"hairpin_mode"`
50+
HairpinMode bool `json:"hairpin_mode,omitempty"`
5151
}
5252

5353
// Route defines a routing table entry.
@@ -62,14 +62,14 @@ type Network struct {
6262
// destination of 0.0.0.0(or *) when viewed in the route table.
6363
type Route struct {
6464
// Destination specifies the destination IP address and mask in the CIDR form.
65-
Destination string `json:"destination"`
65+
Destination string `json:"destination,omitempty"`
6666

6767
// Source specifies the source IP address and mask in the CIDR form.
68-
Source string `json:"source"`
68+
Source string `json:"source,omitempty"`
6969

7070
// Gateway specifies the gateway IP address.
71-
Gateway string `json:"gateway"`
71+
Gateway string `json:"gateway,omitempty"`
7272

7373
// InterfaceName specifies the device to set this route up for, for example eth0.
74-
InterfaceName string `json:"interface_name"`
74+
InterfaceName string `json:"interface_name,omitempty"`
7575
}

libcontainer/container_linux.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,29 @@ type Container struct {
5050
type State struct {
5151
BaseState
5252

53-
// Platform specific fields below here
53+
// Platform specific fields below.
5454

5555
// Specified if the container was started under the rootless mode.
5656
// Set to true if BaseState.Config.RootlessEUID && BaseState.Config.RootlessCgroups
57-
Rootless bool `json:"rootless"`
57+
Rootless bool `json:"rootless,omitempty"`
5858

5959
// Paths to all the container's cgroups, as returned by (*cgroups.Manager).GetPaths
6060
//
6161
// For cgroup v1, a key is cgroup subsystem name, and the value is the path
6262
// to the cgroup for this subsystem.
6363
//
6464
// For cgroup v2 unified hierarchy, a key is "", and the value is the unified path.
65-
CgroupPaths map[string]string `json:"cgroup_paths"`
65+
CgroupPaths map[string]string `json:"cgroup_paths,omitempty"`
6666

6767
// NamespacePaths are filepaths to the container's namespaces. Key is the namespace type
6868
// with the value as the path.
6969
NamespacePaths map[configs.NamespaceType]string `json:"namespace_paths"`
7070

71-
// Container's standard descriptors (std{in,out,err}), needed for checkpoint and restore
71+
// Container's standard descriptors (std{in,out,err}), needed for checkpoint and restore.
7272
ExternalDescriptors []string `json:"external_descriptors,omitempty"`
7373

74-
// Intel RDT "resource control" filesystem path
75-
IntelRdtPath string `json:"intel_rdt_path"`
74+
// Intel RDT "resource control" filesystem path.
75+
IntelRdtPath string `json:"intel_rdt_path,omitempty"`
7676
}
7777

7878
// ID returns the container's unique ID

0 commit comments

Comments
 (0)