Skip to content

Commit 89fbfc1

Browse files
author
Mrunal Patel
committed
Merge pull request #51 from crosbymichael/addtypes
Add Go types for specification
2 parents 3e6d666 + 238800f commit 89fbfc1

File tree

3 files changed

+215
-0
lines changed

3 files changed

+215
-0
lines changed

spec.go

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package specs
2+
3+
// Spec is the base configuration for the container. It specifies platform
4+
// independent configuration.
5+
type Spec struct {
6+
// Version is the version of the specification that is supported.
7+
Version string `json:"version"`
8+
// Platform is the host information for OS and Arch.
9+
Platform Platform `json:"platform"`
10+
// Process is the container's main process.
11+
Process Process `json:"process"`
12+
// Root is the root information for the container's filesystem.
13+
Root Root `json:"root"`
14+
// Hostname is the containers host name.
15+
Hostname string `json:"hostname"`
16+
// Mounts profile configuration for adding mounts to the container's filesystem.
17+
Mounts []Mount `json:"mounts"`
18+
}
19+
20+
// Mount specifies a mount for a container.
21+
type Mount struct {
22+
// Type specifies the mount kind.
23+
Type string `json:"type"`
24+
// Source specifies the source path of the mount. In the case of bind mounts on
25+
// linux based systems this would be the file on the host.
26+
Source string `json:"source"`
27+
// Destination is the path where the mount will be placed relative to the container's root.
28+
Destination string `json:"destination"`
29+
// Options are fstab style mount options.
30+
Options string `json:"options"`
31+
}
32+
33+
// Process contains information to start a specific application inside the container.
34+
type Process struct {
35+
// Terminal creates an interactive terminal for the container.
36+
Terminal bool `json:"terminal"`
37+
// User specifies user information for the process.
38+
User User `json:"user"`
39+
// Args specifies the binary and arguments for the application to execute.
40+
Args []string `json:"args"`
41+
// Env populates the process environment for the process.
42+
Env []string `json:"env"`
43+
// Cwd is the current working directory for the process and must be
44+
// relative to the container's root.
45+
Cwd string `json:"cwd"`
46+
}
47+
48+
// Root contains information about the container's root filesystem on the host.
49+
type Root struct {
50+
// Path is the absolute path to the container's root filesystem.
51+
Path string `json:"path"`
52+
// Readonly makes the root filesystem for the container readonly before the process is executed.
53+
Readonly bool `json:"readonly"`
54+
}
55+
56+
// Platform specifies OS and arch information for the host system that the container
57+
// is created for.
58+
type Platform struct {
59+
// OS is the operating system.
60+
OS string `json:"os"`
61+
// Arch is the architecture
62+
Arch string `json:"arch"`
63+
}

