This repository was archived by the owner on Feb 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathspec.go
141 lines (125 loc) · 4.48 KB
/
spec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package json
type VolumeDescriptor struct {
Device string `json:"device"`
Addr string `json:"addr,omitempty"`
Mount string `json:"mount"`
Fstype string `json:"fstype,omitempty"`
ReadOnly bool `json:"readOnly"`
DockerVolume bool `json:"dockerVolume"`
}
type FsmapDescriptor struct {
Source string `json:"source"`
Path string `json:"path"`
ReadOnly bool `json:"readOnly"`
DockerVolume bool `json:"dockerVolume"`
}
type EnvironmentVar struct {
Env string `json:"env"`
Value string `json:"value"`
}
// Rlimit type and restrictions
type Rlimit struct {
// Type of the rlimit to set
Type string `json:"type"`
// Hard is the hard limit for the specified type
Hard uint64 `json:"hard"`
// Soft is the soft limit for the specified type
Soft uint64 `json:"soft"`
}
type Process struct {
// Process Id
Id string `json:"id"`
// User, Group, AdditionalGroups specify the user information
User string `json:"user,omitempty"`
Group string `json:"group,omitempty"`
AdditionalGroups []string `json:"additionalGroups,omitempty"`
// Terminal creates an interactive terminal for the process.
Terminal bool `json:"terminal"`
// Sequeue number for stdin and stdout
Stdio uint64 `json:"stdio,omitempty"`
// sequeue number for stderr if it is not shared with stdout
Stderr uint64 `json:"stderr,omitempty"`
// Args specifies the binary and arguments for the application to execute.
Args []string `json:"args"`
// Envs populates the process environment for the process.
Envs []EnvironmentVar `json:"envs,omitempty"`
// Workdir is the current working directory for the process and must be
// relative to the container's root.
Workdir string `json:"workdir"`
// Rlimits specifies rlimit options to apply to the process.
Rlimits []Rlimit `json:"rlimits,omitempty"`
}
type Port struct {
HostPort int `json:"hostPort"`
ContainerPort int `json:"containerPort"`
Protocol string `json:"protocol"`
}
type Container struct {
Id string `json:"id"`
Rootfs string `json:"rootfs"`
Fstype string `json:"fstype,omitempty"`
Image string `json:"image"`
Addr string `json:"addr,omitempty"`
Volumes []*VolumeDescriptor `json:"volumes,omitempty"`
Fsmap []*FsmapDescriptor `json:"fsmap,omitempty"`
Sysctl map[string]string `json:"sysctl,omitempty"`
Process *Process `json:"process"`
RestartPolicy string `json:"restartPolicy"`
Initialize bool `json:"initialize"`
ReadOnly bool `json:"readOnly"`
Ports []Port `json:"ports,omitempty"` //deprecated
}
type IpAddress struct {
IpAddress string `json:"ipAddress"`
NetMask string `json:"netMask"`
}
type NetworkInf struct {
Device string `json:"device"`
NewName string `json:"newDeviceName"`
IpAddresses []IpAddress `json:"ipAddresses"`
Mtu uint64 `json:"mtu"`
}
type Route struct {
Dest string `json:"dest"`
Gateway string `json:"gateway,omitempty"`
Device string `json:"device,omitempty"`
}
type PortmappingWhiteList struct {
InternalNetworks []string `json:"internalNetworks,omitempty"`
ExternalNetworks []string `json:"externalNetworks,omitempty"`
}
type Pod struct {
Hostname string `json:"hostname"`
DeprecatedContainers []Container `json:"containers,omitempty"`
DeprecatedInterfaces []NetworkInf `json:"interfaces,omitempty"`
Dns []string `json:"dns,omitempty"`
DnsOptions []string `json:"dnsOptions,omitempty"`
DnsSearch []string `json:"dnsSearch,omitempty"`
DeprecatedRoutes []Route `json:"routes,omitempty"`
ShareDir string `json:"shareDir,omitempty"`
PortmappingWhiteLists *PortmappingWhiteList `json:"portmappingWhiteLists,omitempty"`
}
func (cr *Container) RoLookup(mpoint string) bool {
if v := cr.volLookup(mpoint); v != nil {
return v.ReadOnly
} else if m := cr.mapLookup(mpoint); m != nil {
return m.ReadOnly
}
return false
}
func (cr *Container) mapLookup(mpoint string) *FsmapDescriptor {
for _, fs := range cr.Fsmap {
if fs.Path == mpoint {
return fs
}
}
return nil
}
func (cr *Container) volLookup(mpoint string) *VolumeDescriptor {
for _, vol := range cr.Volumes {
if vol.Mount == mpoint {
return vol
}
}
return nil
}