godep update ocitools/generate

Signed-off-by: Haiyan Meng <hmeng@redhat.com>
This commit is contained in:
Haiyan Meng 2016-08-01 18:35:33 -04:00 committed by Mrunal Patel
parent 764f02ca11
commit 18112081c2
2 changed files with 54 additions and 107 deletions

2
Godeps/Godeps.json generated
View file

@ -277,7 +277,7 @@
}, },
{ {
"ImportPath": "github.com/opencontainers/ocitools/generate", "ImportPath": "github.com/opencontainers/ocitools/generate",
"Rev": "bc8aadb6bbc2ceac25b0f247244c96a1432c2c1a" "Rev": "7233310b6ba4390b50cc509a04bc1d852558e8d3"
}, },
{ {
"ImportPath": "github.com/opencontainers/runc/libcontainer/user", "ImportPath": "github.com/opencontainers/runc/libcontainer/user",

View file

@ -237,20 +237,16 @@ func (g *Generator) SetHostname(s string) {
// ClearAnnotations clears g.spec.Annotations. // ClearAnnotations clears g.spec.Annotations.
func (g *Generator) ClearAnnotations() { func (g *Generator) ClearAnnotations() {
g.initSpec() if g.spec == nil {
return
}
g.spec.Annotations = make(map[string]string) g.spec.Annotations = make(map[string]string)
} }
// AddAnnotation adds an annotation into g.spec.Annotations. // AddAnnotation adds an annotation into g.spec.Annotations.
func (g *Generator) AddAnnotation(s string) error { func (g *Generator) AddAnnotation(key, value string) {
g.initSpecAnnotations() g.initSpecAnnotations()
g.spec.Annotations[key] = value
pair := strings.Split(s, "=")
if len(pair) != 2 {
return fmt.Errorf("incorrectly specified annotation: %s", s)
}
g.spec.Annotations[pair[0]] = pair[1]
return nil
} }
// RemoveAnnotation remove an annotation from g.spec.Annotations. // RemoveAnnotation remove an annotation from g.spec.Annotations.
@ -317,7 +313,9 @@ func (g *Generator) SetProcessArgs(args []string) {
// ClearProcessEnv clears g.spec.Process.Env. // ClearProcessEnv clears g.spec.Process.Env.
func (g *Generator) ClearProcessEnv() { func (g *Generator) ClearProcessEnv() {
g.initSpec() if g.spec == nil {
return
}
g.spec.Process.Env = []string{} g.spec.Process.Env = []string{}
} }
@ -329,25 +327,21 @@ func (g *Generator) AddProcessEnv(env string) {
// ClearProcessAdditionalGids clear g.spec.Process.AdditionalGids. // ClearProcessAdditionalGids clear g.spec.Process.AdditionalGids.
func (g *Generator) ClearProcessAdditionalGids() { func (g *Generator) ClearProcessAdditionalGids() {
g.initSpec() if g.spec == nil {
return
}
g.spec.Process.User.AdditionalGids = []uint32{} g.spec.Process.User.AdditionalGids = []uint32{}
} }
// AddProcessAdditionalGid adds an additional gid into g.spec.Process.AdditionalGids. // AddProcessAdditionalGid adds an additional gid into g.spec.Process.AdditionalGids.
func (g *Generator) AddProcessAdditionalGid(gid string) error { func (g *Generator) AddProcessAdditionalGid(gid uint32) {
groupID, err := strconv.Atoi(gid)
if err != nil {
return err
}
g.initSpec() g.initSpec()
for _, group := range g.spec.Process.User.AdditionalGids { for _, group := range g.spec.Process.User.AdditionalGids {
if group == uint32(groupID) { if group == gid {
return nil return
} }
} }
g.spec.Process.User.AdditionalGids = append(g.spec.Process.User.AdditionalGids, uint32(groupID)) g.spec.Process.User.AdditionalGids = append(g.spec.Process.User.AdditionalGids, gid)
return nil
} }
// SetProcessSelinuxLabel sets g.spec.Process.SelinuxLabel. // SetProcessSelinuxLabel sets g.spec.Process.SelinuxLabel.
@ -455,15 +449,9 @@ func (g *Generator) ClearLinuxSysctl() {
} }
// AddLinuxSysctl adds a new sysctl config into g.spec.Linux.Sysctl. // AddLinuxSysctl adds a new sysctl config into g.spec.Linux.Sysctl.
func (g *Generator) AddLinuxSysctl(s string) error { func (g *Generator) AddLinuxSysctl(key, value string) {
g.initSpecLinuxSysctl() g.initSpecLinuxSysctl()
g.spec.Linux.Sysctl[key] = value
pair := strings.Split(s, "=")
if len(pair) != 2 {
return fmt.Errorf("incorrectly specified sysctl: %s", s)
}
g.spec.Linux.Sysctl[pair[0]] = pair[1]
return nil
} }
// RemoveLinuxSysctl removes a sysctl config from g.spec.Linux.Sysctl. // RemoveLinuxSysctl removes a sysctl config from g.spec.Linux.Sysctl.
@ -746,35 +734,6 @@ func (g *Generator) RemoveSeccompSyscall(name string, action string) error {
return nil return nil
} }
func parseIDMapping(idms string) (rspec.IDMapping, error) {
idm := strings.Split(idms, ":")
if len(idm) != 3 {
return rspec.IDMapping{}, fmt.Errorf("idmappings error: %s", idms)
}
hid, err := strconv.Atoi(idm[0])
if err != nil {
return rspec.IDMapping{}, err
}
cid, err := strconv.Atoi(idm[1])
if err != nil {
return rspec.IDMapping{}, err
}
size, err := strconv.Atoi(idm[2])
if err != nil {
return rspec.IDMapping{}, err
}
idMapping := rspec.IDMapping{
HostID: uint32(hid),
ContainerID: uint32(cid),
Size: uint32(size),
}
return idMapping, nil
}
// ClearLinuxUIDMappings clear g.spec.Linux.UIDMappings. // ClearLinuxUIDMappings clear g.spec.Linux.UIDMappings.
func (g *Generator) ClearLinuxUIDMappings() { func (g *Generator) ClearLinuxUIDMappings() {
if g.spec == nil || g.spec.Linux == nil { if g.spec == nil || g.spec.Linux == nil {
@ -784,15 +743,15 @@ func (g *Generator) ClearLinuxUIDMappings() {
} }
// AddLinuxUIDMapping adds uidMap into g.spec.Linux.UIDMappings. // AddLinuxUIDMapping adds uidMap into g.spec.Linux.UIDMappings.
func (g *Generator) AddLinuxUIDMapping(uidMap string) error { func (g *Generator) AddLinuxUIDMapping(hid, cid, size uint32) {
r, err := parseIDMapping(uidMap) idMapping := rspec.IDMapping{
if err != nil { HostID: hid,
return err ContainerID: cid,
Size: size,
} }
g.initSpecLinux() g.initSpecLinux()
g.spec.Linux.UIDMappings = append(g.spec.Linux.UIDMappings, r) g.spec.Linux.UIDMappings = append(g.spec.Linux.UIDMappings, idMapping)
return nil
} }
// ClearLinuxGIDMappings clear g.spec.Linux.GIDMappings. // ClearLinuxGIDMappings clear g.spec.Linux.GIDMappings.
@ -804,15 +763,15 @@ func (g *Generator) ClearLinuxGIDMappings() {
} }
// AddLinuxGIDMapping adds gidMap into g.spec.Linux.GIDMappings. // AddLinuxGIDMapping adds gidMap into g.spec.Linux.GIDMappings.
func (g *Generator) AddLinuxGIDMapping(gidMap string) error { func (g *Generator) AddLinuxGIDMapping(hid, cid, size uint32) {
r, err := parseIDMapping(gidMap) idMapping := rspec.IDMapping{
if err != nil { HostID: hid,
return err ContainerID: cid,
Size: size,
} }
g.initSpecLinux() g.initSpecLinux()
g.spec.Linux.GIDMappings = append(g.spec.Linux.GIDMappings, r) g.spec.Linux.GIDMappings = append(g.spec.Linux.GIDMappings, idMapping)
return nil
} }
// SetLinuxRootPropagation sets g.spec.Linux.RootfsPropagation. // SetLinuxRootPropagation sets g.spec.Linux.RootfsPropagation.
@ -833,16 +792,6 @@ func (g *Generator) SetLinuxRootPropagation(rp string) error {
return nil return nil
} }
func parseHook(s string) rspec.Hook {
parts := strings.Split(s, ":")
args := []string{}
path := parts[0]
if len(parts) > 1 {
args = parts[1:]
}
return rspec.Hook{Path: path, Args: args}
}
// ClearPreStartHooks clear g.spec.Hooks.Prestart. // ClearPreStartHooks clear g.spec.Hooks.Prestart.
func (g *Generator) ClearPreStartHooks() { func (g *Generator) ClearPreStartHooks() {
if g.spec == nil { if g.spec == nil {
@ -852,11 +801,10 @@ func (g *Generator) ClearPreStartHooks() {
} }
// AddPreStartHook add a prestart hook into g.spec.Hooks.Prestart. // AddPreStartHook add a prestart hook into g.spec.Hooks.Prestart.
func (g *Generator) AddPreStartHook(s string) error { func (g *Generator) AddPreStartHook(path string, args []string) {
hook := parseHook(s)
g.initSpec() g.initSpec()
hook := rspec.Hook{Path: path, Args: args}
g.spec.Hooks.Prestart = append(g.spec.Hooks.Prestart, hook) g.spec.Hooks.Prestart = append(g.spec.Hooks.Prestart, hook)
return nil
} }
// ClearPostStopHooks clear g.spec.Hooks.Poststop. // ClearPostStopHooks clear g.spec.Hooks.Poststop.
@ -868,11 +816,10 @@ func (g *Generator) ClearPostStopHooks() {
} }
// AddPostStopHook adds a poststop hook into g.spec.Hooks.Poststop. // AddPostStopHook adds a poststop hook into g.spec.Hooks.Poststop.
func (g *Generator) AddPostStopHook(s string) error { func (g *Generator) AddPostStopHook(path string, args []string) {
hook := parseHook(s)
g.initSpec() g.initSpec()
hook := rspec.Hook{Path: path, Args: args}
g.spec.Hooks.Poststop = append(g.spec.Hooks.Poststop, hook) g.spec.Hooks.Poststop = append(g.spec.Hooks.Poststop, hook)
return nil
} }
// ClearPostStartHooks clear g.spec.Hooks.Poststart. // ClearPostStartHooks clear g.spec.Hooks.Poststart.
@ -884,25 +831,23 @@ func (g *Generator) ClearPostStartHooks() {
} }
// AddPostStartHook adds a poststart hook into g.spec.Hooks.Poststart. // AddPostStartHook adds a poststart hook into g.spec.Hooks.Poststart.
func (g *Generator) AddPostStartHook(s string) error { func (g *Generator) AddPostStartHook(path string, args []string) {
hook := parseHook(s)
g.initSpec() g.initSpec()
hook := rspec.Hook{Path: path, Args: args}
g.spec.Hooks.Poststart = append(g.spec.Hooks.Poststart, hook) g.spec.Hooks.Poststart = append(g.spec.Hooks.Poststart, hook)
return nil
} }
// AddTmpfsMount adds a tmpfs mount into g.spec.Mounts. // AddTmpfsMount adds a tmpfs mount into g.spec.Mounts.
func (g *Generator) AddTmpfsMount(dest string) error { func (g *Generator) AddTmpfsMount(dest string, options []string) {
mnt := rspec.Mount{ mnt := rspec.Mount{
Destination: dest, Destination: dest,
Type: "tmpfs", Type: "tmpfs",
Source: "tmpfs", Source: "tmpfs",
Options: []string{"nosuid", "nodev", "mode=755"}, Options: options,
} }
g.initSpec() g.initSpec()
g.spec.Mounts = append(g.spec.Mounts, mnt) g.spec.Mounts = append(g.spec.Mounts, mnt)
return nil
} }
// AddCgroupsMount adds a cgroup mount into g.spec.Mounts. // AddCgroupsMount adds a cgroup mount into g.spec.Mounts.
@ -929,20 +874,13 @@ func (g *Generator) AddCgroupsMount(mountCgroupOption string) error {
} }
// AddBindMount adds a bind mount into g.spec.Mounts. // AddBindMount adds a bind mount into g.spec.Mounts.
func (g *Generator) AddBindMount(bind string) error { func (g *Generator) AddBindMount(source, dest, options string) {
var source, dest string if options == "" {
options := "ro" options = "ro"
bparts := strings.SplitN(bind, ":", 3)
switch len(bparts) {
case 2:
source, dest = bparts[0], bparts[1]
case 3:
source, dest, options = bparts[0], bparts[1], bparts[2]
default:
return fmt.Errorf("--bind should have format src:dest:[options]")
} }
defaultOptions := []string{"bind"} defaultOptions := []string{"bind"}
mnt := rspec.Mount{ mnt := rspec.Mount{
Destination: dest, Destination: dest,
Type: "bind", Type: "bind",
@ -951,7 +889,6 @@ func (g *Generator) AddBindMount(bind string) error {
} }
g.initSpec() g.initSpec()
g.spec.Mounts = append(g.spec.Mounts, mnt) g.spec.Mounts = append(g.spec.Mounts, mnt)
return nil
} }
// SetupPrivileged sets up the priviledge-related fields inside g.spec. // SetupPrivileged sets up the priviledge-related fields inside g.spec.
@ -960,7 +897,7 @@ func (g *Generator) SetupPrivileged(privileged bool) {
// Add all capabilities in privileged mode. // Add all capabilities in privileged mode.
var finalCapList []string var finalCapList []string
for _, cap := range capability.List() { for _, cap := range capability.List() {
if g.HostSpecific && cap > capability.CAP_LAST_CAP { if g.HostSpecific && cap > lastCap() {
continue continue
} }
finalCapList = append(finalCapList, fmt.Sprintf("CAP_%s", strings.ToUpper(cap.String()))) finalCapList = append(finalCapList, fmt.Sprintf("CAP_%s", strings.ToUpper(cap.String())))
@ -973,13 +910,23 @@ func (g *Generator) SetupPrivileged(privileged bool) {
} }
} }
func lastCap() capability.Cap {
last := capability.CAP_LAST_CAP
// hack for RHEL6 which has no /proc/sys/kernel/cap_last_cap
if last == capability.Cap(63) {
last = capability.CAP_BLOCK_SUSPEND
}
return last
}
func checkCap(c string, hostSpecific bool) error { func checkCap(c string, hostSpecific bool) error {
isValid := false isValid := false
cp := strings.ToUpper(c) cp := strings.ToUpper(c)
for _, cap := range capability.List() { for _, cap := range capability.List() {
if cp == strings.ToUpper(cap.String()) { if cp == strings.ToUpper(cap.String()) {
if hostSpecific && cap > capability.CAP_LAST_CAP { if hostSpecific && cap > lastCap() {
return fmt.Errorf("CAP_%s is not supported on the current host", cp) return fmt.Errorf("CAP_%s is not supported on the current host", cp)
} }
isValid = true isValid = true