spec_linux.go

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// +build linux
2+
3+
package specs
4+
5+
// LinuxSpec is the full specification for linux containers.
6+
type LinuxSpec struct {
7+
Spec
8+
// Linux is platform specific configuration for linux based containers.
9+
Linux Linux `json:"linux"`
10+
}
11+
12+
// Linux contains platform specific configuration for linux based containers.
13+
type Linux struct {
14+
// UidMapping specifies user mappings for supporting user namespaces on linux.
15+
UidMappings []IDMapping `json:"uidMappings"`
16+
// UidMapping specifies group mappings for supporting user namespaces on linux.
17+
GidMappings []IDMapping `json:"gidMappings"`
18+
// Rlimits specifies rlimit options to apply to the container's process.
19+
Rlimits []Rlimit `json:"rlimits"`
20+
// SystemProperties are a set of key value pairs that are set for the container on start.
21+
SystemProperties map[string]string `json:"systemProperties"`
22+
// Resources contain cgroup information for handling resource constraints
23+
// for the container.
24+
Resources Resources `json:"resources"`
25+
// Namespaces contains the namespaces that are created and/or joined by the container.
26+
Namespaces []Namespace `json:"namespaces"`
27+
// Capabilities are linux capabilities that are kept for the container.
28+
Capabilities []string `json:"capabilities"`
29+
// Devices are a list of device nodes that are created and enabled for the container.
30+
Devices []string `json:"devices"`
31+
}
32+
33+
// User specifies linux specific user and group information for the container's
34+
// main process.
35+
type User struct {
36+
// Uid is the user id.
37+
Uid int32 `json:"uid"`
38+
// Gid is the group id.
39+
Gid int32 `json:"gid"`
40+
// AdditionalGids are additional group ids set the the container's process.
41+
AdditionalGids []int32 `json:"additionalGids"`
42+
}
43+
44+
// Namespace is the configuration for a linux namespace.
45+
type Namespace struct {
46+
// Type is the type of linux namespace.
47+
Type string `json:"type"`
48+
// Path is a path to an existing namespace persisted on disk that can be joined
49+
// and is of the same type.
50+
Path string `json:"path"`
51+
}
52+
53+
// IDMapping specifies uid/gid mappings.
54+
type IDMapping struct {
55+
// From is the uid/gid of the host user or group.
56+
From int32 `json:"from"`
57+
// To is the uid/gid of the container's user or group.
58+
To int32 `json:"to"`
59+
// Count is how many uid/gids to map after To.
60+
Count int32 `json:"count"`
61+
}
62+
63+
// Rlimit type and restrictions.
64+
type Rlimit struct {
65+
// Type of the rlimit to set.
66+
Type int `json:"type"`
67+
// Hard is the hard limit for the specified type.
68+
Hard uint64 `json:"hard"`
69+
// Soft is the soft limit for the specified type.
70+
Soft uint64 `json:"soft"`
71+
}
72+
73+
type HugepageLimit struct {
74+
Pagesize string `json:"pageSize"`
75+
Limit int `json:"limit"`
76+
}
77+
78+
type InterfacePriority struct {
79+
// Name is the name of the network interface.
80+
Name string `json:"name"`
81+
// Priority for the interface.
82+
Priority int64 `json:"priority"`
83+
}
84+
85+
type BlockIO struct {
86+
// Specifies per cgroup weight, range is from 10 to 1000.
87+
Weight int64 `json:"blkioWeight"`
88+
// Weight per cgroup per device, can override BlkioWeight.
89+
WeightDevice string `json:"blkioWeightDevice"`
90+
// IO read rate limit per cgroup per device, bytes per second.
91+
ThrottleReadBpsDevice string `json:"blkioThrottleReadBpsDevice"`
92+
// IO write rate limit per cgroup per divice, bytes per second.
93+
ThrottleWriteBpsDevice string `json:"blkioThrottleWriteBpsDevice"`
94+
// IO read rate limit per cgroup per device, IO per second.
95+
ThrottleReadIOpsDevice string `json:"blkioThrottleReadIopsDevice"`
96+
// IO write rate limit per cgroup per device, IO per second.
97+
ThrottleWriteIOpsDevice string `json:"blkioThrottleWriteIopsDevice"`
98+
}
99+
100+
type Memory struct {
101+
// Memory limit (in bytes)
102+
Limit int64 `json:"limit"`
103+
// Memory reservation or soft_limit (in bytes)
104+
Reservation int64 `json:"reservation"`
105+
// Total memory usage (memory + swap); set `-1' to disable swap
106+
Swap int64 `json:"swap"`
107+
// Kernel memory limit (in bytes)
108+
Kernel int64 `json:"kernel"`
109+
}
110+
111+
type CPU struct {
112+
// CPU shares (relative weight vs. other cgroups with cpu shares).
113+
Shares int64 `json:"shares"`
114+
// CPU hardcap limit (in usecs). Allowed cpu time in a given period.
115+
Quota int64 `json:"quota"`
116+
// CPU period to be used for hardcapping (in usecs). 0 to use system default.
117+
Period int64 `json:"period"`
118+
// How many time CPU will use in realtime scheduling (in usecs).
119+
RealtimeRuntime int64 `json:"realtimeRuntime"`
120+
// CPU period to be used for realtime scheduling (in usecs).
121+
RealtimePeriod int64 `json:"realtimePeriod"`
122+
// CPU to use within the cpuset.
123+
Cpus string `json:"cpus"`
124+
// MEM to use within the cpuset.
125+
Mems string `json:"mems"`
126+
}
127+
128+
type Network struct {
129+
// Set class identifier for container's network packets.
130+
ClassID string `json:"classId"`
131+
// Set priority of network traffic for container.
132+
Priorities []InterfacePriority `json:"priorities"`
133+
}
134+
135+
type Resources struct {
136+
// DisableOOMKiller disables the OOM killer for out of memory conditions.
137+
DisableOOMKiller bool `json:"disableOOMKiller"`
138+
// Memory restriction configuration.
139+
Memory Memory `json:"memory"`
140+
// CPU resource restriction configuration.
141+
CPU CPU `json:"cpu"`
142+
// BlockIO restriction configuration.
143+
BlockIO BlockIO `json:"blockIO"`
144+
// Hugetlb limit (in bytes)
145+
HugepageLimits []HugepageLimit `json:"hugepageLimits"`
146+
// Network restriction configuration.
147+
Network Network `json:"network"`
148+
}

version.go

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package specs
2+
3+
// Version is the specification version that the package types support.
4+
const Version = "pre-draft"

0 commit comments

Comments
 (0)