id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
167,200
rkt/rkt
stage1/init/common/path.go
IOMuxDir
func IOMuxDir(root string, appName types.ACName) string { return filepath.Join(common.Stage1RootfsPath(root), ioMuxDir, appName.String()) }
go
func IOMuxDir(root string, appName types.ACName) string { return filepath.Join(common.Stage1RootfsPath(root), ioMuxDir, appName.String()) }
[ "func", "IOMuxDir", "(", "root", "string", ",", "appName", "types", ".", "ACName", ")", "string", "{", "return", "filepath", ".", "Join", "(", "common", ".", "Stage1RootfsPath", "(", "root", ")", ",", "ioMuxDir", ",", "appName", ".", "String", "(", ")", ")", "\n", "}" ]
// IOMUxFilePath returns the path to the environment file for the given app name.
[ "IOMUxFilePath", "returns", "the", "path", "to", "the", "environment", "file", "for", "the", "given", "app", "name", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/path.go#L66-L68
167,201
rkt/rkt
stage1/init/common/path.go
ServiceWantPath
func ServiceWantPath(root string, appName types.ACName) string { return filepath.Join(common.Stage1RootfsPath(root), defaultWantsDir, ServiceUnitName(appName)) }
go
func ServiceWantPath(root string, appName types.ACName) string { return filepath.Join(common.Stage1RootfsPath(root), defaultWantsDir, ServiceUnitName(appName)) }
[ "func", "ServiceWantPath", "(", "root", "string", ",", "appName", "types", ".", "ACName", ")", "string", "{", "return", "filepath", ".", "Join", "(", "common", ".", "Stage1RootfsPath", "(", "root", ")", ",", "defaultWantsDir", ",", "ServiceUnitName", "(", "appName", ")", ")", "\n", "}" ]
// ServiceWantPath returns the systemd default.target want symlink path for the // given app name.
[ "ServiceWantPath", "returns", "the", "systemd", "default", ".", "target", "want", "symlink", "path", "for", "the", "given", "app", "name", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/path.go#L72-L74
167,202
rkt/rkt
stage1/init/common/path.go
InstantiatedPrepareAppUnitName
func InstantiatedPrepareAppUnitName(appName types.ACName) string { // Naming respecting escaping rules, see systemd.unit(5) and systemd-escape(1) escapedRoot := unit.UnitNamePathEscape(common.RelAppRootfsPath(appName)) return "prepare-app@-" + escapedRoot + ".service" }
go
func InstantiatedPrepareAppUnitName(appName types.ACName) string { // Naming respecting escaping rules, see systemd.unit(5) and systemd-escape(1) escapedRoot := unit.UnitNamePathEscape(common.RelAppRootfsPath(appName)) return "prepare-app@-" + escapedRoot + ".service" }
[ "func", "InstantiatedPrepareAppUnitName", "(", "appName", "types", ".", "ACName", ")", "string", "{", "// Naming respecting escaping rules, see systemd.unit(5) and systemd-escape(1)", "escapedRoot", ":=", "unit", ".", "UnitNamePathEscape", "(", "common", ".", "RelAppRootfsPath", "(", "appName", ")", ")", "\n", "return", "\"", "\"", "+", "escapedRoot", "+", "\"", "\"", "\n", "}" ]
// InstantiatedPrepareAppUnitName returns the systemd service unit name for prepare-app // instantiated for the given root.
[ "InstantiatedPrepareAppUnitName", "returns", "the", "systemd", "service", "unit", "name", "for", "prepare", "-", "app", "instantiated", "for", "the", "given", "root", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/path.go#L78-L82
167,203
rkt/rkt
stage1/init/common/path.go
SocketUnitPath
func SocketUnitPath(root string, appName types.ACName) string { return filepath.Join(common.Stage1RootfsPath(root), UnitsDir, SocketUnitName(appName)) }
go
func SocketUnitPath(root string, appName types.ACName) string { return filepath.Join(common.Stage1RootfsPath(root), UnitsDir, SocketUnitName(appName)) }
[ "func", "SocketUnitPath", "(", "root", "string", ",", "appName", "types", ".", "ACName", ")", "string", "{", "return", "filepath", ".", "Join", "(", "common", ".", "Stage1RootfsPath", "(", "root", ")", ",", "UnitsDir", ",", "SocketUnitName", "(", "appName", ")", ")", "\n", "}" ]
// SocketUnitPath returns the path to the systemd socket file for the given app name.
[ "SocketUnitPath", "returns", "the", "path", "to", "the", "systemd", "socket", "file", "for", "the", "given", "app", "name", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/path.go#L90-L92
167,204
rkt/rkt
stage1/init/common/path.go
SocketWantPath
func SocketWantPath(root string, appName types.ACName) string { return filepath.Join(common.Stage1RootfsPath(root), socketsWantsDir, SocketUnitName(appName)) }
go
func SocketWantPath(root string, appName types.ACName) string { return filepath.Join(common.Stage1RootfsPath(root), socketsWantsDir, SocketUnitName(appName)) }
[ "func", "SocketWantPath", "(", "root", "string", ",", "appName", "types", ".", "ACName", ")", "string", "{", "return", "filepath", ".", "Join", "(", "common", ".", "Stage1RootfsPath", "(", "root", ")", ",", "socketsWantsDir", ",", "SocketUnitName", "(", "appName", ")", ")", "\n", "}" ]
// SocketWantPath returns the systemd sockets.target.wants symlink path for the // given app name.
[ "SocketWantPath", "returns", "the", "systemd", "sockets", ".", "target", ".", "wants", "symlink", "path", "for", "the", "given", "app", "name", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/path.go#L96-L98
167,205
rkt/rkt
stage1/init/common/path.go
TypedUnitPath
func TypedUnitPath(root string, unitName string, unitType string) string { return filepath.Join(common.Stage1RootfsPath(root), UnitsDir, unitName+"."+unitType) }
go
func TypedUnitPath(root string, unitName string, unitType string) string { return filepath.Join(common.Stage1RootfsPath(root), UnitsDir, unitName+"."+unitType) }
[ "func", "TypedUnitPath", "(", "root", "string", ",", "unitName", "string", ",", "unitType", "string", ")", "string", "{", "return", "filepath", ".", "Join", "(", "common", ".", "Stage1RootfsPath", "(", "root", ")", ",", "UnitsDir", ",", "unitName", "+", "\"", "\"", "+", "unitType", ")", "\n", "}" ]
// TypedUnitPath returns the path to a custom-typed unit file
[ "TypedUnitPath", "returns", "the", "path", "to", "a", "custom", "-", "typed", "unit", "file" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/path.go#L101-L103
167,206
rkt/rkt
pkg/distribution/aciarchive.go
NewACIArchive
func NewACIArchive(u *url.URL) (Distribution, error) { c, err := parseCIMD(u) if err != nil { return nil, fmt.Errorf("cannot parse URI: %q: %v", u.String(), err) } if c.Type != TypeACIArchive { return nil, fmt.Errorf("illegal ACI archive distribution type: %q", c.Type) } // This should be a valid URL data, err := url.QueryUnescape(c.Data) if err != nil { return nil, errwrap.Wrap(fmt.Errorf("error unescaping url %q", c.Data), err) } aciu, err := url.Parse(data) if err != nil { return nil, errwrap.Wrap(fmt.Errorf("error parsing url %q", c.Data), err) } // save the URI as sorted to make it ready for comparison purell.NormalizeURL(u, purell.FlagSortQuery) str := u.String() if path := aciu.String(); filepath.Ext(path) == schema.ACIExtension { str = path } return &ACIArchive{ cimdURL: u, transportURL: aciu, str: str, }, nil }
go
func NewACIArchive(u *url.URL) (Distribution, error) { c, err := parseCIMD(u) if err != nil { return nil, fmt.Errorf("cannot parse URI: %q: %v", u.String(), err) } if c.Type != TypeACIArchive { return nil, fmt.Errorf("illegal ACI archive distribution type: %q", c.Type) } // This should be a valid URL data, err := url.QueryUnescape(c.Data) if err != nil { return nil, errwrap.Wrap(fmt.Errorf("error unescaping url %q", c.Data), err) } aciu, err := url.Parse(data) if err != nil { return nil, errwrap.Wrap(fmt.Errorf("error parsing url %q", c.Data), err) } // save the URI as sorted to make it ready for comparison purell.NormalizeURL(u, purell.FlagSortQuery) str := u.String() if path := aciu.String(); filepath.Ext(path) == schema.ACIExtension { str = path } return &ACIArchive{ cimdURL: u, transportURL: aciu, str: str, }, nil }
[ "func", "NewACIArchive", "(", "u", "*", "url", ".", "URL", ")", "(", "Distribution", ",", "error", ")", "{", "c", ",", "err", ":=", "parseCIMD", "(", "u", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ",", "err", ")", "\n", "}", "\n", "if", "c", ".", "Type", "!=", "TypeACIArchive", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "c", ".", "Type", ")", "\n", "}", "\n\n", "// This should be a valid URL", "data", ",", "err", ":=", "url", ".", "QueryUnescape", "(", "c", ".", "Data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "c", ".", "Data", ")", ",", "err", ")", "\n", "}", "\n", "aciu", ",", "err", ":=", "url", ".", "Parse", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "c", ".", "Data", ")", ",", "err", ")", "\n", "}", "\n\n", "// save the URI as sorted to make it ready for comparison", "purell", ".", "NormalizeURL", "(", "u", ",", "purell", ".", "FlagSortQuery", ")", "\n\n", "str", ":=", "u", ".", "String", "(", ")", "\n", "if", "path", ":=", "aciu", ".", "String", "(", ")", ";", "filepath", ".", "Ext", "(", "path", ")", "==", "schema", ".", "ACIExtension", "{", "str", "=", "path", "\n", "}", "\n\n", "return", "&", "ACIArchive", "{", "cimdURL", ":", "u", ",", "transportURL", ":", "aciu", ",", "str", ":", "str", ",", "}", ",", "nil", "\n", "}" ]
// NewACIArchive creates a new aci-archive distribution from the provided distribution uri.
[ "NewACIArchive", "creates", "a", "new", "aci", "-", "archive", "distribution", "from", "the", "provided", "distribution", "uri", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/distribution/aciarchive.go#L54-L86
167,207
rkt/rkt
pkg/distribution/aciarchive.go
TransportURL
func (a *ACIArchive) TransportURL() *url.URL { // Create a copy of the transport URL tu, err := url.Parse(a.transportURL.String()) if err != nil { panic(fmt.Errorf("invalid transport URL: %v", err)) } return tu }
go
func (a *ACIArchive) TransportURL() *url.URL { // Create a copy of the transport URL tu, err := url.Parse(a.transportURL.String()) if err != nil { panic(fmt.Errorf("invalid transport URL: %v", err)) } return tu }
[ "func", "(", "a", "*", "ACIArchive", ")", "TransportURL", "(", ")", "*", "url", ".", "URL", "{", "// Create a copy of the transport URL", "tu", ",", "err", ":=", "url", ".", "Parse", "(", "a", ".", "transportURL", ".", "String", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", ")", "\n", "}", "\n\n", "return", "tu", "\n", "}" ]
// TransportURL returns a copy of the transport URL.
[ "TransportURL", "returns", "a", "copy", "of", "the", "transport", "URL", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/distribution/aciarchive.go#L122-L130
167,208
rkt/rkt
stage0/gc.go
MountGC
func MountGC(path, uuid string) error { err := common.ChrootPrivateUnmount(path, log, debug) if err != nil { return errwrap.Wrap(fmt.Errorf("error cleaning mounts for pod %s", uuid), err) } return nil }
go
func MountGC(path, uuid string) error { err := common.ChrootPrivateUnmount(path, log, debug) if err != nil { return errwrap.Wrap(fmt.Errorf("error cleaning mounts for pod %s", uuid), err) } return nil }
[ "func", "MountGC", "(", "path", ",", "uuid", "string", ")", "error", "{", "err", ":=", "common", ".", "ChrootPrivateUnmount", "(", "path", ",", "log", ",", "debug", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "uuid", ")", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// MountGC removes mounts from pods that couldn't be GCed cleanly.
[ "MountGC", "removes", "mounts", "from", "pods", "that", "couldn", "t", "be", "GCed", "cleanly", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage0/gc.go#L71-L77
167,209
rkt/rkt
pkg/pod/uuid.go
matchUUID
func matchUUID(dataDir, uuid string) ([]string, error) { if uuid == "" { return nil, types.ErrNoEmptyUUID } ls, err := listPods(dataDir, IncludeMostDirs) if err != nil { return nil, err } var matches []string for _, p := range ls { if strings.HasPrefix(p, uuid) { matches = append(matches, p) } } return matches, nil }
go
func matchUUID(dataDir, uuid string) ([]string, error) { if uuid == "" { return nil, types.ErrNoEmptyUUID } ls, err := listPods(dataDir, IncludeMostDirs) if err != nil { return nil, err } var matches []string for _, p := range ls { if strings.HasPrefix(p, uuid) { matches = append(matches, p) } } return matches, nil }
[ "func", "matchUUID", "(", "dataDir", ",", "uuid", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "uuid", "==", "\"", "\"", "{", "return", "nil", ",", "types", ".", "ErrNoEmptyUUID", "\n", "}", "\n\n", "ls", ",", "err", ":=", "listPods", "(", "dataDir", ",", "IncludeMostDirs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "matches", "[", "]", "string", "\n", "for", "_", ",", "p", ":=", "range", "ls", "{", "if", "strings", ".", "HasPrefix", "(", "p", ",", "uuid", ")", "{", "matches", "=", "append", "(", "matches", ",", "p", ")", "\n", "}", "\n", "}", "\n\n", "return", "matches", ",", "nil", "\n", "}" ]
// matchUUID attempts to match the uuid specified as uuid against all pods present. // An array of matches is returned, which may be empty when nothing matches.
[ "matchUUID", "attempts", "to", "match", "the", "uuid", "specified", "as", "uuid", "against", "all", "pods", "present", ".", "An", "array", "of", "matches", "is", "returned", "which", "may", "be", "empty", "when", "nothing", "matches", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/uuid.go#L30-L48
167,210
rkt/rkt
pkg/pod/uuid.go
resolveUUID
func resolveUUID(dataDir, uuid string) (*types.UUID, error) { uuid = strings.ToLower(uuid) m, err := matchUUID(dataDir, uuid) if err != nil { return nil, err } if len(m) == 0 { return nil, fmt.Errorf("no matches found for %q", uuid) } if len(m) > 1 { return nil, fmt.Errorf("ambiguous uuid, %d matches", len(m)) } u, err := types.NewUUID(m[0]) if err != nil { return nil, errwrap.Wrap(errors.New("invalid UUID"), err) } return u, nil }
go
func resolveUUID(dataDir, uuid string) (*types.UUID, error) { uuid = strings.ToLower(uuid) m, err := matchUUID(dataDir, uuid) if err != nil { return nil, err } if len(m) == 0 { return nil, fmt.Errorf("no matches found for %q", uuid) } if len(m) > 1 { return nil, fmt.Errorf("ambiguous uuid, %d matches", len(m)) } u, err := types.NewUUID(m[0]) if err != nil { return nil, errwrap.Wrap(errors.New("invalid UUID"), err) } return u, nil }
[ "func", "resolveUUID", "(", "dataDir", ",", "uuid", "string", ")", "(", "*", "types", ".", "UUID", ",", "error", ")", "{", "uuid", "=", "strings", ".", "ToLower", "(", "uuid", ")", "\n", "m", ",", "err", ":=", "matchUUID", "(", "dataDir", ",", "uuid", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "m", ")", "==", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "uuid", ")", "\n", "}", "\n\n", "if", "len", "(", "m", ")", ">", "1", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "m", ")", ")", "\n", "}", "\n\n", "u", ",", "err", ":=", "types", ".", "NewUUID", "(", "m", "[", "0", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "return", "u", ",", "nil", "\n", "}" ]
// resolveUUID attempts to resolve the uuid specified as uuid against all pods present. // An unambiguously matched uuid or nil is returned.
[ "resolveUUID", "attempts", "to", "resolve", "the", "uuid", "specified", "as", "uuid", "against", "all", "pods", "present", ".", "An", "unambiguously", "matched", "uuid", "or", "nil", "is", "returned", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/uuid.go#L52-L73
167,211
rkt/rkt
pkg/pod/uuid.go
ReadUUIDFromFile
func ReadUUIDFromFile(path string) (string, error) { uuid, err := ioutil.ReadFile(path) if err != nil { return "", err } return string(bytes.TrimSpace(uuid)), nil }
go
func ReadUUIDFromFile(path string) (string, error) { uuid, err := ioutil.ReadFile(path) if err != nil { return "", err } return string(bytes.TrimSpace(uuid)), nil }
[ "func", "ReadUUIDFromFile", "(", "path", "string", ")", "(", "string", ",", "error", ")", "{", "uuid", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "string", "(", "bytes", ".", "TrimSpace", "(", "uuid", ")", ")", ",", "nil", "\n", "}" ]
// ReadUUIDFromFile reads the uuid string from the given path.
[ "ReadUUIDFromFile", "reads", "the", "uuid", "string", "from", "the", "given", "path", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/uuid.go#L76-L82
167,212
rkt/rkt
pkg/pod/uuid.go
WriteUUIDToFile
func WriteUUIDToFile(uuid *types.UUID, path string) error { return ioutil.WriteFile(path, []byte(uuid.String()), 0644) }
go
func WriteUUIDToFile(uuid *types.UUID, path string) error { return ioutil.WriteFile(path, []byte(uuid.String()), 0644) }
[ "func", "WriteUUIDToFile", "(", "uuid", "*", "types", ".", "UUID", ",", "path", "string", ")", "error", "{", "return", "ioutil", ".", "WriteFile", "(", "path", ",", "[", "]", "byte", "(", "uuid", ".", "String", "(", ")", ")", ",", "0644", ")", "\n", "}" ]
// WriteUUIDToFile writes the uuid string to the given path.
[ "WriteUUIDToFile", "writes", "the", "uuid", "string", "to", "the", "given", "path", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/uuid.go#L85-L87
167,213
rkt/rkt
networking/networking.go
Setup
func Setup(podRoot string, podID types.UUID, fps []commonnet.ForwardedPort, netList common.NetList, localConfig, flavor string, noDNS, debug bool) (*Networking, error) { stderr = log.New(os.Stderr, "networking", debug) debuglog = debug if flavor == "kvm" { return kvmSetup(podRoot, podID, fps, netList, localConfig, noDNS) } // TODO(jonboulle): currently podRoot is _always_ ".", and behaviour in other // circumstances is untested. This should be cleaned up. n := Networking{ podEnv: podEnv{ podRoot: podRoot, podID: podID, netsLoadList: netList, localConfig: localConfig, }, } err := n.mountNetnsDirectory() if err != nil { return nil, err } // Create the network namespace (and save its name in a file) err = n.podNSCreate() if err != nil { return nil, err } n.nets, err = n.loadNets() if err != nil { return nil, errwrap.Wrap(errors.New("error loading network definitions"), err) } if err := n.setupNets(n.nets, noDNS); err != nil { return nil, err } if len(fps) > 0 { if err = n.enableDefaultLocalnetRouting(); err != nil { return nil, err } podIP, err := n.GetForwardableNetPodIP() if err != nil { return nil, err } if err := n.setupForwarding(); err != nil { n.teardownForwarding() return nil, err } if err := n.forwardPorts(fps, podIP); err != nil { n.teardownForwarding() return nil, err } } // Switch to the podNS if err := n.podNS.Set(); err != nil { return nil, err } if err = loUp(); err != nil { return nil, err } return &n, nil }
go
func Setup(podRoot string, podID types.UUID, fps []commonnet.ForwardedPort, netList common.NetList, localConfig, flavor string, noDNS, debug bool) (*Networking, error) { stderr = log.New(os.Stderr, "networking", debug) debuglog = debug if flavor == "kvm" { return kvmSetup(podRoot, podID, fps, netList, localConfig, noDNS) } // TODO(jonboulle): currently podRoot is _always_ ".", and behaviour in other // circumstances is untested. This should be cleaned up. n := Networking{ podEnv: podEnv{ podRoot: podRoot, podID: podID, netsLoadList: netList, localConfig: localConfig, }, } err := n.mountNetnsDirectory() if err != nil { return nil, err } // Create the network namespace (and save its name in a file) err = n.podNSCreate() if err != nil { return nil, err } n.nets, err = n.loadNets() if err != nil { return nil, errwrap.Wrap(errors.New("error loading network definitions"), err) } if err := n.setupNets(n.nets, noDNS); err != nil { return nil, err } if len(fps) > 0 { if err = n.enableDefaultLocalnetRouting(); err != nil { return nil, err } podIP, err := n.GetForwardableNetPodIP() if err != nil { return nil, err } if err := n.setupForwarding(); err != nil { n.teardownForwarding() return nil, err } if err := n.forwardPorts(fps, podIP); err != nil { n.teardownForwarding() return nil, err } } // Switch to the podNS if err := n.podNS.Set(); err != nil { return nil, err } if err = loUp(); err != nil { return nil, err } return &n, nil }
[ "func", "Setup", "(", "podRoot", "string", ",", "podID", "types", ".", "UUID", ",", "fps", "[", "]", "commonnet", ".", "ForwardedPort", ",", "netList", "common", ".", "NetList", ",", "localConfig", ",", "flavor", "string", ",", "noDNS", ",", "debug", "bool", ")", "(", "*", "Networking", ",", "error", ")", "{", "stderr", "=", "log", ".", "New", "(", "os", ".", "Stderr", ",", "\"", "\"", ",", "debug", ")", "\n", "debuglog", "=", "debug", "\n\n", "if", "flavor", "==", "\"", "\"", "{", "return", "kvmSetup", "(", "podRoot", ",", "podID", ",", "fps", ",", "netList", ",", "localConfig", ",", "noDNS", ")", "\n", "}", "\n\n", "// TODO(jonboulle): currently podRoot is _always_ \".\", and behaviour in other", "// circumstances is untested. This should be cleaned up.", "n", ":=", "Networking", "{", "podEnv", ":", "podEnv", "{", "podRoot", ":", "podRoot", ",", "podID", ":", "podID", ",", "netsLoadList", ":", "netList", ",", "localConfig", ":", "localConfig", ",", "}", ",", "}", "\n\n", "err", ":=", "n", ".", "mountNetnsDirectory", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Create the network namespace (and save its name in a file)", "err", "=", "n", ".", "podNSCreate", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "n", ".", "nets", ",", "err", "=", "n", ".", "loadNets", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "n", ".", "setupNets", "(", "n", ".", "nets", ",", "noDNS", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "fps", ")", ">", "0", "{", "if", "err", "=", "n", ".", "enableDefaultLocalnetRouting", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "podIP", ",", "err", ":=", "n", ".", "GetForwardableNetPodIP", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "n", ".", "setupForwarding", "(", ")", ";", "err", "!=", "nil", "{", "n", ".", "teardownForwarding", "(", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "n", ".", "forwardPorts", "(", "fps", ",", "podIP", ")", ";", "err", "!=", "nil", "{", "n", ".", "teardownForwarding", "(", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "// Switch to the podNS", "if", "err", ":=", "n", ".", "podNS", ".", "Set", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", "=", "loUp", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "n", ",", "nil", "\n", "}" ]
// Setup creates a new networking namespace and executes network plugins to // set up networking. It returns in the new pod namespace
[ "Setup", "creates", "a", "new", "networking", "namespace", "and", "executes", "network", "plugins", "to", "set", "up", "networking", ".", "It", "returns", "in", "the", "new", "pod", "namespace" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/networking.go#L67-L135
167,214
rkt/rkt
networking/networking.go
enableDefaultLocalnetRouting
func (n *Networking) enableDefaultLocalnetRouting() error { routeLocalnetFormat := "" defaultHostIP, err := n.GetForwardableNetHostIP() if err != nil { return err } defaultHostIPstring := defaultHostIP.String() switch { case strings.Contains(defaultHostIPstring, "."): routeLocalnetFormat = "/proc/sys/net/ipv4/conf/%s/route_localnet" case strings.Contains(defaultHostIPstring, ":"): return fmt.Errorf("unexpected IPv6 Address returned for default host interface: %q", defaultHostIPstring) default: return fmt.Errorf("unknown type for default Host IP: %q", defaultHostIPstring) } hostIfaces, err := n.GetIfacesByIP(defaultHostIP) if err != nil { return err } for _, hostIface := range hostIfaces { routeLocalnetPath := fmt.Sprintf(routeLocalnetFormat, hostIface.Name) routeLocalnetValue, err := ioutil.ReadFile(routeLocalnetPath) if err != nil { return err } if strings.TrimSpace(string(routeLocalnetValue)) != "1" { routeLocalnetFile, err := os.OpenFile(routeLocalnetPath, os.O_WRONLY, 0) if err != nil { return err } defer routeLocalnetFile.Close() if _, err = io.WriteString(routeLocalnetFile, "1"); err != nil { return err } } } return nil }
go
func (n *Networking) enableDefaultLocalnetRouting() error { routeLocalnetFormat := "" defaultHostIP, err := n.GetForwardableNetHostIP() if err != nil { return err } defaultHostIPstring := defaultHostIP.String() switch { case strings.Contains(defaultHostIPstring, "."): routeLocalnetFormat = "/proc/sys/net/ipv4/conf/%s/route_localnet" case strings.Contains(defaultHostIPstring, ":"): return fmt.Errorf("unexpected IPv6 Address returned for default host interface: %q", defaultHostIPstring) default: return fmt.Errorf("unknown type for default Host IP: %q", defaultHostIPstring) } hostIfaces, err := n.GetIfacesByIP(defaultHostIP) if err != nil { return err } for _, hostIface := range hostIfaces { routeLocalnetPath := fmt.Sprintf(routeLocalnetFormat, hostIface.Name) routeLocalnetValue, err := ioutil.ReadFile(routeLocalnetPath) if err != nil { return err } if strings.TrimSpace(string(routeLocalnetValue)) != "1" { routeLocalnetFile, err := os.OpenFile(routeLocalnetPath, os.O_WRONLY, 0) if err != nil { return err } defer routeLocalnetFile.Close() if _, err = io.WriteString(routeLocalnetFile, "1"); err != nil { return err } } } return nil }
[ "func", "(", "n", "*", "Networking", ")", "enableDefaultLocalnetRouting", "(", ")", "error", "{", "routeLocalnetFormat", ":=", "\"", "\"", "\n\n", "defaultHostIP", ",", "err", ":=", "n", ".", "GetForwardableNetHostIP", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "defaultHostIPstring", ":=", "defaultHostIP", ".", "String", "(", ")", "\n", "switch", "{", "case", "strings", ".", "Contains", "(", "defaultHostIPstring", ",", "\"", "\"", ")", ":", "routeLocalnetFormat", "=", "\"", "\"", "\n", "case", "strings", ".", "Contains", "(", "defaultHostIPstring", ",", "\"", "\"", ")", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "defaultHostIPstring", ")", "\n", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "defaultHostIPstring", ")", "\n", "}", "\n\n", "hostIfaces", ",", "err", ":=", "n", ".", "GetIfacesByIP", "(", "defaultHostIP", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "for", "_", ",", "hostIface", ":=", "range", "hostIfaces", "{", "routeLocalnetPath", ":=", "fmt", ".", "Sprintf", "(", "routeLocalnetFormat", ",", "hostIface", ".", "Name", ")", "\n", "routeLocalnetValue", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "routeLocalnetPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "strings", ".", "TrimSpace", "(", "string", "(", "routeLocalnetValue", ")", ")", "!=", "\"", "\"", "{", "routeLocalnetFile", ",", "err", ":=", "os", ".", "OpenFile", "(", "routeLocalnetPath", ",", "os", ".", "O_WRONLY", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "routeLocalnetFile", ".", "Close", "(", ")", "\n\n", "if", "_", ",", "err", "=", "io", ".", "WriteString", "(", "routeLocalnetFile", ",", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// enableDefaultLocalnetRouting enables the route_localnet attribute on the supposedly default network interface. // This allows setting up loopback NAT so the host can access the pod's forwarded ports on the localhost address.
[ "enableDefaultLocalnetRouting", "enables", "the", "route_localnet", "attribute", "on", "the", "supposedly", "default", "network", "interface", ".", "This", "allows", "setting", "up", "loopback", "NAT", "so", "the", "host", "can", "access", "the", "pod", "s", "forwarded", "ports", "on", "the", "localhost", "address", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/networking.go#L139-L182
167,215
rkt/rkt
networking/networking.go
Load
func Load(podRoot string, podID *types.UUID, localConfig string) (*Networking, error) { // the current directory is pod root pdirfd, err := syscall.Open(podRoot, syscall.O_RDONLY|syscall.O_DIRECTORY, 0) if err != nil { return nil, errwrap.Wrap(fmt.Errorf("failed to open pod root directory (%v)", podRoot), err) } defer syscall.Close(pdirfd) nis, err := netinfo.LoadAt(pdirfd) if err != nil { return nil, err } var nets []activeNet for _, ni := range nis { n, err := loadNet(ni.ConfPath) if err != nil { if !os.IsNotExist(err) { stderr.PrintE(fmt.Sprintf("error loading %q; ignoring", ni.ConfPath), err) } continue } // make a copy of ni to make it a unique object as it's saved via ptr rti := ni n.runtime = &rti nets = append(nets, *n) } p := podEnv{ podRoot: podRoot, podID: *podID, localConfig: localConfig, } err = p.podNSLoad() if err != nil { return nil, err } return &Networking{ podEnv: p, nets: nets, }, nil }
go
func Load(podRoot string, podID *types.UUID, localConfig string) (*Networking, error) { // the current directory is pod root pdirfd, err := syscall.Open(podRoot, syscall.O_RDONLY|syscall.O_DIRECTORY, 0) if err != nil { return nil, errwrap.Wrap(fmt.Errorf("failed to open pod root directory (%v)", podRoot), err) } defer syscall.Close(pdirfd) nis, err := netinfo.LoadAt(pdirfd) if err != nil { return nil, err } var nets []activeNet for _, ni := range nis { n, err := loadNet(ni.ConfPath) if err != nil { if !os.IsNotExist(err) { stderr.PrintE(fmt.Sprintf("error loading %q; ignoring", ni.ConfPath), err) } continue } // make a copy of ni to make it a unique object as it's saved via ptr rti := ni n.runtime = &rti nets = append(nets, *n) } p := podEnv{ podRoot: podRoot, podID: *podID, localConfig: localConfig, } err = p.podNSLoad() if err != nil { return nil, err } return &Networking{ podEnv: p, nets: nets, }, nil }
[ "func", "Load", "(", "podRoot", "string", ",", "podID", "*", "types", ".", "UUID", ",", "localConfig", "string", ")", "(", "*", "Networking", ",", "error", ")", "{", "// the current directory is pod root", "pdirfd", ",", "err", ":=", "syscall", ".", "Open", "(", "podRoot", ",", "syscall", ".", "O_RDONLY", "|", "syscall", ".", "O_DIRECTORY", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "podRoot", ")", ",", "err", ")", "\n", "}", "\n", "defer", "syscall", ".", "Close", "(", "pdirfd", ")", "\n\n", "nis", ",", "err", ":=", "netinfo", ".", "LoadAt", "(", "pdirfd", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "nets", "[", "]", "activeNet", "\n", "for", "_", ",", "ni", ":=", "range", "nis", "{", "n", ",", "err", ":=", "loadNet", "(", "ni", ".", "ConfPath", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "stderr", ".", "PrintE", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ni", ".", "ConfPath", ")", ",", "err", ")", "\n", "}", "\n", "continue", "\n", "}", "\n\n", "// make a copy of ni to make it a unique object as it's saved via ptr", "rti", ":=", "ni", "\n", "n", ".", "runtime", "=", "&", "rti", "\n", "nets", "=", "append", "(", "nets", ",", "*", "n", ")", "\n", "}", "\n\n", "p", ":=", "podEnv", "{", "podRoot", ":", "podRoot", ",", "podID", ":", "*", "podID", ",", "localConfig", ":", "localConfig", ",", "}", "\n\n", "err", "=", "p", ".", "podNSLoad", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "Networking", "{", "podEnv", ":", "p", ",", "nets", ":", "nets", ",", "}", ",", "nil", "\n", "}" ]
// Load creates the Networking object from saved state. // Assumes the current netns is that of the host.
[ "Load", "creates", "the", "Networking", "object", "from", "saved", "state", ".", "Assumes", "the", "current", "netns", "is", "that", "of", "the", "host", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/networking.go#L186-L230
167,216
rkt/rkt
networking/networking.go
GetIfacesByIP
func (n *Networking) GetIfacesByIP(ifaceIP net.IP) ([]net.Interface, error) { ifaces, err := net.Interfaces() if err != nil { return nil, err } searchAddr := strings.Split(ifaceIP.String(), "/")[0] resultInterfaces := make([]net.Interface, 0) for _, iface := range ifaces { if iface.Flags&net.FlagLoopback != 0 { continue } addrs, err := iface.Addrs() if err != nil { return nil, errwrap.Wrap(fmt.Errorf("cannot get addresses for interface %v", iface.Name), err) } for _, addr := range addrs { currentAddr := strings.Split(addr.String(), "/")[0] if searchAddr == currentAddr { resultInterfaces = append(resultInterfaces, iface) break } } } if len(resultInterfaces) == 0 { return nil, fmt.Errorf("no interface found with IP %q", ifaceIP) } return resultInterfaces, nil }
go
func (n *Networking) GetIfacesByIP(ifaceIP net.IP) ([]net.Interface, error) { ifaces, err := net.Interfaces() if err != nil { return nil, err } searchAddr := strings.Split(ifaceIP.String(), "/")[0] resultInterfaces := make([]net.Interface, 0) for _, iface := range ifaces { if iface.Flags&net.FlagLoopback != 0 { continue } addrs, err := iface.Addrs() if err != nil { return nil, errwrap.Wrap(fmt.Errorf("cannot get addresses for interface %v", iface.Name), err) } for _, addr := range addrs { currentAddr := strings.Split(addr.String(), "/")[0] if searchAddr == currentAddr { resultInterfaces = append(resultInterfaces, iface) break } } } if len(resultInterfaces) == 0 { return nil, fmt.Errorf("no interface found with IP %q", ifaceIP) } return resultInterfaces, nil }
[ "func", "(", "n", "*", "Networking", ")", "GetIfacesByIP", "(", "ifaceIP", "net", ".", "IP", ")", "(", "[", "]", "net", ".", "Interface", ",", "error", ")", "{", "ifaces", ",", "err", ":=", "net", ".", "Interfaces", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "searchAddr", ":=", "strings", ".", "Split", "(", "ifaceIP", ".", "String", "(", ")", ",", "\"", "\"", ")", "[", "0", "]", "\n", "resultInterfaces", ":=", "make", "(", "[", "]", "net", ".", "Interface", ",", "0", ")", "\n\n", "for", "_", ",", "iface", ":=", "range", "ifaces", "{", "if", "iface", ".", "Flags", "&", "net", ".", "FlagLoopback", "!=", "0", "{", "continue", "\n", "}", "\n\n", "addrs", ",", "err", ":=", "iface", ".", "Addrs", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "iface", ".", "Name", ")", ",", "err", ")", "\n", "}", "\n\n", "for", "_", ",", "addr", ":=", "range", "addrs", "{", "currentAddr", ":=", "strings", ".", "Split", "(", "addr", ".", "String", "(", ")", ",", "\"", "\"", ")", "[", "0", "]", "\n", "if", "searchAddr", "==", "currentAddr", "{", "resultInterfaces", "=", "append", "(", "resultInterfaces", ",", "iface", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "resultInterfaces", ")", "==", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ifaceIP", ")", "\n", "}", "\n\n", "return", "resultInterfaces", ",", "nil", "\n", "}" ]
// GetIfacesByIP searches for and returns the interfaces with the given IP // Disregards the subnet mask since not every net.IP object contains // On success it will return the list of found interfaces
[ "GetIfacesByIP", "searches", "for", "and", "returns", "the", "interfaces", "with", "the", "given", "IP", "Disregards", "the", "subnet", "mask", "since", "not", "every", "net", ".", "IP", "object", "contains", "On", "success", "it", "will", "return", "the", "list", "of", "found", "interfaces" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/networking.go#L235-L268
167,217
rkt/rkt
networking/networking.go
Teardown
func (n *Networking) Teardown(flavor string, debug bool) { stderr = log.New(os.Stderr, "networking", debug) debuglog = debug // Teardown everything in reverse order of setup. // This should be idempotent -- be tolerant of missing stuff if flavor == "kvm" { n.kvmTeardown() return } if err := n.teardownForwarding(); err != nil { stderr.PrintE("error removing forwarded ports", err) } err := n.podNSLoad() if err != nil { stderr.PrintE("error loading podNS", err) } n.teardownNets(n.nets) n.podNSDestroy() }
go
func (n *Networking) Teardown(flavor string, debug bool) { stderr = log.New(os.Stderr, "networking", debug) debuglog = debug // Teardown everything in reverse order of setup. // This should be idempotent -- be tolerant of missing stuff if flavor == "kvm" { n.kvmTeardown() return } if err := n.teardownForwarding(); err != nil { stderr.PrintE("error removing forwarded ports", err) } err := n.podNSLoad() if err != nil { stderr.PrintE("error loading podNS", err) } n.teardownNets(n.nets) n.podNSDestroy() }
[ "func", "(", "n", "*", "Networking", ")", "Teardown", "(", "flavor", "string", ",", "debug", "bool", ")", "{", "stderr", "=", "log", ".", "New", "(", "os", ".", "Stderr", ",", "\"", "\"", ",", "debug", ")", "\n", "debuglog", "=", "debug", "\n\n", "// Teardown everything in reverse order of setup.", "// This should be idempotent -- be tolerant of missing stuff", "if", "flavor", "==", "\"", "\"", "{", "n", ".", "kvmTeardown", "(", ")", "\n", "return", "\n", "}", "\n\n", "if", "err", ":=", "n", ".", "teardownForwarding", "(", ")", ";", "err", "!=", "nil", "{", "stderr", ".", "PrintE", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "err", ":=", "n", ".", "podNSLoad", "(", ")", "\n", "if", "err", "!=", "nil", "{", "stderr", ".", "PrintE", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "n", ".", "teardownNets", "(", "n", ".", "nets", ")", "\n", "n", ".", "podNSDestroy", "(", ")", "\n", "}" ]
// Teardown cleans up a produced Networking object.
[ "Teardown", "cleans", "up", "a", "produced", "Networking", "object", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/networking.go#L271-L295
167,218
rkt/rkt
networking/networking.go
Save
func (e *Networking) Save() error { if e.podNS != nil { if err := e.podNSPathSave(); err != nil { return err } } var nis []netinfo.NetInfo for _, n := range e.nets { nis = append(nis, *n.runtime) } return netinfo.Save(e.podRoot, nis) }
go
func (e *Networking) Save() error { if e.podNS != nil { if err := e.podNSPathSave(); err != nil { return err } } var nis []netinfo.NetInfo for _, n := range e.nets { nis = append(nis, *n.runtime) } return netinfo.Save(e.podRoot, nis) }
[ "func", "(", "e", "*", "Networking", ")", "Save", "(", ")", "error", "{", "if", "e", ".", "podNS", "!=", "nil", "{", "if", "err", ":=", "e", ".", "podNSPathSave", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "var", "nis", "[", "]", "netinfo", ".", "NetInfo", "\n", "for", "_", ",", "n", ":=", "range", "e", ".", "nets", "{", "nis", "=", "append", "(", "nis", ",", "*", "n", ".", "runtime", ")", "\n", "}", "\n\n", "return", "netinfo", ".", "Save", "(", "e", ".", "podRoot", ",", "nis", ")", "\n", "}" ]
// Save writes out the info about active nets // for "rkt list" and friends to display
[ "Save", "writes", "out", "the", "info", "about", "active", "nets", "for", "rkt", "list", "and", "friends", "to", "display" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/networking.go#L299-L313
167,219
rkt/rkt
networking/networking.go
CleanUpGarbage
func CleanUpGarbage(podRoot string, podID *types.UUID) error { p := podEnv{ podRoot: podRoot, podID: *podID, } err := p.podNSLoad() if err != nil { return err } return p.podNSDestroy() }
go
func CleanUpGarbage(podRoot string, podID *types.UUID) error { p := podEnv{ podRoot: podRoot, podID: *podID, } err := p.podNSLoad() if err != nil { return err } return p.podNSDestroy() }
[ "func", "CleanUpGarbage", "(", "podRoot", "string", ",", "podID", "*", "types", ".", "UUID", ")", "error", "{", "p", ":=", "podEnv", "{", "podRoot", ":", "podRoot", ",", "podID", ":", "*", "podID", ",", "}", "\n\n", "err", ":=", "p", ".", "podNSLoad", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "p", ".", "podNSDestroy", "(", ")", "\n", "}" ]
// CleanUpGarbage can be called when Load fails, but there may still // be some garbage lying around. Right now, this deletes the namespace.
[ "CleanUpGarbage", "can", "be", "called", "when", "Load", "fails", "but", "there", "may", "still", "be", "some", "garbage", "lying", "around", ".", "Right", "now", "this", "deletes", "the", "namespace", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/networking.go#L317-L328
167,220
rkt/rkt
rkt/image/asc.go
Get
func (a *asc) Get() (readSeekCloser, error) { if a.Fetcher != nil { return a.Fetcher.Get(a.Location) } return NopReadSeekCloser(nil), nil }
go
func (a *asc) Get() (readSeekCloser, error) { if a.Fetcher != nil { return a.Fetcher.Get(a.Location) } return NopReadSeekCloser(nil), nil }
[ "func", "(", "a", "*", "asc", ")", "Get", "(", ")", "(", "readSeekCloser", ",", "error", ")", "{", "if", "a", ".", "Fetcher", "!=", "nil", "{", "return", "a", ".", "Fetcher", ".", "Get", "(", "a", ".", "Location", ")", "\n", "}", "\n", "return", "NopReadSeekCloser", "(", "nil", ")", ",", "nil", "\n", "}" ]
// Get fetches a signature file. It returns nil and no error if there // was no fetcher set.
[ "Get", "fetches", "a", "signature", "file", ".", "It", "returns", "nil", "and", "no", "error", "if", "there", "was", "no", "fetcher", "set", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/asc.go#L89-L94
167,221
rkt/rkt
rkt/image/finder.go
FindImages
func (f *Finder) FindImages(al *apps.Apps) error { return al.Walk(func(app *apps.App) error { h, err := f.FindImage(app.Image, app.Asc) if err != nil { return err } app.ImageID = *h return nil }) }
go
func (f *Finder) FindImages(al *apps.Apps) error { return al.Walk(func(app *apps.App) error { h, err := f.FindImage(app.Image, app.Asc) if err != nil { return err } app.ImageID = *h return nil }) }
[ "func", "(", "f", "*", "Finder", ")", "FindImages", "(", "al", "*", "apps", ".", "Apps", ")", "error", "{", "return", "al", ".", "Walk", "(", "func", "(", "app", "*", "apps", ".", "App", ")", "error", "{", "h", ",", "err", ":=", "f", ".", "FindImage", "(", "app", ".", "Image", ",", "app", ".", "Asc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "app", ".", "ImageID", "=", "*", "h", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// FindImages uses FindImage to attain a list of image hashes
[ "FindImages", "uses", "FindImage", "to", "attain", "a", "list", "of", "image", "hashes" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/finder.go#L31-L40
167,222
rkt/rkt
rkt/image/finder.go
FindImage
func (f *Finder) FindImage(img string, asc string) (*types.Hash, error) { ensureLogger(f.Debug) // Check if it's an hash if _, err := types.NewHash(img); err == nil { h, err := f.getHashFromStore(img) if err != nil { return nil, err } return h, nil } d, err := DistFromImageString(img) if err != nil { return nil, err } // urls, names, paths have to be fetched, potentially remotely ft := (*Fetcher)(f) h, err := ft.FetchImage(d, img, asc) if err != nil { return nil, err } return h, nil }
go
func (f *Finder) FindImage(img string, asc string) (*types.Hash, error) { ensureLogger(f.Debug) // Check if it's an hash if _, err := types.NewHash(img); err == nil { h, err := f.getHashFromStore(img) if err != nil { return nil, err } return h, nil } d, err := DistFromImageString(img) if err != nil { return nil, err } // urls, names, paths have to be fetched, potentially remotely ft := (*Fetcher)(f) h, err := ft.FetchImage(d, img, asc) if err != nil { return nil, err } return h, nil }
[ "func", "(", "f", "*", "Finder", ")", "FindImage", "(", "img", "string", ",", "asc", "string", ")", "(", "*", "types", ".", "Hash", ",", "error", ")", "{", "ensureLogger", "(", "f", ".", "Debug", ")", "\n\n", "// Check if it's an hash", "if", "_", ",", "err", ":=", "types", ".", "NewHash", "(", "img", ")", ";", "err", "==", "nil", "{", "h", ",", "err", ":=", "f", ".", "getHashFromStore", "(", "img", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "h", ",", "nil", "\n", "}", "\n\n", "d", ",", "err", ":=", "DistFromImageString", "(", "img", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// urls, names, paths have to be fetched, potentially remotely", "ft", ":=", "(", "*", "Fetcher", ")", "(", "f", ")", "\n", "h", ",", "err", ":=", "ft", ".", "FetchImage", "(", "d", ",", "img", ",", "asc", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "h", ",", "nil", "\n", "}" ]
// FindImage tries to get a hash of a passed image, ideally from // store. Otherwise this might involve fetching it from remote with // the Fetcher.
[ "FindImage", "tries", "to", "get", "a", "hash", "of", "a", "passed", "image", "ideally", "from", "store", ".", "Otherwise", "this", "might", "involve", "fetching", "it", "from", "remote", "with", "the", "Fetcher", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/finder.go#L45-L69
167,223
rkt/rkt
stage1/common/ssh/ssh.go
fileAccessible
func fileAccessible(path string) bool { if info, err := os.Stat(path); err == nil { return info.Mode().IsRegular() } return false }
go
func fileAccessible(path string) bool { if info, err := os.Stat(path); err == nil { return info.Mode().IsRegular() } return false }
[ "func", "fileAccessible", "(", "path", "string", ")", "bool", "{", "if", "info", ",", "err", ":=", "os", ".", "Stat", "(", "path", ")", ";", "err", "==", "nil", "{", "return", "info", ".", "Mode", "(", ")", ".", "IsRegular", "(", ")", "\n", "}", "\n", "return", "false", "\n", "}" ]
// fileAccessible checks if the given path exists and is a regular file
[ "fileAccessible", "checks", "if", "the", "given", "path", "exists", "and", "is", "a", "regular", "file" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/common/ssh/ssh.go#L44-L49
167,224
rkt/rkt
stage1/common/ssh/ssh.go
generateKeyPair
func generateKeyPair(private string) error { out, err := exec.Command( "ssh-keygen", "-q", // silence "-t", "dsa", // type "-b", "1024", // length in bits "-f", private, // output file "-N", "", // no passphrase ).Output() if err != nil { // out is in form of bytes buffer and we have to turn it into slice ending on first \0 occurrence return fmt.Errorf("error in keygen time. ret_val: %v, output: %v", err, string(out[:])) } return nil }
go
func generateKeyPair(private string) error { out, err := exec.Command( "ssh-keygen", "-q", // silence "-t", "dsa", // type "-b", "1024", // length in bits "-f", private, // output file "-N", "", // no passphrase ).Output() if err != nil { // out is in form of bytes buffer and we have to turn it into slice ending on first \0 occurrence return fmt.Errorf("error in keygen time. ret_val: %v, output: %v", err, string(out[:])) } return nil }
[ "func", "generateKeyPair", "(", "private", "string", ")", "error", "{", "out", ",", "err", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "// silence", "\"", "\"", ",", "\"", "\"", ",", "// type", "\"", "\"", ",", "\"", "\"", ",", "// length in bits", "\"", "\"", ",", "private", ",", "// output file", "\"", "\"", ",", "\"", "\"", ",", "// no passphrase", ")", ".", "Output", "(", ")", "\n", "if", "err", "!=", "nil", "{", "// out is in form of bytes buffer and we have to turn it into slice ending on first \\0 occurrence", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ",", "string", "(", "out", "[", ":", "]", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// generateKeyPair calls ssh-keygen with private key location for key generation purpose
[ "generateKeyPair", "calls", "ssh", "-", "keygen", "with", "private", "key", "location", "for", "key", "generation", "purpose" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/common/ssh/ssh.go#L60-L74
167,225
rkt/rkt
pkg/mountinfo/types.go
NeedsRemountPrivate
func (m *Mount) NeedsRemountPrivate() bool { for _, key := range []string{ "shared", "master", } { if _, needsRemount := m.Opts[key]; needsRemount { return true } } return false }
go
func (m *Mount) NeedsRemountPrivate() bool { for _, key := range []string{ "shared", "master", } { if _, needsRemount := m.Opts[key]; needsRemount { return true } } return false }
[ "func", "(", "m", "*", "Mount", ")", "NeedsRemountPrivate", "(", ")", "bool", "{", "for", "_", ",", "key", ":=", "range", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "}", "{", "if", "_", ",", "needsRemount", ":=", "m", ".", "Opts", "[", "key", "]", ";", "needsRemount", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// NeedsRemountPrivate checks if this mountPoint needs to be remounted // as private, in order for children to be properly unmounted without // leaking to parents.
[ "NeedsRemountPrivate", "checks", "if", "this", "mountPoint", "needs", "to", "be", "remounted", "as", "private", "in", "order", "for", "children", "to", "be", "properly", "unmounted", "without", "leaking", "to", "parents", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/mountinfo/types.go#L34-L44
167,226
rkt/rkt
pkg/mountinfo/types.go
Filter
func (ms Mounts) Filter(f FilterFunc) Mounts { filtered := make([]*Mount, 0, len(ms)) for _, m := range ms { if f(m) { filtered = append(filtered, m) } } return Mounts(filtered) }
go
func (ms Mounts) Filter(f FilterFunc) Mounts { filtered := make([]*Mount, 0, len(ms)) for _, m := range ms { if f(m) { filtered = append(filtered, m) } } return Mounts(filtered) }
[ "func", "(", "ms", "Mounts", ")", "Filter", "(", "f", "FilterFunc", ")", "Mounts", "{", "filtered", ":=", "make", "(", "[", "]", "*", "Mount", ",", "0", ",", "len", "(", "ms", ")", ")", "\n\n", "for", "_", ",", "m", ":=", "range", "ms", "{", "if", "f", "(", "m", ")", "{", "filtered", "=", "append", "(", "filtered", ",", "m", ")", "\n", "}", "\n", "}", "\n\n", "return", "Mounts", "(", "filtered", ")", "\n", "}" ]
// Filter returns a filtered copy of Mounts
[ "Filter", "returns", "a", "filtered", "copy", "of", "Mounts" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/mountinfo/types.go#L51-L61
167,227
rkt/rkt
pkg/mountinfo/types.go
mountDepth
func (ms Mounts) mountDepth(i int) int { ancestorCount := 0 current := ms[i] for found := true; found; { found = false for _, mnt := range ms { if mnt.ID == current.Parent { ancestorCount++ current = mnt found = true break } } } return ancestorCount }
go
func (ms Mounts) mountDepth(i int) int { ancestorCount := 0 current := ms[i] for found := true; found; { found = false for _, mnt := range ms { if mnt.ID == current.Parent { ancestorCount++ current = mnt found = true break } } } return ancestorCount }
[ "func", "(", "ms", "Mounts", ")", "mountDepth", "(", "i", "int", ")", "int", "{", "ancestorCount", ":=", "0", "\n", "current", ":=", "ms", "[", "i", "]", "\n", "for", "found", ":=", "true", ";", "found", ";", "{", "found", "=", "false", "\n", "for", "_", ",", "mnt", ":=", "range", "ms", "{", "if", "mnt", ".", "ID", "==", "current", ".", "Parent", "{", "ancestorCount", "++", "\n", "current", "=", "mnt", "\n", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "ancestorCount", "\n", "}" ]
// mountDepth determines and returns the number of ancestors of the mount at index i
[ "mountDepth", "determines", "and", "returns", "the", "number", "of", "ancestors", "of", "the", "mount", "at", "index", "i" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/mountinfo/types.go#L72-L87
167,228
rkt/rkt
pkg/flag/bitflags.go
NewBitFlags
func NewBitFlags(permissibleOptions []string, defaultOptions string, flagMap map[string]int) (*BitFlags, error) { ol, err := NewOptionList(permissibleOptions, defaultOptions) if err != nil { return nil, err } bf := &BitFlags{ OptionList: ol, FlagMap: flagMap, } bf.typeName = "BitFlags" if err := bf.Set(defaultOptions); err != nil { return nil, errwrap.Wrap(errors.New("problem setting defaults"), err) } return bf, nil }
go
func NewBitFlags(permissibleOptions []string, defaultOptions string, flagMap map[string]int) (*BitFlags, error) { ol, err := NewOptionList(permissibleOptions, defaultOptions) if err != nil { return nil, err } bf := &BitFlags{ OptionList: ol, FlagMap: flagMap, } bf.typeName = "BitFlags" if err := bf.Set(defaultOptions); err != nil { return nil, errwrap.Wrap(errors.New("problem setting defaults"), err) } return bf, nil }
[ "func", "NewBitFlags", "(", "permissibleOptions", "[", "]", "string", ",", "defaultOptions", "string", ",", "flagMap", "map", "[", "string", "]", "int", ")", "(", "*", "BitFlags", ",", "error", ")", "{", "ol", ",", "err", ":=", "NewOptionList", "(", "permissibleOptions", ",", "defaultOptions", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "bf", ":=", "&", "BitFlags", "{", "OptionList", ":", "ol", ",", "FlagMap", ":", "flagMap", ",", "}", "\n", "bf", ".", "typeName", "=", "\"", "\"", "\n\n", "if", "err", ":=", "bf", ".", "Set", "(", "defaultOptions", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "return", "bf", ",", "nil", "\n", "}" ]
// NewBitFlags initializes a simple bitflag version of the OptionList Type. // flagMap is the mapping from option names to the integer value
[ "NewBitFlags", "initializes", "a", "simple", "bitflag", "version", "of", "the", "OptionList", "Type", ".", "flagMap", "is", "the", "mapping", "from", "option", "names", "to", "the", "integer", "value" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/flag/bitflags.go#L33-L50
167,229
rkt/rkt
tools/common/filelist/filelist.go
parseList
func parseList(scanner *bufio.Scanner, count int) ([]string, error) { got := 0 items := make([]string, 0, count) for { if !scanner.Scan() { if err := scanner.Err(); err != nil { return nil, err } return nil, fmt.Errorf("expected either an empty line or a line with an item, unexpected EOF?") } line := scanner.Text() if line == "" { if got < count { return nil, fmt.Errorf("too few items (declared %d, got %d)", count, got) } break } got++ if got > count { return nil, fmt.Errorf("too many items (declared %d)", count) } items = append(items, line) } return items, nil }
go
func parseList(scanner *bufio.Scanner, count int) ([]string, error) { got := 0 items := make([]string, 0, count) for { if !scanner.Scan() { if err := scanner.Err(); err != nil { return nil, err } return nil, fmt.Errorf("expected either an empty line or a line with an item, unexpected EOF?") } line := scanner.Text() if line == "" { if got < count { return nil, fmt.Errorf("too few items (declared %d, got %d)", count, got) } break } got++ if got > count { return nil, fmt.Errorf("too many items (declared %d)", count) } items = append(items, line) } return items, nil }
[ "func", "parseList", "(", "scanner", "*", "bufio", ".", "Scanner", ",", "count", "int", ")", "(", "[", "]", "string", ",", "error", ")", "{", "got", ":=", "0", "\n", "items", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "count", ")", "\n", "for", "{", "if", "!", "scanner", ".", "Scan", "(", ")", "{", "if", "err", ":=", "scanner", ".", "Err", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "line", ":=", "scanner", ".", "Text", "(", ")", "\n", "if", "line", "==", "\"", "\"", "{", "if", "got", "<", "count", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "count", ",", "got", ")", "\n", "}", "\n", "break", "\n", "}", "\n", "got", "++", "\n", "if", "got", ">", "count", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "count", ")", "\n", "}", "\n", "items", "=", "append", "(", "items", ",", "line", ")", "\n", "}", "\n", "return", "items", ",", "nil", "\n", "}" ]
// parseList parses the list part of a block. It makes sure that there // is an exactly expected count of items.
[ "parseList", "parses", "the", "list", "part", "of", "a", "block", ".", "It", "makes", "sure", "that", "there", "is", "an", "exactly", "expected", "count", "of", "items", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/common/filelist/filelist.go#L89-L113
167,230
rkt/rkt
tools/common/filelist/filelist.go
GenerateFilelist
func (list *Lists) GenerateFilelist(out io.Writer) error { w := bufio.NewWriter(out) for _, pair := range list.getPairs() { dLen := len(*pair.data) toWrite := []string{ pair.kind, "\n(", strconv.Itoa(dLen), ")\n", } if dLen > 0 { toWrite = append(toWrite, strings.Join(*pair.data, "\n"), "\n") } toWrite = append(toWrite, "\n") for _, str := range toWrite { if _, err := w.WriteString(str); err != nil { return err } } } w.Flush() return nil }
go
func (list *Lists) GenerateFilelist(out io.Writer) error { w := bufio.NewWriter(out) for _, pair := range list.getPairs() { dLen := len(*pair.data) toWrite := []string{ pair.kind, "\n(", strconv.Itoa(dLen), ")\n", } if dLen > 0 { toWrite = append(toWrite, strings.Join(*pair.data, "\n"), "\n") } toWrite = append(toWrite, "\n") for _, str := range toWrite { if _, err := w.WriteString(str); err != nil { return err } } } w.Flush() return nil }
[ "func", "(", "list", "*", "Lists", ")", "GenerateFilelist", "(", "out", "io", ".", "Writer", ")", "error", "{", "w", ":=", "bufio", ".", "NewWriter", "(", "out", ")", "\n", "for", "_", ",", "pair", ":=", "range", "list", ".", "getPairs", "(", ")", "{", "dLen", ":=", "len", "(", "*", "pair", ".", "data", ")", "\n", "toWrite", ":=", "[", "]", "string", "{", "pair", ".", "kind", ",", "\"", "\\n", "\"", ",", "strconv", ".", "Itoa", "(", "dLen", ")", ",", "\"", "\\n", "\"", ",", "}", "\n", "if", "dLen", ">", "0", "{", "toWrite", "=", "append", "(", "toWrite", ",", "strings", ".", "Join", "(", "*", "pair", ".", "data", ",", "\"", "\\n", "\"", ")", ",", "\"", "\\n", "\"", ")", "\n", "}", "\n", "toWrite", "=", "append", "(", "toWrite", ",", "\"", "\\n", "\"", ")", "\n", "for", "_", ",", "str", ":=", "range", "toWrite", "{", "if", "_", ",", "err", ":=", "w", ".", "WriteString", "(", "str", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "w", ".", "Flush", "(", ")", "\n", "return", "nil", "\n", "}" ]
// GenerateFilelist generates a filelist, duh. And writes it to a // given writer. The format of generated file is described in // filelist.ParseFilelist.
[ "GenerateFilelist", "generates", "a", "filelist", "duh", ".", "And", "writes", "it", "to", "a", "given", "writer", ".", "The", "format", "of", "generated", "file", "is", "described", "in", "filelist", ".", "ParseFilelist", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/common/filelist/filelist.go#L166-L190
167,231
rkt/rkt
tools/depsgen/mkfile.go
GenerateFileDeps
func GenerateFileDeps(target, filesGenerator string, files []string) string { return replacePlaceholders(fileDepMkTemplate, "DEPS_GEN_APP_NAME", appName(), "DEPS_GEN_FILES_GENERATOR", filesGenerator, "DEPS_GEN_ALL_FILES_STORED", strings.Join(files, " "), "DEPS_GEN_TARGET", target, ) }
go
func GenerateFileDeps(target, filesGenerator string, files []string) string { return replacePlaceholders(fileDepMkTemplate, "DEPS_GEN_APP_NAME", appName(), "DEPS_GEN_FILES_GENERATOR", filesGenerator, "DEPS_GEN_ALL_FILES_STORED", strings.Join(files, " "), "DEPS_GEN_TARGET", target, ) }
[ "func", "GenerateFileDeps", "(", "target", ",", "filesGenerator", "string", ",", "files", "[", "]", "string", ")", "string", "{", "return", "replacePlaceholders", "(", "fileDepMkTemplate", ",", "\"", "\"", ",", "appName", "(", ")", ",", "\"", "\"", ",", "filesGenerator", ",", "\"", "\"", ",", "strings", ".", "Join", "(", "files", ",", "\"", "\"", ")", ",", "\"", "\"", ",", "target", ",", ")", "\n", "}" ]
// GenerateFileDeps returns contents of make file describing // dependencies of given target on given files and checking if files // weren't added or removed in directories where given files are.
[ "GenerateFileDeps", "returns", "contents", "of", "make", "file", "describing", "dependencies", "of", "given", "target", "on", "given", "files", "and", "checking", "if", "files", "weren", "t", "added", "or", "removed", "in", "directories", "where", "given", "files", "are", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/depsgen/mkfile.go#L101-L108
167,232
rkt/rkt
common/resolv_conf.go
MakeResolvConf
func MakeResolvConf(dns cnitypes.DNS, comment string) string { content := "" if len(comment) > 0 { content += fmt.Sprintf("# %s\n\n", comment) } if len(dns.Search) > 0 { content += fmt.Sprintf("search %s\n", strings.Join(dns.Search, " ")) } for _, ns := range dns.Nameservers { content += fmt.Sprintf("nameserver %s\n", ns) } if len(dns.Options) > 0 { content += fmt.Sprintf("options %s\n", strings.Join(dns.Options, " ")) } if len(dns.Domain) > 0 { content += fmt.Sprintf("domain %s\n", dns.Domain) } return content }
go
func MakeResolvConf(dns cnitypes.DNS, comment string) string { content := "" if len(comment) > 0 { content += fmt.Sprintf("# %s\n\n", comment) } if len(dns.Search) > 0 { content += fmt.Sprintf("search %s\n", strings.Join(dns.Search, " ")) } for _, ns := range dns.Nameservers { content += fmt.Sprintf("nameserver %s\n", ns) } if len(dns.Options) > 0 { content += fmt.Sprintf("options %s\n", strings.Join(dns.Options, " ")) } if len(dns.Domain) > 0 { content += fmt.Sprintf("domain %s\n", dns.Domain) } return content }
[ "func", "MakeResolvConf", "(", "dns", "cnitypes", ".", "DNS", ",", "comment", "string", ")", "string", "{", "content", ":=", "\"", "\"", "\n", "if", "len", "(", "comment", ")", ">", "0", "{", "content", "+=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\\n", "\"", ",", "comment", ")", "\n", "}", "\n\n", "if", "len", "(", "dns", ".", "Search", ")", ">", "0", "{", "content", "+=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "strings", ".", "Join", "(", "dns", ".", "Search", ",", "\"", "\"", ")", ")", "\n", "}", "\n\n", "for", "_", ",", "ns", ":=", "range", "dns", ".", "Nameservers", "{", "content", "+=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "ns", ")", "\n", "}", "\n", "if", "len", "(", "dns", ".", "Options", ")", ">", "0", "{", "content", "+=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "strings", ".", "Join", "(", "dns", ".", "Options", ",", "\"", "\"", ")", ")", "\n", "}", "\n\n", "if", "len", "(", "dns", ".", "Domain", ")", ">", "0", "{", "content", "+=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "dns", ".", "Domain", ")", "\n", "}", "\n", "return", "content", "\n", "}" ]
// MakeResolvConf generates resolv.conf contents given a cni DNS configuration
[ "MakeResolvConf", "generates", "resolv", ".", "conf", "contents", "given", "a", "cni", "DNS", "configuration" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/resolv_conf.go#L25-L46
167,233
rkt/rkt
pkg/tar/tar.go
extractFileFromTar
func extractFileFromTar(tr *tar.Reader, file string) ([]byte, error) { for { hdr, err := tr.Next() switch err { case io.EOF: return nil, fmt.Errorf("file not found") case nil: if filepath.Clean(hdr.Name) != filepath.Clean(file) { continue } switch hdr.Typeflag { case tar.TypeReg: case tar.TypeRegA: default: return nil, fmt.Errorf("requested file not a regular file") } buf, err := ioutil.ReadAll(tr) if err != nil { return nil, err } return buf, nil default: return nil, err } } }
go
func extractFileFromTar(tr *tar.Reader, file string) ([]byte, error) { for { hdr, err := tr.Next() switch err { case io.EOF: return nil, fmt.Errorf("file not found") case nil: if filepath.Clean(hdr.Name) != filepath.Clean(file) { continue } switch hdr.Typeflag { case tar.TypeReg: case tar.TypeRegA: default: return nil, fmt.Errorf("requested file not a regular file") } buf, err := ioutil.ReadAll(tr) if err != nil { return nil, err } return buf, nil default: return nil, err } } }
[ "func", "extractFileFromTar", "(", "tr", "*", "tar", ".", "Reader", ",", "file", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "for", "{", "hdr", ",", "err", ":=", "tr", ".", "Next", "(", ")", "\n", "switch", "err", "{", "case", "io", ".", "EOF", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "case", "nil", ":", "if", "filepath", ".", "Clean", "(", "hdr", ".", "Name", ")", "!=", "filepath", ".", "Clean", "(", "file", ")", "{", "continue", "\n", "}", "\n", "switch", "hdr", ".", "Typeflag", "{", "case", "tar", ".", "TypeReg", ":", "case", "tar", ".", "TypeRegA", ":", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "buf", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "tr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "buf", ",", "nil", "\n", "default", ":", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "}" ]
// extractFileFromTar extracts a regular file from the given tar, returning its // contents as a byte slice
[ "extractFileFromTar", "extracts", "a", "regular", "file", "from", "the", "given", "tar", "returning", "its", "contents", "as", "a", "byte", "slice" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/tar/tar.go#L248-L273
167,234
rkt/rkt
networking/portfwd.go
GetForwardableNet
func (n *Networking) GetForwardableNet() (*activeNet, error) { numberNets := len(n.nets) if numberNets == 0 { return nil, fmt.Errorf("no networks found") } for _, net := range n.nets { if net.IPMasq() { return &net, nil } } return &n.nets[numberNets-1], nil }
go
func (n *Networking) GetForwardableNet() (*activeNet, error) { numberNets := len(n.nets) if numberNets == 0 { return nil, fmt.Errorf("no networks found") } for _, net := range n.nets { if net.IPMasq() { return &net, nil } } return &n.nets[numberNets-1], nil }
[ "func", "(", "n", "*", "Networking", ")", "GetForwardableNet", "(", ")", "(", "*", "activeNet", ",", "error", ")", "{", "numberNets", ":=", "len", "(", "n", ".", "nets", ")", "\n", "if", "numberNets", "==", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "for", "_", ",", "net", ":=", "range", "n", ".", "nets", "{", "if", "net", ".", "IPMasq", "(", ")", "{", "return", "&", "net", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "&", "n", ".", "nets", "[", "numberNets", "-", "1", "]", ",", "nil", "\n", "}" ]
// GetForwardableNet iterates through all loaded networks and returns either // the first network that has masquerading enabled, // or the last network in case there is no masqueraded one, // or an error if no network was loaded.
[ "GetForwardableNet", "iterates", "through", "all", "loaded", "networks", "and", "returns", "either", "the", "first", "network", "that", "has", "masquerading", "enabled", "or", "the", "last", "network", "in", "case", "there", "is", "no", "masqueraded", "one", "or", "an", "error", "if", "no", "network", "was", "loaded", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/portfwd.go#L36-L47
167,235
rkt/rkt
networking/portfwd.go
setupForwarding
func (e *podEnv) setupForwarding() error { ipt, err := iptables.New() if err != nil { return err } // Create a separate chain for this pod. This helps with debugging // and makes it easier to cleanup chainDNAT := e.portFwdChain("DNAT") chainSNAT := e.portFwdChain("SNAT") if err = ipt.NewChain("nat", chainDNAT); err != nil { return err } if err = ipt.NewChain("nat", chainSNAT); err != nil { return err } chainRuleDNAT := e.portFwdChainRuleSpec(chainDNAT, "DNAT") chainRuleSNAT := e.portFwdChainRuleSpec(chainSNAT, "SNAT") for _, entry := range []struct { chain string customChainRule []string }{ {"POSTROUTING", chainRuleSNAT}, // traffic originating from this host from loopback {"PREROUTING", chainRuleDNAT}, // outside traffic hitting this host {"OUTPUT", chainRuleDNAT}, // traffic originating from this host on non-loopback } { exists, err := ipt.Exists("nat", entry.chain, entry.customChainRule...) if err != nil { return err } if !exists { err = ipt.Insert("nat", entry.chain, 1, entry.customChainRule...) if err != nil { return err } } } return nil }
go
func (e *podEnv) setupForwarding() error { ipt, err := iptables.New() if err != nil { return err } // Create a separate chain for this pod. This helps with debugging // and makes it easier to cleanup chainDNAT := e.portFwdChain("DNAT") chainSNAT := e.portFwdChain("SNAT") if err = ipt.NewChain("nat", chainDNAT); err != nil { return err } if err = ipt.NewChain("nat", chainSNAT); err != nil { return err } chainRuleDNAT := e.portFwdChainRuleSpec(chainDNAT, "DNAT") chainRuleSNAT := e.portFwdChainRuleSpec(chainSNAT, "SNAT") for _, entry := range []struct { chain string customChainRule []string }{ {"POSTROUTING", chainRuleSNAT}, // traffic originating from this host from loopback {"PREROUTING", chainRuleDNAT}, // outside traffic hitting this host {"OUTPUT", chainRuleDNAT}, // traffic originating from this host on non-loopback } { exists, err := ipt.Exists("nat", entry.chain, entry.customChainRule...) if err != nil { return err } if !exists { err = ipt.Insert("nat", entry.chain, 1, entry.customChainRule...) if err != nil { return err } } } return nil }
[ "func", "(", "e", "*", "podEnv", ")", "setupForwarding", "(", ")", "error", "{", "ipt", ",", "err", ":=", "iptables", ".", "New", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Create a separate chain for this pod. This helps with debugging", "// and makes it easier to cleanup", "chainDNAT", ":=", "e", ".", "portFwdChain", "(", "\"", "\"", ")", "\n", "chainSNAT", ":=", "e", ".", "portFwdChain", "(", "\"", "\"", ")", "\n\n", "if", "err", "=", "ipt", ".", "NewChain", "(", "\"", "\"", ",", "chainDNAT", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", "=", "ipt", ".", "NewChain", "(", "\"", "\"", ",", "chainSNAT", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "chainRuleDNAT", ":=", "e", ".", "portFwdChainRuleSpec", "(", "chainDNAT", ",", "\"", "\"", ")", "\n", "chainRuleSNAT", ":=", "e", ".", "portFwdChainRuleSpec", "(", "chainSNAT", ",", "\"", "\"", ")", "\n\n", "for", "_", ",", "entry", ":=", "range", "[", "]", "struct", "{", "chain", "string", "\n", "customChainRule", "[", "]", "string", "\n", "}", "{", "{", "\"", "\"", ",", "chainRuleSNAT", "}", ",", "// traffic originating from this host from loopback", "{", "\"", "\"", ",", "chainRuleDNAT", "}", ",", "// outside traffic hitting this host", "{", "\"", "\"", ",", "chainRuleDNAT", "}", ",", "// traffic originating from this host on non-loopback", "}", "{", "exists", ",", "err", ":=", "ipt", ".", "Exists", "(", "\"", "\"", ",", "entry", ".", "chain", ",", "entry", ".", "customChainRule", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "!", "exists", "{", "err", "=", "ipt", ".", "Insert", "(", "\"", "\"", ",", "entry", ".", "chain", ",", "1", ",", "entry", ".", "customChainRule", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// setupForwarding creates the iptables chains
[ "setupForwarding", "creates", "the", "iptables", "chains" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/portfwd.go#L70-L112
167,236
rkt/rkt
stage1/init/kvm.go
KvmNetworkingToSystemd
func KvmNetworkingToSystemd(p *stage1commontypes.Pod, n *networking.Networking) error { podRoot := common.Stage1RootfsPath(p.Root) // networking netDescriptions := kvm.GetNetworkDescriptions(n) if err := kvm.GenerateNetworkInterfaceUnits(filepath.Join(podRoot, stage1initcommon.UnitsDir), netDescriptions); err != nil { return errwrap.Wrap(errors.New("failed to transform networking to units"), err) } return nil }
go
func KvmNetworkingToSystemd(p *stage1commontypes.Pod, n *networking.Networking) error { podRoot := common.Stage1RootfsPath(p.Root) // networking netDescriptions := kvm.GetNetworkDescriptions(n) if err := kvm.GenerateNetworkInterfaceUnits(filepath.Join(podRoot, stage1initcommon.UnitsDir), netDescriptions); err != nil { return errwrap.Wrap(errors.New("failed to transform networking to units"), err) } return nil }
[ "func", "KvmNetworkingToSystemd", "(", "p", "*", "stage1commontypes", ".", "Pod", ",", "n", "*", "networking", ".", "Networking", ")", "error", "{", "podRoot", ":=", "common", ".", "Stage1RootfsPath", "(", "p", ".", "Root", ")", "\n\n", "// networking", "netDescriptions", ":=", "kvm", ".", "GetNetworkDescriptions", "(", "n", ")", "\n", "if", "err", ":=", "kvm", ".", "GenerateNetworkInterfaceUnits", "(", "filepath", ".", "Join", "(", "podRoot", ",", "stage1initcommon", ".", "UnitsDir", ")", ",", "netDescriptions", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// KvmNetworkingToSystemd generates systemd unit files for a pod according to network configuration
[ "KvmNetworkingToSystemd", "generates", "systemd", "unit", "files", "for", "a", "pod", "according", "to", "network", "configuration" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/kvm.go#L44-L54
167,237
rkt/rkt
pkg/pod/pods.go
initPods
func initPods(dataDir string) error { if !podsInitialized { dirs := []string{embryoDir(dataDir), prepareDir(dataDir), preparedDir(dataDir), runDir(dataDir), exitedGarbageDir(dataDir), garbageDir(dataDir)} for _, d := range dirs { if err := os.MkdirAll(d, 0750); err != nil { return errwrap.Wrap(errors.New("error creating directory"), err) } } podsInitialized = true } return nil }
go
func initPods(dataDir string) error { if !podsInitialized { dirs := []string{embryoDir(dataDir), prepareDir(dataDir), preparedDir(dataDir), runDir(dataDir), exitedGarbageDir(dataDir), garbageDir(dataDir)} for _, d := range dirs { if err := os.MkdirAll(d, 0750); err != nil { return errwrap.Wrap(errors.New("error creating directory"), err) } } podsInitialized = true } return nil }
[ "func", "initPods", "(", "dataDir", "string", ")", "error", "{", "if", "!", "podsInitialized", "{", "dirs", ":=", "[", "]", "string", "{", "embryoDir", "(", "dataDir", ")", ",", "prepareDir", "(", "dataDir", ")", ",", "preparedDir", "(", "dataDir", ")", ",", "runDir", "(", "dataDir", ")", ",", "exitedGarbageDir", "(", "dataDir", ")", ",", "garbageDir", "(", "dataDir", ")", "}", "\n", "for", "_", ",", "d", ":=", "range", "dirs", "{", "if", "err", ":=", "os", ".", "MkdirAll", "(", "d", ",", "0750", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "}", "\n", "podsInitialized", "=", "true", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// initPods creates the required global directories
[ "initPods", "creates", "the", "required", "global", "directories" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L136-L147
167,238
rkt/rkt
pkg/pod/pods.go
embryoPath
func (p *Pod) embryoPath() string { return filepath.Join(embryoDir(p.dataDir), p.UUID.String()) }
go
func (p *Pod) embryoPath() string { return filepath.Join(embryoDir(p.dataDir), p.UUID.String()) }
[ "func", "(", "p", "*", "Pod", ")", "embryoPath", "(", ")", "string", "{", "return", "filepath", ".", "Join", "(", "embryoDir", "(", "p", ".", "dataDir", ")", ",", "p", ".", "UUID", ".", "String", "(", ")", ")", "\n", "}" ]
// embryoPath returns the path to the pod where it would be in the embryoDir in its embryonic state.
[ "embryoPath", "returns", "the", "path", "to", "the", "pod", "where", "it", "would", "be", "in", "the", "embryoDir", "in", "its", "embryonic", "state", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L304-L306
167,239
rkt/rkt
pkg/pod/pods.go
preparePath
func (p *Pod) preparePath() string { return filepath.Join(prepareDir(p.dataDir), p.UUID.String()) }
go
func (p *Pod) preparePath() string { return filepath.Join(prepareDir(p.dataDir), p.UUID.String()) }
[ "func", "(", "p", "*", "Pod", ")", "preparePath", "(", ")", "string", "{", "return", "filepath", ".", "Join", "(", "prepareDir", "(", "p", ".", "dataDir", ")", ",", "p", ".", "UUID", ".", "String", "(", ")", ")", "\n", "}" ]
// preparePath returns the path to the pod where it would be in the prepareDir in its preparing state.
[ "preparePath", "returns", "the", "path", "to", "the", "pod", "where", "it", "would", "be", "in", "the", "prepareDir", "in", "its", "preparing", "state", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L309-L311
167,240
rkt/rkt
pkg/pod/pods.go
preparedPath
func (p *Pod) preparedPath() string { return filepath.Join(preparedDir(p.dataDir), p.UUID.String()) }
go
func (p *Pod) preparedPath() string { return filepath.Join(preparedDir(p.dataDir), p.UUID.String()) }
[ "func", "(", "p", "*", "Pod", ")", "preparedPath", "(", ")", "string", "{", "return", "filepath", ".", "Join", "(", "preparedDir", "(", "p", ".", "dataDir", ")", ",", "p", ".", "UUID", ".", "String", "(", ")", ")", "\n", "}" ]
// preparedPath returns the path to the pod where it would be in the preparedDir.
[ "preparedPath", "returns", "the", "path", "to", "the", "pod", "where", "it", "would", "be", "in", "the", "preparedDir", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L314-L316
167,241
rkt/rkt
pkg/pod/pods.go
runPath
func (p *Pod) runPath() string { return filepath.Join(runDir(p.dataDir), p.UUID.String()) }
go
func (p *Pod) runPath() string { return filepath.Join(runDir(p.dataDir), p.UUID.String()) }
[ "func", "(", "p", "*", "Pod", ")", "runPath", "(", ")", "string", "{", "return", "filepath", ".", "Join", "(", "runDir", "(", "p", ".", "dataDir", ")", ",", "p", ".", "UUID", ".", "String", "(", ")", ")", "\n", "}" ]
// runPath returns the path to the pod where it would be in the runDir.
[ "runPath", "returns", "the", "path", "to", "the", "pod", "where", "it", "would", "be", "in", "the", "runDir", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L319-L321
167,242
rkt/rkt
pkg/pod/pods.go
exitedGarbagePath
func (p *Pod) exitedGarbagePath() string { return filepath.Join(exitedGarbageDir(p.dataDir), p.UUID.String()) }
go
func (p *Pod) exitedGarbagePath() string { return filepath.Join(exitedGarbageDir(p.dataDir), p.UUID.String()) }
[ "func", "(", "p", "*", "Pod", ")", "exitedGarbagePath", "(", ")", "string", "{", "return", "filepath", ".", "Join", "(", "exitedGarbageDir", "(", "p", ".", "dataDir", ")", ",", "p", ".", "UUID", ".", "String", "(", ")", ")", "\n", "}" ]
// exitedGarbagePath returns the path to the pod where it would be in the exitedGarbageDir.
[ "exitedGarbagePath", "returns", "the", "path", "to", "the", "pod", "where", "it", "would", "be", "in", "the", "exitedGarbageDir", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L324-L326
167,243
rkt/rkt
pkg/pod/pods.go
garbagePath
func (p *Pod) garbagePath() string { return filepath.Join(garbageDir(p.dataDir), p.UUID.String()) }
go
func (p *Pod) garbagePath() string { return filepath.Join(garbageDir(p.dataDir), p.UUID.String()) }
[ "func", "(", "p", "*", "Pod", ")", "garbagePath", "(", ")", "string", "{", "return", "filepath", ".", "Join", "(", "garbageDir", "(", "p", ".", "dataDir", ")", ",", "p", ".", "UUID", ".", "String", "(", ")", ")", "\n", "}" ]
// garbagePath returns the path to the pod where it would be in the garbageDir.
[ "garbagePath", "returns", "the", "path", "to", "the", "pod", "where", "it", "would", "be", "in", "the", "garbageDir", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L329-L331
167,244
rkt/rkt
pkg/pod/pods.go
ToExitedGarbage
func (p *Pod) ToExitedGarbage() error { if !p.isExited || p.isExitedGarbage { return fmt.Errorf("bug: only exited non-garbage pods may transition to exited-garbage") } if err := os.Rename(p.runPath(), p.exitedGarbagePath()); err != nil { // TODO(vc): another case where we could race with a concurrent ToExitedGarbage(), let caller deal with the error. return err } df, err := os.Open(exitedGarbageDir(p.dataDir)) if err != nil { return err } defer df.Close() if err := df.Sync(); err != nil { return err } p.isExitedGarbage = true return nil }
go
func (p *Pod) ToExitedGarbage() error { if !p.isExited || p.isExitedGarbage { return fmt.Errorf("bug: only exited non-garbage pods may transition to exited-garbage") } if err := os.Rename(p.runPath(), p.exitedGarbagePath()); err != nil { // TODO(vc): another case where we could race with a concurrent ToExitedGarbage(), let caller deal with the error. return err } df, err := os.Open(exitedGarbageDir(p.dataDir)) if err != nil { return err } defer df.Close() if err := df.Sync(); err != nil { return err } p.isExitedGarbage = true return nil }
[ "func", "(", "p", "*", "Pod", ")", "ToExitedGarbage", "(", ")", "error", "{", "if", "!", "p", ".", "isExited", "||", "p", ".", "isExitedGarbage", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "err", ":=", "os", ".", "Rename", "(", "p", ".", "runPath", "(", ")", ",", "p", ".", "exitedGarbagePath", "(", ")", ")", ";", "err", "!=", "nil", "{", "// TODO(vc): another case where we could race with a concurrent ToExitedGarbage(), let caller deal with the error.", "return", "err", "\n", "}", "\n\n", "df", ",", "err", ":=", "os", ".", "Open", "(", "exitedGarbageDir", "(", "p", ".", "dataDir", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "df", ".", "Close", "(", ")", "\n", "if", "err", ":=", "df", ".", "Sync", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "p", ".", "isExitedGarbage", "=", "true", "\n\n", "return", "nil", "\n", "}" ]
// ToExitedGarbage transitions a pod from run -> exitedGarbage // This method refreshes the pod state.
[ "ToExitedGarbage", "transitions", "a", "pod", "from", "run", "-", ">", "exitedGarbage", "This", "method", "refreshes", "the", "pod", "state", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L440-L462
167,245
rkt/rkt
pkg/pod/pods.go
ToGarbage
func (p *Pod) ToGarbage() error { if !p.isAbortedPrepare && !p.isPrepared { return fmt.Errorf("bug: only failed prepare or prepared pods may transition to garbage") } if err := os.Rename(p.Path(), p.garbagePath()); err != nil { return err } df, err := os.Open(garbageDir(p.dataDir)) if err != nil { return err } defer df.Close() if err := df.Sync(); err != nil { return err } p.isAbortedPrepare = false p.isPrepared = false p.isGarbage = true return nil }
go
func (p *Pod) ToGarbage() error { if !p.isAbortedPrepare && !p.isPrepared { return fmt.Errorf("bug: only failed prepare or prepared pods may transition to garbage") } if err := os.Rename(p.Path(), p.garbagePath()); err != nil { return err } df, err := os.Open(garbageDir(p.dataDir)) if err != nil { return err } defer df.Close() if err := df.Sync(); err != nil { return err } p.isAbortedPrepare = false p.isPrepared = false p.isGarbage = true return nil }
[ "func", "(", "p", "*", "Pod", ")", "ToGarbage", "(", ")", "error", "{", "if", "!", "p", ".", "isAbortedPrepare", "&&", "!", "p", ".", "isPrepared", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "err", ":=", "os", ".", "Rename", "(", "p", ".", "Path", "(", ")", ",", "p", ".", "garbagePath", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "df", ",", "err", ":=", "os", ".", "Open", "(", "garbageDir", "(", "p", ".", "dataDir", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "df", ".", "Close", "(", ")", "\n", "if", "err", ":=", "df", ".", "Sync", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "p", ".", "isAbortedPrepare", "=", "false", "\n", "p", ".", "isPrepared", "=", "false", "\n", "p", ".", "isGarbage", "=", "true", "\n\n", "return", "nil", "\n", "}" ]
// ToGarbage transitions a pod from abortedPrepared -> garbage or prepared -> garbage // This method refreshes the pod state.
[ "ToGarbage", "transitions", "a", "pod", "from", "abortedPrepared", "-", ">", "garbage", "or", "prepared", "-", ">", "garbage", "This", "method", "refreshes", "the", "pod", "state", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L466-L489
167,246
rkt/rkt
pkg/pod/pods.go
listPods
func listPods(dataDir string, include IncludeMask) ([]string, error) { // uniqued due to the possibility of a pod being renamed from across directories during the list operation ups := make(map[string]struct{}) dirs := []struct { kind IncludeMask path string }{ { // the order here is significant: embryo -> preparing -> prepared -> running -> exitedGarbage kind: IncludeEmbryoDir, path: embryoDir(dataDir), }, { kind: IncludePrepareDir, path: prepareDir(dataDir), }, { kind: IncludePreparedDir, path: preparedDir(dataDir), }, { kind: IncludeRunDir, path: runDir(dataDir), }, { kind: IncludeExitedGarbageDir, path: exitedGarbageDir(dataDir), }, { kind: IncludeGarbageDir, path: garbageDir(dataDir), }, } for _, d := range dirs { if include&d.kind != 0 { ps, err := listPodsFromDir(d.path) if err != nil { return nil, err } for _, p := range ps { ups[p] = struct{}{} } } } ps := make([]string, 0, len(ups)) for p := range ups { ps = append(ps, p) } return ps, nil }
go
func listPods(dataDir string, include IncludeMask) ([]string, error) { // uniqued due to the possibility of a pod being renamed from across directories during the list operation ups := make(map[string]struct{}) dirs := []struct { kind IncludeMask path string }{ { // the order here is significant: embryo -> preparing -> prepared -> running -> exitedGarbage kind: IncludeEmbryoDir, path: embryoDir(dataDir), }, { kind: IncludePrepareDir, path: prepareDir(dataDir), }, { kind: IncludePreparedDir, path: preparedDir(dataDir), }, { kind: IncludeRunDir, path: runDir(dataDir), }, { kind: IncludeExitedGarbageDir, path: exitedGarbageDir(dataDir), }, { kind: IncludeGarbageDir, path: garbageDir(dataDir), }, } for _, d := range dirs { if include&d.kind != 0 { ps, err := listPodsFromDir(d.path) if err != nil { return nil, err } for _, p := range ps { ups[p] = struct{}{} } } } ps := make([]string, 0, len(ups)) for p := range ups { ps = append(ps, p) } return ps, nil }
[ "func", "listPods", "(", "dataDir", "string", ",", "include", "IncludeMask", ")", "(", "[", "]", "string", ",", "error", ")", "{", "// uniqued due to the possibility of a pod being renamed from across directories during the list operation", "ups", ":=", "make", "(", "map", "[", "string", "]", "struct", "{", "}", ")", "\n", "dirs", ":=", "[", "]", "struct", "{", "kind", "IncludeMask", "\n", "path", "string", "\n", "}", "{", "{", "// the order here is significant: embryo -> preparing -> prepared -> running -> exitedGarbage", "kind", ":", "IncludeEmbryoDir", ",", "path", ":", "embryoDir", "(", "dataDir", ")", ",", "}", ",", "{", "kind", ":", "IncludePrepareDir", ",", "path", ":", "prepareDir", "(", "dataDir", ")", ",", "}", ",", "{", "kind", ":", "IncludePreparedDir", ",", "path", ":", "preparedDir", "(", "dataDir", ")", ",", "}", ",", "{", "kind", ":", "IncludeRunDir", ",", "path", ":", "runDir", "(", "dataDir", ")", ",", "}", ",", "{", "kind", ":", "IncludeExitedGarbageDir", ",", "path", ":", "exitedGarbageDir", "(", "dataDir", ")", ",", "}", ",", "{", "kind", ":", "IncludeGarbageDir", ",", "path", ":", "garbageDir", "(", "dataDir", ")", ",", "}", ",", "}", "\n\n", "for", "_", ",", "d", ":=", "range", "dirs", "{", "if", "include", "&", "d", ".", "kind", "!=", "0", "{", "ps", ",", "err", ":=", "listPodsFromDir", "(", "d", ".", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "for", "_", ",", "p", ":=", "range", "ps", "{", "ups", "[", "p", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "ps", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "ups", ")", ")", "\n", "for", "p", ":=", "range", "ups", "{", "ps", "=", "append", "(", "ps", ",", "p", ")", "\n", "}", "\n\n", "return", "ps", ",", "nil", "\n", "}" ]
// listPods returns a list of pod uuids in string form.
[ "listPods", "returns", "a", "list", "of", "pod", "uuids", "in", "string", "form", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L492-L538
167,247
rkt/rkt
pkg/pod/pods.go
listPodsFromDir
func listPodsFromDir(cdir string) ([]string, error) { var ps []string ls, err := ioutil.ReadDir(cdir) if err != nil { if os.IsNotExist(err) { return ps, nil } return nil, errwrap.Wrap(errors.New("cannot read pods directory"), err) } for _, p := range ls { if !p.IsDir() { fmt.Fprintf(os.Stderr, "unrecognized entry: %q, ignoring", p.Name()) continue } ps = append(ps, p.Name()) } return ps, nil }
go
func listPodsFromDir(cdir string) ([]string, error) { var ps []string ls, err := ioutil.ReadDir(cdir) if err != nil { if os.IsNotExist(err) { return ps, nil } return nil, errwrap.Wrap(errors.New("cannot read pods directory"), err) } for _, p := range ls { if !p.IsDir() { fmt.Fprintf(os.Stderr, "unrecognized entry: %q, ignoring", p.Name()) continue } ps = append(ps, p.Name()) } return ps, nil }
[ "func", "listPodsFromDir", "(", "cdir", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "var", "ps", "[", "]", "string", "\n\n", "ls", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "cdir", ")", "\n", "if", "err", "!=", "nil", "{", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "ps", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "for", "_", ",", "p", ":=", "range", "ls", "{", "if", "!", "p", ".", "IsDir", "(", ")", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\"", ",", "p", ".", "Name", "(", ")", ")", "\n", "continue", "\n", "}", "\n", "ps", "=", "append", "(", "ps", ",", "p", ".", "Name", "(", ")", ")", "\n", "}", "\n\n", "return", "ps", ",", "nil", "\n", "}" ]
// listPodsFromDir returns a list of pod uuids in string form from a specific directory.
[ "listPodsFromDir", "returns", "a", "list", "of", "pod", "uuids", "in", "string", "form", "from", "a", "specific", "directory", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L541-L561
167,248
rkt/rkt
pkg/pod/pods.go
readFile
func (p *Pod) readFile(path string) ([]byte, error) { f, err := p.openFile(path, syscall.O_RDONLY) if err != nil { return nil, err } defer f.Close() return ioutil.ReadAll(f) }
go
func (p *Pod) readFile(path string) ([]byte, error) { f, err := p.openFile(path, syscall.O_RDONLY) if err != nil { return nil, err } defer f.Close() return ioutil.ReadAll(f) }
[ "func", "(", "p", "*", "Pod", ")", "readFile", "(", "path", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "f", ",", "err", ":=", "p", ".", "openFile", "(", "path", ",", "syscall", ".", "O_RDONLY", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n\n", "return", "ioutil", ".", "ReadAll", "(", "f", ")", "\n", "}" ]
// readFile reads an entire file from a pod's directory.
[ "readFile", "reads", "an", "entire", "file", "from", "a", "pod", "s", "directory", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L654-L662
167,249
rkt/rkt
pkg/pod/pods.go
readIntFromFile
func (p *Pod) readIntFromFile(path string) (i int, err error) { b, err := p.readFile(path) if err != nil { return } _, err = fmt.Sscanf(string(b), "%d", &i) return }
go
func (p *Pod) readIntFromFile(path string) (i int, err error) { b, err := p.readFile(path) if err != nil { return } _, err = fmt.Sscanf(string(b), "%d", &i) return }
[ "func", "(", "p", "*", "Pod", ")", "readIntFromFile", "(", "path", "string", ")", "(", "i", "int", ",", "err", "error", ")", "{", "b", ",", "err", ":=", "p", ".", "readFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "_", ",", "err", "=", "fmt", ".", "Sscanf", "(", "string", "(", "b", ")", ",", "\"", "\"", ",", "&", "i", ")", "\n", "return", "\n", "}" ]
// readIntFromFile reads an int from a file in a pod's directory.
[ "readIntFromFile", "reads", "an", "int", "from", "a", "file", "in", "a", "pod", "s", "directory", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L665-L672
167,250
rkt/rkt
pkg/pod/pods.go
openFile
func (p *Pod) openFile(path string, flags int) (*os.File, error) { cdirfd, err := p.Fd() if err != nil { return nil, err } fd, err := syscall.Openat(cdirfd, path, flags, 0) if err != nil { return nil, err } return os.NewFile(uintptr(fd), path), nil }
go
func (p *Pod) openFile(path string, flags int) (*os.File, error) { cdirfd, err := p.Fd() if err != nil { return nil, err } fd, err := syscall.Openat(cdirfd, path, flags, 0) if err != nil { return nil, err } return os.NewFile(uintptr(fd), path), nil }
[ "func", "(", "p", "*", "Pod", ")", "openFile", "(", "path", "string", ",", "flags", "int", ")", "(", "*", "os", ".", "File", ",", "error", ")", "{", "cdirfd", ",", "err", ":=", "p", ".", "Fd", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "fd", ",", "err", ":=", "syscall", ".", "Openat", "(", "cdirfd", ",", "path", ",", "flags", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "os", ".", "NewFile", "(", "uintptr", "(", "fd", ")", ",", "path", ")", ",", "nil", "\n", "}" ]
// openFile opens a file from a pod's directory returning a file descriptor.
[ "openFile", "opens", "a", "file", "from", "a", "pod", "s", "directory", "returning", "a", "file", "descriptor", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L675-L687
167,251
rkt/rkt
pkg/pod/pods.go
getChildPID
func getChildPID(ppid int) (int, error) { var pid int // If possible, get the child in O(1). Fallback on O(n) when the kernel does not have // either CONFIG_PROC_CHILDREN or CONFIG_CHECKPOINT_RESTORE _, err := os.Stat("/proc/1/task/1/children") if err == nil { b, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/task/%d/children", ppid, ppid)) if err == nil { children := strings.SplitN(string(b), " ", 2) if len(children) == 2 && children[1] != "" { return -1, fmt.Errorf("too many children of pid %d", ppid) } if _, err := fmt.Sscanf(children[0], "%d ", &pid); err == nil { return pid, nil } } return -1, ErrChildNotReady{} } // Fallback on the slower method fdir, err := os.Open(`/proc`) if err != nil { return -1, err } defer fdir.Close() for { fi, err := fdir.Readdir(1) if err == io.EOF { break } if err != nil { return -1, err } if len(fi) == 0 { // See https://github.com/rkt/rkt/issues/3109#issuecomment-242209246 continue } var pid64 int64 if pid64, err = strconv.ParseInt(fi[0].Name(), 10, 0); err != nil { continue } filename := fmt.Sprintf("/proc/%d/stat", pid64) statBytes, err := ioutil.ReadFile(filename) if err != nil { // The process just died? It's not the one we want then. continue } statFields := strings.SplitN(string(statBytes), " ", 5) if len(statFields) != 5 { return -1, fmt.Errorf("incomplete file %q", filename) } if statFields[3] == fmt.Sprintf("%d", ppid) { return int(pid64), nil } } return -1, ErrChildNotReady{} }
go
func getChildPID(ppid int) (int, error) { var pid int // If possible, get the child in O(1). Fallback on O(n) when the kernel does not have // either CONFIG_PROC_CHILDREN or CONFIG_CHECKPOINT_RESTORE _, err := os.Stat("/proc/1/task/1/children") if err == nil { b, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/task/%d/children", ppid, ppid)) if err == nil { children := strings.SplitN(string(b), " ", 2) if len(children) == 2 && children[1] != "" { return -1, fmt.Errorf("too many children of pid %d", ppid) } if _, err := fmt.Sscanf(children[0], "%d ", &pid); err == nil { return pid, nil } } return -1, ErrChildNotReady{} } // Fallback on the slower method fdir, err := os.Open(`/proc`) if err != nil { return -1, err } defer fdir.Close() for { fi, err := fdir.Readdir(1) if err == io.EOF { break } if err != nil { return -1, err } if len(fi) == 0 { // See https://github.com/rkt/rkt/issues/3109#issuecomment-242209246 continue } var pid64 int64 if pid64, err = strconv.ParseInt(fi[0].Name(), 10, 0); err != nil { continue } filename := fmt.Sprintf("/proc/%d/stat", pid64) statBytes, err := ioutil.ReadFile(filename) if err != nil { // The process just died? It's not the one we want then. continue } statFields := strings.SplitN(string(statBytes), " ", 5) if len(statFields) != 5 { return -1, fmt.Errorf("incomplete file %q", filename) } if statFields[3] == fmt.Sprintf("%d", ppid) { return int(pid64), nil } } return -1, ErrChildNotReady{} }
[ "func", "getChildPID", "(", "ppid", "int", ")", "(", "int", ",", "error", ")", "{", "var", "pid", "int", "\n\n", "// If possible, get the child in O(1). Fallback on O(n) when the kernel does not have", "// either CONFIG_PROC_CHILDREN or CONFIG_CHECKPOINT_RESTORE", "_", ",", "err", ":=", "os", ".", "Stat", "(", "\"", "\"", ")", "\n", "if", "err", "==", "nil", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ppid", ",", "ppid", ")", ")", "\n", "if", "err", "==", "nil", "{", "children", ":=", "strings", ".", "SplitN", "(", "string", "(", "b", ")", ",", "\"", "\"", ",", "2", ")", "\n", "if", "len", "(", "children", ")", "==", "2", "&&", "children", "[", "1", "]", "!=", "\"", "\"", "{", "return", "-", "1", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ppid", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "fmt", ".", "Sscanf", "(", "children", "[", "0", "]", ",", "\"", "\"", ",", "&", "pid", ")", ";", "err", "==", "nil", "{", "return", "pid", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "-", "1", ",", "ErrChildNotReady", "{", "}", "\n", "}", "\n\n", "// Fallback on the slower method", "fdir", ",", "err", ":=", "os", ".", "Open", "(", "`/proc`", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n", "defer", "fdir", ".", "Close", "(", ")", "\n\n", "for", "{", "fi", ",", "err", ":=", "fdir", ".", "Readdir", "(", "1", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n", "if", "len", "(", "fi", ")", "==", "0", "{", "// See https://github.com/rkt/rkt/issues/3109#issuecomment-242209246", "continue", "\n", "}", "\n", "var", "pid64", "int64", "\n", "if", "pid64", ",", "err", "=", "strconv", ".", "ParseInt", "(", "fi", "[", "0", "]", ".", "Name", "(", ")", ",", "10", ",", "0", ")", ";", "err", "!=", "nil", "{", "continue", "\n", "}", "\n", "filename", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "pid64", ")", "\n", "statBytes", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "// The process just died? It's not the one we want then.", "continue", "\n", "}", "\n", "statFields", ":=", "strings", ".", "SplitN", "(", "string", "(", "statBytes", ")", ",", "\"", "\"", ",", "5", ")", "\n", "if", "len", "(", "statFields", ")", "!=", "5", "{", "return", "-", "1", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "filename", ")", "\n", "}", "\n", "if", "statFields", "[", "3", "]", "==", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ppid", ")", "{", "return", "int", "(", "pid64", ")", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "-", "1", ",", "ErrChildNotReady", "{", "}", "\n", "}" ]
// Returns the pid of the child, or ErrChildNotReady if not ready
[ "Returns", "the", "pid", "of", "the", "child", "or", "ErrChildNotReady", "if", "not", "ready" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L712-L771
167,252
rkt/rkt
pkg/pod/pods.go
getAppsHashes
func (p *Pod) getAppsHashes() ([]types.Hash, error) { apps, err := p.getApps() if err != nil { return nil, err } var hashes []types.Hash for _, a := range apps { hashes = append(hashes, a.Image.ID) } return hashes, nil }
go
func (p *Pod) getAppsHashes() ([]types.Hash, error) { apps, err := p.getApps() if err != nil { return nil, err } var hashes []types.Hash for _, a := range apps { hashes = append(hashes, a.Image.ID) } return hashes, nil }
[ "func", "(", "p", "*", "Pod", ")", "getAppsHashes", "(", ")", "(", "[", "]", "types", ".", "Hash", ",", "error", ")", "{", "apps", ",", "err", ":=", "p", ".", "getApps", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "hashes", "[", "]", "types", ".", "Hash", "\n", "for", "_", ",", "a", ":=", "range", "apps", "{", "hashes", "=", "append", "(", "hashes", ",", "a", ".", "Image", ".", "ID", ")", "\n", "}", "\n\n", "return", "hashes", ",", "nil", "\n", "}" ]
// getAppsHashes returns a list of the app hashes in the pod
[ "getAppsHashes", "returns", "a", "list", "of", "the", "app", "hashes", "in", "the", "pod" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L824-L836
167,253
rkt/rkt
pkg/pod/pods.go
getApps
func (p *Pod) getApps() (schema.AppList, error) { _, pm, err := p.PodManifest() if err != nil { return nil, err } return pm.Apps, nil }
go
func (p *Pod) getApps() (schema.AppList, error) { _, pm, err := p.PodManifest() if err != nil { return nil, err } return pm.Apps, nil }
[ "func", "(", "p", "*", "Pod", ")", "getApps", "(", ")", "(", "schema", ".", "AppList", ",", "error", ")", "{", "_", ",", "pm", ",", "err", ":=", "p", ".", "PodManifest", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "pm", ".", "Apps", ",", "nil", "\n", "}" ]
// getApps returns a list of apps in the pod
[ "getApps", "returns", "a", "list", "of", "apps", "in", "the", "pod" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L839-L845
167,254
rkt/rkt
pkg/pod/pods.go
getDirNames
func (p *Pod) getDirNames(path string) ([]string, error) { dir, err := p.openFile(path, syscall.O_RDONLY|syscall.O_DIRECTORY) if err != nil { return nil, errwrap.Wrap(errors.New("unable to open directory"), err) } defer dir.Close() ld, err := dir.Readdirnames(0) if err != nil { return nil, errwrap.Wrap(errors.New("unable to read directory"), err) } return ld, nil }
go
func (p *Pod) getDirNames(path string) ([]string, error) { dir, err := p.openFile(path, syscall.O_RDONLY|syscall.O_DIRECTORY) if err != nil { return nil, errwrap.Wrap(errors.New("unable to open directory"), err) } defer dir.Close() ld, err := dir.Readdirnames(0) if err != nil { return nil, errwrap.Wrap(errors.New("unable to read directory"), err) } return ld, nil }
[ "func", "(", "p", "*", "Pod", ")", "getDirNames", "(", "path", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "dir", ",", "err", ":=", "p", ".", "openFile", "(", "path", ",", "syscall", ".", "O_RDONLY", "|", "syscall", ".", "O_DIRECTORY", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "defer", "dir", ".", "Close", "(", ")", "\n\n", "ld", ",", "err", ":=", "dir", ".", "Readdirnames", "(", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n\n", "return", "ld", ",", "nil", "\n", "}" ]
// getDirNames returns the list of names from a pod's directory
[ "getDirNames", "returns", "the", "list", "of", "names", "from", "a", "pod", "s", "directory" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L848-L861
167,255
rkt/rkt
pkg/pod/pods.go
Sync
func (p *Pod) Sync() error { cfd, err := p.Fd() if err != nil { return errwrap.Wrap(fmt.Errorf("error acquiring pod %v dir fd", p.UUID.String()), err) } if err := sys.Syncfs(cfd); err != nil { return errwrap.Wrap(fmt.Errorf("failed to sync pod %v data", p.UUID.String()), err) } return nil }
go
func (p *Pod) Sync() error { cfd, err := p.Fd() if err != nil { return errwrap.Wrap(fmt.Errorf("error acquiring pod %v dir fd", p.UUID.String()), err) } if err := sys.Syncfs(cfd); err != nil { return errwrap.Wrap(fmt.Errorf("failed to sync pod %v data", p.UUID.String()), err) } return nil }
[ "func", "(", "p", "*", "Pod", ")", "Sync", "(", ")", "error", "{", "cfd", ",", "err", ":=", "p", ".", "Fd", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "p", ".", "UUID", ".", "String", "(", ")", ")", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "sys", ".", "Syncfs", "(", "cfd", ")", ";", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "p", ".", "UUID", ".", "String", "(", ")", ")", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Sync syncs the pod data. By now it calls a syncfs on the filesystem // containing the pod's directory.
[ "Sync", "syncs", "the", "pod", "data", ".", "By", "now", "it", "calls", "a", "syncfs", "on", "the", "filesystem", "containing", "the", "pod", "s", "directory", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L873-L882
167,256
rkt/rkt
pkg/pod/pods.go
WalkPods
func WalkPods(dataDir string, include IncludeMask, f func(*Pod)) error { if err := initPods(dataDir); err != nil { return err } ls, err := listPods(dataDir, include) if err != nil { return errwrap.Wrap(errors.New("failed to get pods"), err) } sort.Strings(ls) for _, uuid := range ls { u, err := types.NewUUID(uuid) if err != nil { fmt.Fprintf(os.Stderr, "skipping %q: %v", uuid, err) continue } p, err := getPod(dataDir, u) if err != nil { fmt.Fprintf(os.Stderr, "skipping %q: %v", uuid, err) continue } // omit pods found in unrequested states // this is to cover a race between listPods finding the uuids and pod states changing // it's preferable to keep these operations lock-free, for example a `rkt gc` shouldn't block `rkt run`. if p.isEmbryo && include&IncludeEmbryoDir == 0 || p.isExitedGarbage && include&IncludeExitedGarbageDir == 0 || p.isGarbage && include&IncludeGarbageDir == 0 || p.isPrepared && include&IncludePreparedDir == 0 || ((p.isPreparing || p.isAbortedPrepare) && include&IncludePrepareDir == 0) || p.isRunning() && include&IncludeRunDir == 0 { p.Close() continue } f(p) p.Close() } return nil }
go
func WalkPods(dataDir string, include IncludeMask, f func(*Pod)) error { if err := initPods(dataDir); err != nil { return err } ls, err := listPods(dataDir, include) if err != nil { return errwrap.Wrap(errors.New("failed to get pods"), err) } sort.Strings(ls) for _, uuid := range ls { u, err := types.NewUUID(uuid) if err != nil { fmt.Fprintf(os.Stderr, "skipping %q: %v", uuid, err) continue } p, err := getPod(dataDir, u) if err != nil { fmt.Fprintf(os.Stderr, "skipping %q: %v", uuid, err) continue } // omit pods found in unrequested states // this is to cover a race between listPods finding the uuids and pod states changing // it's preferable to keep these operations lock-free, for example a `rkt gc` shouldn't block `rkt run`. if p.isEmbryo && include&IncludeEmbryoDir == 0 || p.isExitedGarbage && include&IncludeExitedGarbageDir == 0 || p.isGarbage && include&IncludeGarbageDir == 0 || p.isPrepared && include&IncludePreparedDir == 0 || ((p.isPreparing || p.isAbortedPrepare) && include&IncludePrepareDir == 0) || p.isRunning() && include&IncludeRunDir == 0 { p.Close() continue } f(p) p.Close() } return nil }
[ "func", "WalkPods", "(", "dataDir", "string", ",", "include", "IncludeMask", ",", "f", "func", "(", "*", "Pod", ")", ")", "error", "{", "if", "err", ":=", "initPods", "(", "dataDir", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "ls", ",", "err", ":=", "listPods", "(", "dataDir", ",", "include", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "ls", ")", "\n\n", "for", "_", ",", "uuid", ":=", "range", "ls", "{", "u", ",", "err", ":=", "types", ".", "NewUUID", "(", "uuid", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\"", ",", "uuid", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "p", ",", "err", ":=", "getPod", "(", "dataDir", ",", "u", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\"", ",", "uuid", ",", "err", ")", "\n", "continue", "\n", "}", "\n\n", "// omit pods found in unrequested states", "// this is to cover a race between listPods finding the uuids and pod states changing", "// it's preferable to keep these operations lock-free, for example a `rkt gc` shouldn't block `rkt run`.", "if", "p", ".", "isEmbryo", "&&", "include", "&", "IncludeEmbryoDir", "==", "0", "||", "p", ".", "isExitedGarbage", "&&", "include", "&", "IncludeExitedGarbageDir", "==", "0", "||", "p", ".", "isGarbage", "&&", "include", "&", "IncludeGarbageDir", "==", "0", "||", "p", ".", "isPrepared", "&&", "include", "&", "IncludePreparedDir", "==", "0", "||", "(", "(", "p", ".", "isPreparing", "||", "p", ".", "isAbortedPrepare", ")", "&&", "include", "&", "IncludePrepareDir", "==", "0", ")", "||", "p", ".", "isRunning", "(", ")", "&&", "include", "&", "IncludeRunDir", "==", "0", "{", "p", ".", "Close", "(", ")", "\n", "continue", "\n", "}", "\n\n", "f", "(", "p", ")", "\n", "p", ".", "Close", "(", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// WalkPods iterates over the included directories calling function f for every pod found. // The pod will be closed after the function 'f' is executed.
[ "WalkPods", "iterates", "over", "the", "included", "directories", "calling", "function", "f", "for", "every", "pod", "found", ".", "The", "pod", "will", "be", "closed", "after", "the", "function", "f", "is", "executed", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L886-L927
167,257
rkt/rkt
pkg/pod/pods.go
PodManifest
func (p *Pod) PodManifest() ([]byte, *schema.PodManifest, error) { pmb, err := p.readFile("pod") if err != nil { return nil, nil, errwrap.Wrap(errors.New("error reading pod manifest"), err) } pm := &schema.PodManifest{} if err = pm.UnmarshalJSON(pmb); err != nil { return nil, nil, errwrap.Wrap(errors.New("invalid pod manifest"), err) } return pmb, pm, nil }
go
func (p *Pod) PodManifest() ([]byte, *schema.PodManifest, error) { pmb, err := p.readFile("pod") if err != nil { return nil, nil, errwrap.Wrap(errors.New("error reading pod manifest"), err) } pm := &schema.PodManifest{} if err = pm.UnmarshalJSON(pmb); err != nil { return nil, nil, errwrap.Wrap(errors.New("invalid pod manifest"), err) } return pmb, pm, nil }
[ "func", "(", "p", "*", "Pod", ")", "PodManifest", "(", ")", "(", "[", "]", "byte", ",", "*", "schema", ".", "PodManifest", ",", "error", ")", "{", "pmb", ",", "err", ":=", "p", ".", "readFile", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "pm", ":=", "&", "schema", ".", "PodManifest", "{", "}", "\n", "if", "err", "=", "pm", ".", "UnmarshalJSON", "(", "pmb", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "return", "pmb", ",", "pm", ",", "nil", "\n", "}" ]
// PodManifest reads the pod manifest, returns the raw bytes and the unmarshalled object.
[ "PodManifest", "reads", "the", "pod", "manifest", "returns", "the", "raw", "bytes", "and", "the", "unmarshalled", "object", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L930-L940
167,258
rkt/rkt
pkg/pod/pods.go
AppImageManifest
func (p *Pod) AppImageManifest(appName string) (*schema.ImageManifest, error) { appACName, err := types.NewACName(appName) if err != nil { return nil, err } imb, err := ioutil.ReadFile(common.AppImageManifestPath(p.Path(), *appACName)) if err != nil { return nil, err } aim := &schema.ImageManifest{} if err := aim.UnmarshalJSON(imb); err != nil { return nil, errwrap.Wrap(fmt.Errorf("invalid image manifest for app %q", appName), err) } return aim, nil }
go
func (p *Pod) AppImageManifest(appName string) (*schema.ImageManifest, error) { appACName, err := types.NewACName(appName) if err != nil { return nil, err } imb, err := ioutil.ReadFile(common.AppImageManifestPath(p.Path(), *appACName)) if err != nil { return nil, err } aim := &schema.ImageManifest{} if err := aim.UnmarshalJSON(imb); err != nil { return nil, errwrap.Wrap(fmt.Errorf("invalid image manifest for app %q", appName), err) } return aim, nil }
[ "func", "(", "p", "*", "Pod", ")", "AppImageManifest", "(", "appName", "string", ")", "(", "*", "schema", ".", "ImageManifest", ",", "error", ")", "{", "appACName", ",", "err", ":=", "types", ".", "NewACName", "(", "appName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "imb", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "common", ".", "AppImageManifestPath", "(", "p", ".", "Path", "(", ")", ",", "*", "appACName", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "aim", ":=", "&", "schema", ".", "ImageManifest", "{", "}", "\n", "if", "err", ":=", "aim", ".", "UnmarshalJSON", "(", "imb", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "appName", ")", ",", "err", ")", "\n", "}", "\n\n", "return", "aim", ",", "nil", "\n", "}" ]
// AppImageManifest returns an ImageManifest for the app.
[ "AppImageManifest", "returns", "an", "ImageManifest", "for", "the", "app", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L943-L959
167,259
rkt/rkt
pkg/pod/pods.go
CreationTime
func (p *Pod) CreationTime() (time.Time, error) { if !(p.isPrepared || p.isRunning() || p.IsAfterRun()) { return time.Time{}, nil } t, err := p.getModTime("pod-created") if err == nil { return t, nil } if !os.IsNotExist(err) { return t, err } // backwards compatibility with rkt before v1.20 return p.getModTime("pod") }
go
func (p *Pod) CreationTime() (time.Time, error) { if !(p.isPrepared || p.isRunning() || p.IsAfterRun()) { return time.Time{}, nil } t, err := p.getModTime("pod-created") if err == nil { return t, nil } if !os.IsNotExist(err) { return t, err } // backwards compatibility with rkt before v1.20 return p.getModTime("pod") }
[ "func", "(", "p", "*", "Pod", ")", "CreationTime", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "if", "!", "(", "p", ".", "isPrepared", "||", "p", ".", "isRunning", "(", ")", "||", "p", ".", "IsAfterRun", "(", ")", ")", "{", "return", "time", ".", "Time", "{", "}", ",", "nil", "\n", "}", "\n", "t", ",", "err", ":=", "p", ".", "getModTime", "(", "\"", "\"", ")", "\n", "if", "err", "==", "nil", "{", "return", "t", ",", "nil", "\n", "}", "\n", "if", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "t", ",", "err", "\n", "}", "\n", "// backwards compatibility with rkt before v1.20", "return", "p", ".", "getModTime", "(", "\"", "\"", ")", "\n", "}" ]
// CreationTime returns the time when the pod was created. // This happens at prepare time.
[ "CreationTime", "returns", "the", "time", "when", "the", "pod", "was", "created", ".", "This", "happens", "at", "prepare", "time", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L963-L976
167,260
rkt/rkt
pkg/pod/pods.go
StartTime
func (p *Pod) StartTime() (time.Time, error) { var ( t time.Time retErr error ) if !p.isRunning() && !p.IsAfterRun() { // hasn't started return t, nil } // check pid and ppid since stage1s can choose one xor the other for _, ctimeFile := range []string{"pid", "ppid"} { t, err := p.getModTime(ctimeFile) if err == nil { return t, nil } // if there's an error starting the pod, it can go to "exited" without // creating a ppid/pid file, so ignore not-exist errors. if !os.IsNotExist(err) { retErr = err } } return t, retErr }
go
func (p *Pod) StartTime() (time.Time, error) { var ( t time.Time retErr error ) if !p.isRunning() && !p.IsAfterRun() { // hasn't started return t, nil } // check pid and ppid since stage1s can choose one xor the other for _, ctimeFile := range []string{"pid", "ppid"} { t, err := p.getModTime(ctimeFile) if err == nil { return t, nil } // if there's an error starting the pod, it can go to "exited" without // creating a ppid/pid file, so ignore not-exist errors. if !os.IsNotExist(err) { retErr = err } } return t, retErr }
[ "func", "(", "p", "*", "Pod", ")", "StartTime", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "var", "(", "t", "time", ".", "Time", "\n", "retErr", "error", "\n", ")", "\n\n", "if", "!", "p", ".", "isRunning", "(", ")", "&&", "!", "p", ".", "IsAfterRun", "(", ")", "{", "// hasn't started", "return", "t", ",", "nil", "\n", "}", "\n\n", "// check pid and ppid since stage1s can choose one xor the other", "for", "_", ",", "ctimeFile", ":=", "range", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", "{", "t", ",", "err", ":=", "p", ".", "getModTime", "(", "ctimeFile", ")", "\n", "if", "err", "==", "nil", "{", "return", "t", ",", "nil", "\n", "}", "\n", "// if there's an error starting the pod, it can go to \"exited\" without", "// creating a ppid/pid file, so ignore not-exist errors.", "if", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "retErr", "=", "err", "\n", "}", "\n", "}", "\n\n", "return", "t", ",", "retErr", "\n", "}" ]
// StartTime returns the time when the pod was started.
[ "StartTime", "returns", "the", "time", "when", "the", "pod", "was", "started", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L979-L1004
167,261
rkt/rkt
pkg/pod/pods.go
GCMarkedTime
func (p *Pod) GCMarkedTime() (time.Time, error) { if !p.isGarbage && !p.isExitedGarbage { return time.Time{}, nil } // At this point, the pod is in either exited-garbage dir, garbage dir or gone already. podPath := p.Path() if podPath == "" { // Pod is gone. return time.Time{}, nil } st := &syscall.Stat_t{} if err := syscall.Lstat(podPath, st); err != nil { if err == syscall.ENOENT { // Pod is gone. err = nil } return time.Time{}, err } return time.Unix(st.Ctim.Unix()), nil }
go
func (p *Pod) GCMarkedTime() (time.Time, error) { if !p.isGarbage && !p.isExitedGarbage { return time.Time{}, nil } // At this point, the pod is in either exited-garbage dir, garbage dir or gone already. podPath := p.Path() if podPath == "" { // Pod is gone. return time.Time{}, nil } st := &syscall.Stat_t{} if err := syscall.Lstat(podPath, st); err != nil { if err == syscall.ENOENT { // Pod is gone. err = nil } return time.Time{}, err } return time.Unix(st.Ctim.Unix()), nil }
[ "func", "(", "p", "*", "Pod", ")", "GCMarkedTime", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "if", "!", "p", ".", "isGarbage", "&&", "!", "p", ".", "isExitedGarbage", "{", "return", "time", ".", "Time", "{", "}", ",", "nil", "\n", "}", "\n\n", "// At this point, the pod is in either exited-garbage dir, garbage dir or gone already.", "podPath", ":=", "p", ".", "Path", "(", ")", "\n", "if", "podPath", "==", "\"", "\"", "{", "// Pod is gone.", "return", "time", ".", "Time", "{", "}", ",", "nil", "\n", "}", "\n\n", "st", ":=", "&", "syscall", ".", "Stat_t", "{", "}", "\n", "if", "err", ":=", "syscall", ".", "Lstat", "(", "podPath", ",", "st", ")", ";", "err", "!=", "nil", "{", "if", "err", "==", "syscall", ".", "ENOENT", "{", "// Pod is gone.", "err", "=", "nil", "\n", "}", "\n", "return", "time", ".", "Time", "{", "}", ",", "err", "\n", "}", "\n", "return", "time", ".", "Unix", "(", "st", ".", "Ctim", ".", "Unix", "(", ")", ")", ",", "nil", "\n", "}" ]
// GCMarkedTime returns the time when the pod is marked by gc.
[ "GCMarkedTime", "returns", "the", "time", "when", "the", "pod", "is", "marked", "by", "gc", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L1007-L1028
167,262
rkt/rkt
pkg/pod/pods.go
Pid
func (p *Pod) Pid() (int, error) { if pid, err := p.readIntFromFile("pid"); err == nil { return pid, nil } if pid, err := p.readIntFromFile("ppid"); err != nil { return -1, err } else { return pid, nil } }
go
func (p *Pod) Pid() (int, error) { if pid, err := p.readIntFromFile("pid"); err == nil { return pid, nil } if pid, err := p.readIntFromFile("ppid"); err != nil { return -1, err } else { return pid, nil } }
[ "func", "(", "p", "*", "Pod", ")", "Pid", "(", ")", "(", "int", ",", "error", ")", "{", "if", "pid", ",", "err", ":=", "p", ".", "readIntFromFile", "(", "\"", "\"", ")", ";", "err", "==", "nil", "{", "return", "pid", ",", "nil", "\n", "}", "\n", "if", "pid", ",", "err", ":=", "p", ".", "readIntFromFile", "(", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "else", "{", "return", "pid", ",", "nil", "\n", "}", "\n", "}" ]
// Pid returns the pid of the stage1 process that started the pod.
[ "Pid", "returns", "the", "pid", "of", "the", "stage1", "process", "that", "started", "the", "pod", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L1031-L1040
167,263
rkt/rkt
pkg/pod/pods.go
Stage1RootfsPath
func (p *Pod) Stage1RootfsPath() (string, error) { stage1RootfsPath := "stage1/rootfs" if p.UsesOverlay() { stage1TreeStoreID, err := p.GetStage1TreeStoreID() if err != nil { return "", err } stage1RootfsPath = fmt.Sprintf("overlay/%s/upper/", stage1TreeStoreID) } return filepath.Join(p.Path(), stage1RootfsPath), nil }
go
func (p *Pod) Stage1RootfsPath() (string, error) { stage1RootfsPath := "stage1/rootfs" if p.UsesOverlay() { stage1TreeStoreID, err := p.GetStage1TreeStoreID() if err != nil { return "", err } stage1RootfsPath = fmt.Sprintf("overlay/%s/upper/", stage1TreeStoreID) } return filepath.Join(p.Path(), stage1RootfsPath), nil }
[ "func", "(", "p", "*", "Pod", ")", "Stage1RootfsPath", "(", ")", "(", "string", ",", "error", ")", "{", "stage1RootfsPath", ":=", "\"", "\"", "\n", "if", "p", ".", "UsesOverlay", "(", ")", "{", "stage1TreeStoreID", ",", "err", ":=", "p", ".", "GetStage1TreeStoreID", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "stage1RootfsPath", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "stage1TreeStoreID", ")", "\n", "}", "\n\n", "return", "filepath", ".", "Join", "(", "p", ".", "Path", "(", ")", ",", "stage1RootfsPath", ")", ",", "nil", "\n", "}" ]
// Stage1RootfsPath returns the stage1 path of the pod.
[ "Stage1RootfsPath", "returns", "the", "stage1", "path", "of", "the", "pod", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L1125-L1136
167,264
rkt/rkt
pkg/pod/pods.go
JournalLogPath
func (p *Pod) JournalLogPath() (string, error) { stage1RootfsPath, err := p.Stage1RootfsPath() if err != nil { return "", err } return filepath.Join(stage1RootfsPath, "/var/log/journal/"), nil }
go
func (p *Pod) JournalLogPath() (string, error) { stage1RootfsPath, err := p.Stage1RootfsPath() if err != nil { return "", err } return filepath.Join(stage1RootfsPath, "/var/log/journal/"), nil }
[ "func", "(", "p", "*", "Pod", ")", "JournalLogPath", "(", ")", "(", "string", ",", "error", ")", "{", "stage1RootfsPath", ",", "err", ":=", "p", ".", "Stage1RootfsPath", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "filepath", ".", "Join", "(", "stage1RootfsPath", ",", "\"", "\"", ")", ",", "nil", "\n", "}" ]
// JournalLogPath returns the path to the journal log dir of the pod.
[ "JournalLogPath", "returns", "the", "path", "to", "the", "journal", "log", "dir", "of", "the", "pod", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L1139-L1145
167,265
rkt/rkt
pkg/pod/pods.go
State
func (p *Pod) State() string { switch { case p.isEmbryo: return Embryo case p.isPreparing: return Preparing case p.isAbortedPrepare: return AbortedPrepare case p.isPrepared: return Prepared case p.isDeleting: return Deleting case p.isExitedDeleting: return ExitedDeleting case p.isExited: // this covers p.isExitedGarbage if p.isExitedGarbage { return ExitedGarbage } return Exited case p.isGarbage: return Garbage } return Running }
go
func (p *Pod) State() string { switch { case p.isEmbryo: return Embryo case p.isPreparing: return Preparing case p.isAbortedPrepare: return AbortedPrepare case p.isPrepared: return Prepared case p.isDeleting: return Deleting case p.isExitedDeleting: return ExitedDeleting case p.isExited: // this covers p.isExitedGarbage if p.isExitedGarbage { return ExitedGarbage } return Exited case p.isGarbage: return Garbage } return Running }
[ "func", "(", "p", "*", "Pod", ")", "State", "(", ")", "string", "{", "switch", "{", "case", "p", ".", "isEmbryo", ":", "return", "Embryo", "\n", "case", "p", ".", "isPreparing", ":", "return", "Preparing", "\n", "case", "p", ".", "isAbortedPrepare", ":", "return", "AbortedPrepare", "\n", "case", "p", ".", "isPrepared", ":", "return", "Prepared", "\n", "case", "p", ".", "isDeleting", ":", "return", "Deleting", "\n", "case", "p", ".", "isExitedDeleting", ":", "return", "ExitedDeleting", "\n", "case", "p", ".", "isExited", ":", "// this covers p.isExitedGarbage", "if", "p", ".", "isExitedGarbage", "{", "return", "ExitedGarbage", "\n", "}", "\n", "return", "Exited", "\n", "case", "p", ".", "isGarbage", ":", "return", "Garbage", "\n", "}", "\n\n", "return", "Running", "\n", "}" ]
// State returns the current state of the pod
[ "State", "returns", "the", "current", "state", "of", "the", "pod" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L1148-L1172
167,266
rkt/rkt
pkg/pod/pods.go
isRunning
func (p *Pod) isRunning() bool { // when none of these things, running! return !p.isEmbryo && !p.isAbortedPrepare && !p.isPreparing && !p.isPrepared && !p.isExited && !p.isExitedGarbage && !p.isExitedDeleting && !p.isGarbage && !p.isDeleting && !p.isGone }
go
func (p *Pod) isRunning() bool { // when none of these things, running! return !p.isEmbryo && !p.isAbortedPrepare && !p.isPreparing && !p.isPrepared && !p.isExited && !p.isExitedGarbage && !p.isExitedDeleting && !p.isGarbage && !p.isDeleting && !p.isGone }
[ "func", "(", "p", "*", "Pod", ")", "isRunning", "(", ")", "bool", "{", "// when none of these things, running!", "return", "!", "p", ".", "isEmbryo", "&&", "!", "p", ".", "isAbortedPrepare", "&&", "!", "p", ".", "isPreparing", "&&", "!", "p", ".", "isPrepared", "&&", "!", "p", ".", "isExited", "&&", "!", "p", ".", "isExitedGarbage", "&&", "!", "p", ".", "isExitedDeleting", "&&", "!", "p", ".", "isGarbage", "&&", "!", "p", ".", "isDeleting", "&&", "!", "p", ".", "isGone", "\n", "}" ]
// isRunning does the annoying tests to infer if a pod is in a running state
[ "isRunning", "does", "the", "annoying", "tests", "to", "infer", "if", "a", "pod", "is", "in", "a", "running", "state" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L1175-L1179
167,267
rkt/rkt
pkg/pod/pods.go
PodManifestAvailable
func (p *Pod) PodManifestAvailable() bool { if p.isPreparing || p.isAbortedPrepare || p.isDeleting { return false } return true }
go
func (p *Pod) PodManifestAvailable() bool { if p.isPreparing || p.isAbortedPrepare || p.isDeleting { return false } return true }
[ "func", "(", "p", "*", "Pod", ")", "PodManifestAvailable", "(", ")", "bool", "{", "if", "p", ".", "isPreparing", "||", "p", ".", "isAbortedPrepare", "||", "p", ".", "isDeleting", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// PodManifestAvailable returns whether the caller should reasonably expect // PodManifest to function in the pod's current state. // Namely, in Preparing, AbortedPrepare, and Deleting it's possible for the // manifest to not be present
[ "PodManifestAvailable", "returns", "whether", "the", "caller", "should", "reasonably", "expect", "PodManifest", "to", "function", "in", "the", "pod", "s", "current", "state", ".", "Namely", "in", "Preparing", "AbortedPrepare", "and", "Deleting", "it", "s", "possible", "for", "the", "manifest", "to", "not", "be", "present" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L1185-L1190
167,268
rkt/rkt
pkg/pod/pods.go
IsAfterRun
func (p *Pod) IsAfterRun() bool { return p.isExitedDeleting || p.isDeleting || p.isExited || p.isGarbage }
go
func (p *Pod) IsAfterRun() bool { return p.isExitedDeleting || p.isDeleting || p.isExited || p.isGarbage }
[ "func", "(", "p", "*", "Pod", ")", "IsAfterRun", "(", ")", "bool", "{", "return", "p", ".", "isExitedDeleting", "||", "p", ".", "isDeleting", "||", "p", ".", "isExited", "||", "p", ".", "isGarbage", "\n", "}" ]
// IsAfterRun returns true if the pod is in a post-running state, otherwise it returns false.
[ "IsAfterRun", "returns", "true", "if", "the", "pod", "is", "in", "a", "post", "-", "running", "state", "otherwise", "it", "returns", "false", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L1193-L1195
167,269
rkt/rkt
pkg/pod/pods.go
IsFinished
func (p *Pod) IsFinished() bool { return p.isExited || p.isAbortedPrepare || p.isGarbage || p.isGone }
go
func (p *Pod) IsFinished() bool { return p.isExited || p.isAbortedPrepare || p.isGarbage || p.isGone }
[ "func", "(", "p", "*", "Pod", ")", "IsFinished", "(", ")", "bool", "{", "return", "p", ".", "isExited", "||", "p", ".", "isAbortedPrepare", "||", "p", ".", "isGarbage", "||", "p", ".", "isGone", "\n", "}" ]
// IsFinished returns true if the pod is in a terminal state, else false.
[ "IsFinished", "returns", "true", "if", "the", "pod", "is", "in", "a", "terminal", "state", "else", "false", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L1198-L1200
167,270
rkt/rkt
pkg/pod/pods.go
AppExitCode
func (p *Pod) AppExitCode(appName string) (int, error) { stage1RootfsPath, err := p.Stage1RootfsPath() if err != nil { return -1, err } statusFile := common.AppStatusPathFromStage1Rootfs(stage1RootfsPath, appName) return p.readIntFromFile(statusFile) }
go
func (p *Pod) AppExitCode(appName string) (int, error) { stage1RootfsPath, err := p.Stage1RootfsPath() if err != nil { return -1, err } statusFile := common.AppStatusPathFromStage1Rootfs(stage1RootfsPath, appName) return p.readIntFromFile(statusFile) }
[ "func", "(", "p", "*", "Pod", ")", "AppExitCode", "(", "appName", "string", ")", "(", "int", ",", "error", ")", "{", "stage1RootfsPath", ",", "err", ":=", "p", ".", "Stage1RootfsPath", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "statusFile", ":=", "common", ".", "AppStatusPathFromStage1Rootfs", "(", "stage1RootfsPath", ",", "appName", ")", "\n", "return", "p", ".", "readIntFromFile", "(", "statusFile", ")", "\n", "}" ]
// AppExitCode returns the app's exit code. // It returns an error if the exit code file doesn't exit or the content of the file is invalid.
[ "AppExitCode", "returns", "the", "app", "s", "exit", "code", ".", "It", "returns", "an", "error", "if", "the", "exit", "code", "file", "doesn", "t", "exit", "or", "the", "content", "of", "the", "file", "is", "invalid", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/pod/pods.go#L1209-L1217
167,271
rkt/rkt
stage0/stop.go
StopPod
func StopPod(dir string, force bool, uuid *types.UUID) error { s1rootfs := common.Stage1RootfsPath(dir) if err := os.Chdir(dir); err != nil { return fmt.Errorf("failed changing to dir: %v", err) } ep, err := getStage1Entrypoint(dir, stopEntrypoint) if err != nil { return fmt.Errorf("rkt stop not implemented for pod's stage1: %v", err) } args := []string{filepath.Join(s1rootfs, ep)} debug("Execing %s", ep) if force { args = append(args, "--force") } args = append(args, uuid.String()) c := exec.Cmd{ Path: args[0], Args: args, Stdout: os.Stdout, Stderr: os.Stderr, } return c.Run() }
go
func StopPod(dir string, force bool, uuid *types.UUID) error { s1rootfs := common.Stage1RootfsPath(dir) if err := os.Chdir(dir); err != nil { return fmt.Errorf("failed changing to dir: %v", err) } ep, err := getStage1Entrypoint(dir, stopEntrypoint) if err != nil { return fmt.Errorf("rkt stop not implemented for pod's stage1: %v", err) } args := []string{filepath.Join(s1rootfs, ep)} debug("Execing %s", ep) if force { args = append(args, "--force") } args = append(args, uuid.String()) c := exec.Cmd{ Path: args[0], Args: args, Stdout: os.Stdout, Stderr: os.Stderr, } return c.Run() }
[ "func", "StopPod", "(", "dir", "string", ",", "force", "bool", ",", "uuid", "*", "types", ".", "UUID", ")", "error", "{", "s1rootfs", ":=", "common", ".", "Stage1RootfsPath", "(", "dir", ")", "\n\n", "if", "err", ":=", "os", ".", "Chdir", "(", "dir", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "ep", ",", "err", ":=", "getStage1Entrypoint", "(", "dir", ",", "stopEntrypoint", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "args", ":=", "[", "]", "string", "{", "filepath", ".", "Join", "(", "s1rootfs", ",", "ep", ")", "}", "\n", "debug", "(", "\"", "\"", ",", "ep", ")", "\n\n", "if", "force", "{", "args", "=", "append", "(", "args", ",", "\"", "\"", ")", "\n", "}", "\n\n", "args", "=", "append", "(", "args", ",", "uuid", ".", "String", "(", ")", ")", "\n\n", "c", ":=", "exec", ".", "Cmd", "{", "Path", ":", "args", "[", "0", "]", ",", "Args", ":", "args", ",", "Stdout", ":", "os", ".", "Stdout", ",", "Stderr", ":", "os", ".", "Stderr", ",", "}", "\n\n", "return", "c", ".", "Run", "(", ")", "\n", "}" ]
// StopPod stops the given pod.
[ "StopPod", "stops", "the", "given", "pod", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage0/stop.go#L31-L59
167,272
rkt/rkt
rkt/config/config.go
MarshalJSON
func (c *Config) MarshalJSON() ([]byte, error) { stage0 := []interface{}{} for host, auth := range c.AuthPerHost { var typ string var credentials interface{} switch h := auth.(type) { case *basicAuthHeaderer: typ = "basic" credentials = h.auth case *oAuthBearerTokenHeaderer: typ = "oauth" credentials = h.auth case *awsAuthHeaderer: typ = "aws" credentials = h.auth default: return nil, errors.New("unknown headerer type") } auth := struct { RktVersion string `json:"rktVersion"` RktKind string `json:"rktKind"` Domains []string `json:"domains"` Type string `json:"type"` Credentials interface{} `json:"credentials"` }{ RktVersion: "v1", RktKind: "auth", Domains: []string{host}, Type: typ, Credentials: credentials, } stage0 = append(stage0, auth) } for registry, credentials := range c.DockerCredentialsPerRegistry { dockerAuth := struct { RktVersion string `json:"rktVersion"` RktKind string `json:"rktKind"` Registries []string `json:"registries"` Credentials BasicCredentials `json:"credentials"` }{ RktVersion: "v1", RktKind: "dockerAuth", Registries: []string{registry}, Credentials: credentials, } stage0 = append(stage0, dockerAuth) } paths := struct { RktVersion string `json:"rktVersion"` RktKind string `json:"rktKind"` Data string `json:"data"` Stage1Images string `json:"stage1-images"` }{ RktVersion: "v1", RktKind: "paths", Data: c.Paths.DataDir, Stage1Images: c.Paths.Stage1ImagesDir, } stage1 := struct { RktVersion string `json:"rktVersion"` RktKind string `json:"rktKind"` Name string `json:"name"` Version string `json:"version"` Location string `json:"location"` }{ RktVersion: "v1", RktKind: "stage1", Name: c.Stage1.Name, Version: c.Stage1.Version, Location: c.Stage1.Location, } stage0 = append(stage0, paths, stage1) data := map[string]interface{}{"stage0": stage0} return json.Marshal(data) }
go
func (c *Config) MarshalJSON() ([]byte, error) { stage0 := []interface{}{} for host, auth := range c.AuthPerHost { var typ string var credentials interface{} switch h := auth.(type) { case *basicAuthHeaderer: typ = "basic" credentials = h.auth case *oAuthBearerTokenHeaderer: typ = "oauth" credentials = h.auth case *awsAuthHeaderer: typ = "aws" credentials = h.auth default: return nil, errors.New("unknown headerer type") } auth := struct { RktVersion string `json:"rktVersion"` RktKind string `json:"rktKind"` Domains []string `json:"domains"` Type string `json:"type"` Credentials interface{} `json:"credentials"` }{ RktVersion: "v1", RktKind: "auth", Domains: []string{host}, Type: typ, Credentials: credentials, } stage0 = append(stage0, auth) } for registry, credentials := range c.DockerCredentialsPerRegistry { dockerAuth := struct { RktVersion string `json:"rktVersion"` RktKind string `json:"rktKind"` Registries []string `json:"registries"` Credentials BasicCredentials `json:"credentials"` }{ RktVersion: "v1", RktKind: "dockerAuth", Registries: []string{registry}, Credentials: credentials, } stage0 = append(stage0, dockerAuth) } paths := struct { RktVersion string `json:"rktVersion"` RktKind string `json:"rktKind"` Data string `json:"data"` Stage1Images string `json:"stage1-images"` }{ RktVersion: "v1", RktKind: "paths", Data: c.Paths.DataDir, Stage1Images: c.Paths.Stage1ImagesDir, } stage1 := struct { RktVersion string `json:"rktVersion"` RktKind string `json:"rktKind"` Name string `json:"name"` Version string `json:"version"` Location string `json:"location"` }{ RktVersion: "v1", RktKind: "stage1", Name: c.Stage1.Name, Version: c.Stage1.Version, Location: c.Stage1.Location, } stage0 = append(stage0, paths, stage1) data := map[string]interface{}{"stage0": stage0} return json.Marshal(data) }
[ "func", "(", "c", "*", "Config", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "stage0", ":=", "[", "]", "interface", "{", "}", "{", "}", "\n\n", "for", "host", ",", "auth", ":=", "range", "c", ".", "AuthPerHost", "{", "var", "typ", "string", "\n", "var", "credentials", "interface", "{", "}", "\n\n", "switch", "h", ":=", "auth", ".", "(", "type", ")", "{", "case", "*", "basicAuthHeaderer", ":", "typ", "=", "\"", "\"", "\n", "credentials", "=", "h", ".", "auth", "\n", "case", "*", "oAuthBearerTokenHeaderer", ":", "typ", "=", "\"", "\"", "\n", "credentials", "=", "h", ".", "auth", "\n", "case", "*", "awsAuthHeaderer", ":", "typ", "=", "\"", "\"", "\n", "credentials", "=", "h", ".", "auth", "\n", "default", ":", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "auth", ":=", "struct", "{", "RktVersion", "string", "`json:\"rktVersion\"`", "\n", "RktKind", "string", "`json:\"rktKind\"`", "\n", "Domains", "[", "]", "string", "`json:\"domains\"`", "\n", "Type", "string", "`json:\"type\"`", "\n", "Credentials", "interface", "{", "}", "`json:\"credentials\"`", "\n", "}", "{", "RktVersion", ":", "\"", "\"", ",", "RktKind", ":", "\"", "\"", ",", "Domains", ":", "[", "]", "string", "{", "host", "}", ",", "Type", ":", "typ", ",", "Credentials", ":", "credentials", ",", "}", "\n\n", "stage0", "=", "append", "(", "stage0", ",", "auth", ")", "\n", "}", "\n\n", "for", "registry", ",", "credentials", ":=", "range", "c", ".", "DockerCredentialsPerRegistry", "{", "dockerAuth", ":=", "struct", "{", "RktVersion", "string", "`json:\"rktVersion\"`", "\n", "RktKind", "string", "`json:\"rktKind\"`", "\n", "Registries", "[", "]", "string", "`json:\"registries\"`", "\n", "Credentials", "BasicCredentials", "`json:\"credentials\"`", "\n", "}", "{", "RktVersion", ":", "\"", "\"", ",", "RktKind", ":", "\"", "\"", ",", "Registries", ":", "[", "]", "string", "{", "registry", "}", ",", "Credentials", ":", "credentials", ",", "}", "\n\n", "stage0", "=", "append", "(", "stage0", ",", "dockerAuth", ")", "\n", "}", "\n\n", "paths", ":=", "struct", "{", "RktVersion", "string", "`json:\"rktVersion\"`", "\n", "RktKind", "string", "`json:\"rktKind\"`", "\n", "Data", "string", "`json:\"data\"`", "\n", "Stage1Images", "string", "`json:\"stage1-images\"`", "\n", "}", "{", "RktVersion", ":", "\"", "\"", ",", "RktKind", ":", "\"", "\"", ",", "Data", ":", "c", ".", "Paths", ".", "DataDir", ",", "Stage1Images", ":", "c", ".", "Paths", ".", "Stage1ImagesDir", ",", "}", "\n\n", "stage1", ":=", "struct", "{", "RktVersion", "string", "`json:\"rktVersion\"`", "\n", "RktKind", "string", "`json:\"rktKind\"`", "\n", "Name", "string", "`json:\"name\"`", "\n", "Version", "string", "`json:\"version\"`", "\n", "Location", "string", "`json:\"location\"`", "\n", "}", "{", "RktVersion", ":", "\"", "\"", ",", "RktKind", ":", "\"", "\"", ",", "Name", ":", "c", ".", "Stage1", ".", "Name", ",", "Version", ":", "c", ".", "Stage1", ".", "Version", ",", "Location", ":", "c", ".", "Stage1", ".", "Location", ",", "}", "\n\n", "stage0", "=", "append", "(", "stage0", ",", "paths", ",", "stage1", ")", "\n\n", "data", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "stage0", "}", "\n", "return", "json", ".", "Marshal", "(", "data", ")", "\n", "}" ]
// MarshalJSON marshals the config for user output.
[ "MarshalJSON", "marshals", "the", "config", "for", "user", "output", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/config/config.go#L70-L154
167,273
rkt/rkt
rkt/config/config.go
ResolveAuthPerHost
func ResolveAuthPerHost(authPerHost map[string]Headerer) map[string]http.Header { hostHeaders := make(map[string]http.Header, len(authPerHost)) for k, v := range authPerHost { hostHeaders[k] = v.GetHeader() } return hostHeaders }
go
func ResolveAuthPerHost(authPerHost map[string]Headerer) map[string]http.Header { hostHeaders := make(map[string]http.Header, len(authPerHost)) for k, v := range authPerHost { hostHeaders[k] = v.GetHeader() } return hostHeaders }
[ "func", "ResolveAuthPerHost", "(", "authPerHost", "map", "[", "string", "]", "Headerer", ")", "map", "[", "string", "]", "http", ".", "Header", "{", "hostHeaders", ":=", "make", "(", "map", "[", "string", "]", "http", ".", "Header", ",", "len", "(", "authPerHost", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "authPerHost", "{", "hostHeaders", "[", "k", "]", "=", "v", ".", "GetHeader", "(", ")", "\n", "}", "\n", "return", "hostHeaders", "\n", "}" ]
// ResolveAuthPerHost takes a map of strings to Headerer and resolves the // Headerers to http.Headers
[ "ResolveAuthPerHost", "takes", "a", "map", "of", "strings", "to", "Headerer", "and", "resolves", "the", "Headerers", "to", "http", ".", "Headers" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/config/config.go#L169-L175
167,274
rkt/rkt
rkt/config/config.go
GetConfigFrom
func GetConfigFrom(dirs ...string) (*Config, error) { cfg := newConfig() for _, cd := range dirs { subcfg, err := GetConfigFromDir(cd) if err != nil { return nil, err } mergeConfigs(cfg, subcfg) } return cfg, nil }
go
func GetConfigFrom(dirs ...string) (*Config, error) { cfg := newConfig() for _, cd := range dirs { subcfg, err := GetConfigFromDir(cd) if err != nil { return nil, err } mergeConfigs(cfg, subcfg) } return cfg, nil }
[ "func", "GetConfigFrom", "(", "dirs", "...", "string", ")", "(", "*", "Config", ",", "error", ")", "{", "cfg", ":=", "newConfig", "(", ")", "\n", "for", "_", ",", "cd", ":=", "range", "dirs", "{", "subcfg", ",", "err", ":=", "GetConfigFromDir", "(", "cd", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "mergeConfigs", "(", "cfg", ",", "subcfg", ")", "\n", "}", "\n", "return", "cfg", ",", "nil", "\n", "}" ]
// GetConfigFrom gets the Config instance with configuration taken // from given paths. Subsequent paths override settings from the // previous paths.
[ "GetConfigFrom", "gets", "the", "Config", "instance", "with", "configuration", "taken", "from", "given", "paths", ".", "Subsequent", "paths", "override", "settings", "from", "the", "previous", "paths", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/config/config.go#L235-L245
167,275
rkt/rkt
rkt/config/config.go
GetConfigFromDir
func GetConfigFromDir(dir string) (*Config, error) { subcfg := newConfig() if valid, err := validDir(dir); err != nil { return nil, err } else if !valid { return subcfg, nil } if err := readConfigDir(subcfg, dir); err != nil { return nil, err } return subcfg, nil }
go
func GetConfigFromDir(dir string) (*Config, error) { subcfg := newConfig() if valid, err := validDir(dir); err != nil { return nil, err } else if !valid { return subcfg, nil } if err := readConfigDir(subcfg, dir); err != nil { return nil, err } return subcfg, nil }
[ "func", "GetConfigFromDir", "(", "dir", "string", ")", "(", "*", "Config", ",", "error", ")", "{", "subcfg", ":=", "newConfig", "(", ")", "\n", "if", "valid", ",", "err", ":=", "validDir", "(", "dir", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "else", "if", "!", "valid", "{", "return", "subcfg", ",", "nil", "\n", "}", "\n", "if", "err", ":=", "readConfigDir", "(", "subcfg", ",", "dir", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "subcfg", ",", "nil", "\n", "}" ]
// GetConfigFromDir gets the Config instance with configuration taken // from given directory.
[ "GetConfigFromDir", "gets", "the", "Config", "instance", "with", "configuration", "taken", "from", "given", "directory", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/config/config.go#L249-L260
167,276
rkt/rkt
common/environment.go
WriteEnvFile
func WriteEnvFile(env []string, uidRange *user.UidRange, envFilePath string) error { ef := bytes.Buffer{} for _, v := range env { fmt.Fprintf(&ef, "%s\n", v) } if err := os.MkdirAll(filepath.Dir(envFilePath), 0755); err != nil { return err } if err := ioutil.WriteFile(envFilePath, ef.Bytes(), 0644); err != nil { return err } if err := user.ShiftFiles([]string{envFilePath}, uidRange); err != nil { return err } return nil }
go
func WriteEnvFile(env []string, uidRange *user.UidRange, envFilePath string) error { ef := bytes.Buffer{} for _, v := range env { fmt.Fprintf(&ef, "%s\n", v) } if err := os.MkdirAll(filepath.Dir(envFilePath), 0755); err != nil { return err } if err := ioutil.WriteFile(envFilePath, ef.Bytes(), 0644); err != nil { return err } if err := user.ShiftFiles([]string{envFilePath}, uidRange); err != nil { return err } return nil }
[ "func", "WriteEnvFile", "(", "env", "[", "]", "string", ",", "uidRange", "*", "user", ".", "UidRange", ",", "envFilePath", "string", ")", "error", "{", "ef", ":=", "bytes", ".", "Buffer", "{", "}", "\n\n", "for", "_", ",", "v", ":=", "range", "env", "{", "fmt", ".", "Fprintf", "(", "&", "ef", ",", "\"", "\\n", "\"", ",", "v", ")", "\n", "}", "\n\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "filepath", ".", "Dir", "(", "envFilePath", ")", ",", "0755", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "envFilePath", ",", "ef", ".", "Bytes", "(", ")", ",", "0644", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "user", ".", "ShiftFiles", "(", "[", "]", "string", "{", "envFilePath", "}", ",", "uidRange", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// WriteEnvFile creates an environment file for given app name. To // ensure the minimum required environment variables by the appc spec // are set to sensible defaults, env should be the result of calling // ComposeEnviron. The containing directory and its ancestors will be // created if necessary.
[ "WriteEnvFile", "creates", "an", "environment", "file", "for", "given", "app", "name", ".", "To", "ensure", "the", "minimum", "required", "environment", "variables", "by", "the", "appc", "spec", "are", "set", "to", "sensible", "defaults", "env", "should", "be", "the", "result", "of", "calling", "ComposeEnviron", ".", "The", "containing", "directory", "and", "its", "ancestors", "will", "be", "created", "if", "necessary", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/environment.go#L45-L65
167,277
rkt/rkt
common/environment.go
ComposeEnviron
func ComposeEnviron(env types.Environment) []string { var composed []string for dk, dv := range defaultEnv { if _, exists := env.Get(dk); !exists { composed = append(composed, fmt.Sprintf("%s=%s", dk, dv)) } } for _, e := range env { composed = append(composed, fmt.Sprintf("%s=%s", e.Name, e.Value)) } return composed }
go
func ComposeEnviron(env types.Environment) []string { var composed []string for dk, dv := range defaultEnv { if _, exists := env.Get(dk); !exists { composed = append(composed, fmt.Sprintf("%s=%s", dk, dv)) } } for _, e := range env { composed = append(composed, fmt.Sprintf("%s=%s", e.Name, e.Value)) } return composed }
[ "func", "ComposeEnviron", "(", "env", "types", ".", "Environment", ")", "[", "]", "string", "{", "var", "composed", "[", "]", "string", "\n\n", "for", "dk", ",", "dv", ":=", "range", "defaultEnv", "{", "if", "_", ",", "exists", ":=", "env", ".", "Get", "(", "dk", ")", ";", "!", "exists", "{", "composed", "=", "append", "(", "composed", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dk", ",", "dv", ")", ")", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "e", ":=", "range", "env", "{", "composed", "=", "append", "(", "composed", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "Name", ",", "e", ".", "Value", ")", ")", "\n", "}", "\n", "return", "composed", "\n", "}" ]
// ComposeEnviron formats the environment into a slice of strings, // each of the form "key=value". The minimum required environment // variables by the appc spec will be set to sensible defaults here if // they're not provided by env.
[ "ComposeEnviron", "formats", "the", "environment", "into", "a", "slice", "of", "strings", "each", "of", "the", "form", "key", "=", "value", ".", "The", "minimum", "required", "environment", "variables", "by", "the", "appc", "spec", "will", "be", "set", "to", "sensible", "defaults", "here", "if", "they", "re", "not", "provided", "by", "env", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/environment.go#L94-L107
167,278
rkt/rkt
pkg/fs/mount_linux.go
String
func (f mountFlags) String() string { var s []string maybeAppendFlag := func(ff uintptr, desc string) { if uintptr(f)&ff != 0 { s = append(s, desc) } } maybeAppendFlag(syscall.MS_DIRSYNC, "MS_DIRSYNC") maybeAppendFlag(syscall.MS_MANDLOCK, "MS_MANDLOCK") maybeAppendFlag(syscall.MS_NOATIME, "MS_NOATIME") maybeAppendFlag(syscall.MS_NODEV, "MS_NODEV") maybeAppendFlag(syscall.MS_NODIRATIME, "MS_NODIRATIME") maybeAppendFlag(syscall.MS_NOEXEC, "MS_NOEXEC") maybeAppendFlag(syscall.MS_NOSUID, "MS_NOSUID") maybeAppendFlag(syscall.MS_RDONLY, "MS_RDONLY") maybeAppendFlag(syscall.MS_REC, "MS_REC") maybeAppendFlag(syscall.MS_RELATIME, "MS_RELATIME") maybeAppendFlag(syscall.MS_SILENT, "MS_SILENT") maybeAppendFlag(syscall.MS_STRICTATIME, "MS_STRICTATIME") maybeAppendFlag(syscall.MS_SYNCHRONOUS, "MS_SYNCHRONOUS") maybeAppendFlag(syscall.MS_REMOUNT, "MS_REMOUNT") maybeAppendFlag(syscall.MS_BIND, "MS_BIND") maybeAppendFlag(syscall.MS_SHARED, "MS_SHARED") maybeAppendFlag(syscall.MS_PRIVATE, "MS_PRIVATE") maybeAppendFlag(syscall.MS_SLAVE, "MS_SLAVE") maybeAppendFlag(syscall.MS_UNBINDABLE, "MS_UNBINDABLE") maybeAppendFlag(syscall.MS_MOVE, "MS_MOVE") return strings.Join(s, "|") }
go
func (f mountFlags) String() string { var s []string maybeAppendFlag := func(ff uintptr, desc string) { if uintptr(f)&ff != 0 { s = append(s, desc) } } maybeAppendFlag(syscall.MS_DIRSYNC, "MS_DIRSYNC") maybeAppendFlag(syscall.MS_MANDLOCK, "MS_MANDLOCK") maybeAppendFlag(syscall.MS_NOATIME, "MS_NOATIME") maybeAppendFlag(syscall.MS_NODEV, "MS_NODEV") maybeAppendFlag(syscall.MS_NODIRATIME, "MS_NODIRATIME") maybeAppendFlag(syscall.MS_NOEXEC, "MS_NOEXEC") maybeAppendFlag(syscall.MS_NOSUID, "MS_NOSUID") maybeAppendFlag(syscall.MS_RDONLY, "MS_RDONLY") maybeAppendFlag(syscall.MS_REC, "MS_REC") maybeAppendFlag(syscall.MS_RELATIME, "MS_RELATIME") maybeAppendFlag(syscall.MS_SILENT, "MS_SILENT") maybeAppendFlag(syscall.MS_STRICTATIME, "MS_STRICTATIME") maybeAppendFlag(syscall.MS_SYNCHRONOUS, "MS_SYNCHRONOUS") maybeAppendFlag(syscall.MS_REMOUNT, "MS_REMOUNT") maybeAppendFlag(syscall.MS_BIND, "MS_BIND") maybeAppendFlag(syscall.MS_SHARED, "MS_SHARED") maybeAppendFlag(syscall.MS_PRIVATE, "MS_PRIVATE") maybeAppendFlag(syscall.MS_SLAVE, "MS_SLAVE") maybeAppendFlag(syscall.MS_UNBINDABLE, "MS_UNBINDABLE") maybeAppendFlag(syscall.MS_MOVE, "MS_MOVE") return strings.Join(s, "|") }
[ "func", "(", "f", "mountFlags", ")", "String", "(", ")", "string", "{", "var", "s", "[", "]", "string", "\n\n", "maybeAppendFlag", ":=", "func", "(", "ff", "uintptr", ",", "desc", "string", ")", "{", "if", "uintptr", "(", "f", ")", "&", "ff", "!=", "0", "{", "s", "=", "append", "(", "s", ",", "desc", ")", "\n", "}", "\n", "}", "\n\n", "maybeAppendFlag", "(", "syscall", ".", "MS_DIRSYNC", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_MANDLOCK", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_NOATIME", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_NODEV", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_NODIRATIME", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_NOEXEC", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_NOSUID", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_RDONLY", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_REC", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_RELATIME", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_SILENT", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_STRICTATIME", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_SYNCHRONOUS", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_REMOUNT", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_BIND", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_SHARED", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_PRIVATE", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_SLAVE", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_UNBINDABLE", ",", "\"", "\"", ")", "\n", "maybeAppendFlag", "(", "syscall", ".", "MS_MOVE", ",", "\"", "\"", ")", "\n\n", "return", "strings", ".", "Join", "(", "s", ",", "\"", "\"", ")", "\n", "}" ]
// String returns a human readable representation of mountFlags based on which bits are set. // E.g. for a value of syscall.MS_RDONLY|syscall.MS_BIND it will print "MS_RDONLY|MS_BIND"
[ "String", "returns", "a", "human", "readable", "representation", "of", "mountFlags", "based", "on", "which", "bits", "are", "set", ".", "E", ".", "g", ".", "for", "a", "value", "of", "syscall", ".", "MS_RDONLY|syscall", ".", "MS_BIND", "it", "will", "print", "MS_RDONLY|MS_BIND" ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/fs/mount_linux.go#L26-L57
167,279
rkt/rkt
rkt/image/validator.go
newValidator
func newValidator(image io.ReadSeeker) (*validator, error) { manifest, err := aci.ManifestFromImage(image) if err != nil { return nil, err } v := &validator{ image: image, manifest: manifest, } return v, nil }
go
func newValidator(image io.ReadSeeker) (*validator, error) { manifest, err := aci.ManifestFromImage(image) if err != nil { return nil, err } v := &validator{ image: image, manifest: manifest, } return v, nil }
[ "func", "newValidator", "(", "image", "io", ".", "ReadSeeker", ")", "(", "*", "validator", ",", "error", ")", "{", "manifest", ",", "err", ":=", "aci", ".", "ManifestFromImage", "(", "image", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "v", ":=", "&", "validator", "{", "image", ":", "image", ",", "manifest", ":", "manifest", ",", "}", "\n", "return", "v", ",", "nil", "\n", "}" ]
// newValidator returns a validator instance if passed image is indeed // an ACI.
[ "newValidator", "returns", "a", "validator", "instance", "if", "passed", "image", "is", "indeed", "an", "ACI", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/validator.go#L40-L50
167,280
rkt/rkt
rkt/image/validator.go
ValidateName
func (v *validator) ValidateName(imageName string) error { name := v.ImageName() if name != imageName { return fmt.Errorf("error when reading the app name: %q expected but %q found", imageName, name) } return nil }
go
func (v *validator) ValidateName(imageName string) error { name := v.ImageName() if name != imageName { return fmt.Errorf("error when reading the app name: %q expected but %q found", imageName, name) } return nil }
[ "func", "(", "v", "*", "validator", ")", "ValidateName", "(", "imageName", "string", ")", "error", "{", "name", ":=", "v", ".", "ImageName", "(", ")", "\n", "if", "name", "!=", "imageName", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "imageName", ",", "name", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ValidateName checks if desired image name is actually the same as // the one in the image manifest.
[ "ValidateName", "checks", "if", "desired", "image", "name", "is", "actually", "the", "same", "as", "the", "one", "in", "the", "image", "manifest", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/validator.go#L59-L66
167,281
rkt/rkt
rkt/image/validator.go
ValidateLabels
func (v *validator) ValidateLabels(labels map[types.ACIdentifier]string) error { for n, rv := range labels { if av, ok := v.manifest.GetLabel(n.String()); ok { if rv != av { return fmt.Errorf("requested value for label %q: %q differs from fetched aci label value: %q", n, rv, av) } } else { return fmt.Errorf("requested label %q not provided by the image manifest", n) } } return nil }
go
func (v *validator) ValidateLabels(labels map[types.ACIdentifier]string) error { for n, rv := range labels { if av, ok := v.manifest.GetLabel(n.String()); ok { if rv != av { return fmt.Errorf("requested value for label %q: %q differs from fetched aci label value: %q", n, rv, av) } } else { return fmt.Errorf("requested label %q not provided by the image manifest", n) } } return nil }
[ "func", "(", "v", "*", "validator", ")", "ValidateLabels", "(", "labels", "map", "[", "types", ".", "ACIdentifier", "]", "string", ")", "error", "{", "for", "n", ",", "rv", ":=", "range", "labels", "{", "if", "av", ",", "ok", ":=", "v", ".", "manifest", ".", "GetLabel", "(", "n", ".", "String", "(", ")", ")", ";", "ok", "{", "if", "rv", "!=", "av", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "n", ",", "rv", ",", "av", ")", "\n", "}", "\n", "}", "else", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "n", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ValidateLabels checks if desired image labels are actually the same as // the ones in the image manifest.
[ "ValidateLabels", "checks", "if", "desired", "image", "labels", "are", "actually", "the", "same", "as", "the", "ones", "in", "the", "image", "manifest", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/validator.go#L70-L81
167,282
rkt/rkt
rkt/image/validator.go
ValidateWithSignature
func (v *validator) ValidateWithSignature(ks *keystore.Keystore, sig io.ReadSeeker) (*openpgp.Entity, error) { if ks == nil { return nil, nil } if _, err := v.image.Seek(0, 0); err != nil { return nil, errwrap.Wrap(errors.New("error seeking ACI file"), err) } if _, err := sig.Seek(0, 0); err != nil { return nil, errwrap.Wrap(errors.New("error seeking signature file"), err) } entity, err := ks.CheckSignature(v.ImageName(), v.image, sig) if err == pgperrors.ErrUnknownIssuer { log.Print("If you expected the signing key to change, try running:") log.Print(" rkt trust --prefix <image>") } if err != nil { return nil, err } return entity, nil }
go
func (v *validator) ValidateWithSignature(ks *keystore.Keystore, sig io.ReadSeeker) (*openpgp.Entity, error) { if ks == nil { return nil, nil } if _, err := v.image.Seek(0, 0); err != nil { return nil, errwrap.Wrap(errors.New("error seeking ACI file"), err) } if _, err := sig.Seek(0, 0); err != nil { return nil, errwrap.Wrap(errors.New("error seeking signature file"), err) } entity, err := ks.CheckSignature(v.ImageName(), v.image, sig) if err == pgperrors.ErrUnknownIssuer { log.Print("If you expected the signing key to change, try running:") log.Print(" rkt trust --prefix <image>") } if err != nil { return nil, err } return entity, nil }
[ "func", "(", "v", "*", "validator", ")", "ValidateWithSignature", "(", "ks", "*", "keystore", ".", "Keystore", ",", "sig", "io", ".", "ReadSeeker", ")", "(", "*", "openpgp", ".", "Entity", ",", "error", ")", "{", "if", "ks", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "if", "_", ",", "err", ":=", "v", ".", "image", ".", "Seek", "(", "0", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "if", "_", ",", "err", ":=", "sig", ".", "Seek", "(", "0", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errwrap", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "entity", ",", "err", ":=", "ks", ".", "CheckSignature", "(", "v", ".", "ImageName", "(", ")", ",", "v", ".", "image", ",", "sig", ")", "\n", "if", "err", "==", "pgperrors", ".", "ErrUnknownIssuer", "{", "log", ".", "Print", "(", "\"", "\"", ")", "\n", "log", ".", "Print", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "entity", ",", "nil", "\n", "}" ]
// ValidateWithSignature verifies the image against a given signature // file.
[ "ValidateWithSignature", "verifies", "the", "image", "against", "a", "given", "signature", "file", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/validator.go#L85-L104
167,283
rkt/rkt
pkg/distribution/distribution.go
Register
func Register(distType Type, f newDistribution) { if _, ok := distributions[distType]; ok { panic(fmt.Errorf("distribution %q already registered", distType)) } distributions[distType] = f }
go
func Register(distType Type, f newDistribution) { if _, ok := distributions[distType]; ok { panic(fmt.Errorf("distribution %q already registered", distType)) } distributions[distType] = f }
[ "func", "Register", "(", "distType", "Type", ",", "f", "newDistribution", ")", "{", "if", "_", ",", "ok", ":=", "distributions", "[", "distType", "]", ";", "ok", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "distType", ")", ")", "\n", "}", "\n", "distributions", "[", "distType", "]", "=", "f", "\n", "}" ]
// Register registers a function that returns a new instance of the given // distribution. This is intended to be called from the init function in // packages that implement distribution functions.
[ "Register", "registers", "a", "function", "that", "returns", "a", "new", "instance", "of", "the", "given", "distribution", ".", "This", "is", "intended", "to", "be", "called", "from", "the", "init", "function", "in", "packages", "that", "implement", "distribution", "functions", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/distribution/distribution.go#L47-L52
167,284
rkt/rkt
pkg/distribution/distribution.go
Get
func Get(u *url.URL) (Distribution, error) { c, err := parseCIMD(u) if err != nil { return nil, fmt.Errorf("malformed distribution uri %q: %v", u.String(), err) } if u.Scheme != Scheme { return nil, fmt.Errorf("malformed distribution uri %q", u.String()) } if _, ok := distributions[c.Type]; !ok { return nil, fmt.Errorf("unknown distribution type: %q", c.Type) } return distributions[c.Type](u) }
go
func Get(u *url.URL) (Distribution, error) { c, err := parseCIMD(u) if err != nil { return nil, fmt.Errorf("malformed distribution uri %q: %v", u.String(), err) } if u.Scheme != Scheme { return nil, fmt.Errorf("malformed distribution uri %q", u.String()) } if _, ok := distributions[c.Type]; !ok { return nil, fmt.Errorf("unknown distribution type: %q", c.Type) } return distributions[c.Type](u) }
[ "func", "Get", "(", "u", "*", "url", ".", "URL", ")", "(", "Distribution", ",", "error", ")", "{", "c", ",", "err", ":=", "parseCIMD", "(", "u", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ",", "err", ")", "\n", "}", "\n", "if", "u", ".", "Scheme", "!=", "Scheme", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ")", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "distributions", "[", "c", ".", "Type", "]", ";", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "c", ".", "Type", ")", "\n", "}", "\n", "return", "distributions", "[", "c", ".", "Type", "]", "(", "u", ")", "\n", "}" ]
// Get returns a Distribution from the input URI. // It returns an error if the uri string is wrong or referencing an unknown // distribution type.
[ "Get", "returns", "a", "Distribution", "from", "the", "input", "URI", ".", "It", "returns", "an", "error", "if", "the", "uri", "string", "is", "wrong", "or", "referencing", "an", "unknown", "distribution", "type", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/distribution/distribution.go#L57-L69
167,285
rkt/rkt
pkg/distribution/distribution.go
Parse
func Parse(rawuri string) (Distribution, error) { u, err := url.Parse(rawuri) if err != nil { return nil, fmt.Errorf("cannot parse uri: %q: %v", rawuri, err) } return Get(u) }
go
func Parse(rawuri string) (Distribution, error) { u, err := url.Parse(rawuri) if err != nil { return nil, fmt.Errorf("cannot parse uri: %q: %v", rawuri, err) } return Get(u) }
[ "func", "Parse", "(", "rawuri", "string", ")", "(", "Distribution", ",", "error", ")", "{", "u", ",", "err", ":=", "url", ".", "Parse", "(", "rawuri", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "rawuri", ",", "err", ")", "\n", "}", "\n", "return", "Get", "(", "u", ")", "\n", "}" ]
// Parse parses the provided distribution URI string and returns a // Distribution.
[ "Parse", "parses", "the", "provided", "distribution", "URI", "string", "and", "returns", "a", "Distribution", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/distribution/distribution.go#L73-L79
167,286
rkt/rkt
rkt/completion.go
newCompletion
func newCompletion(w io.Writer) func(*cobra.Command, []string) int { return func(cmd *cobra.Command, args []string) int { return runCompletion(w, cmd, args) } }
go
func newCompletion(w io.Writer) func(*cobra.Command, []string) int { return func(cmd *cobra.Command, args []string) int { return runCompletion(w, cmd, args) } }
[ "func", "newCompletion", "(", "w", "io", ".", "Writer", ")", "func", "(", "*", "cobra", ".", "Command", ",", "[", "]", "string", ")", "int", "{", "return", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "int", "{", "return", "runCompletion", "(", "w", ",", "cmd", ",", "args", ")", "\n", "}", "\n", "}" ]
// newCompletion creates a new command with a bounded writer. Writer // is used to print the generated shell-completion script, which is // intended to be consumed by the CLI users.
[ "newCompletion", "creates", "a", "new", "command", "with", "a", "bounded", "writer", ".", "Writer", "is", "used", "to", "print", "the", "generated", "shell", "-", "completion", "script", "which", "is", "intended", "to", "be", "consumed", "by", "the", "CLI", "users", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/completion.go#L117-L121
167,287
rkt/rkt
rkt/completion.go
runCompletion
func runCompletion(w io.Writer, cmd *cobra.Command, args []string) (exit int) { if len(args) == 0 { stderr.Print("shell type is not specified") return 254 } if len(args) > 1 { stderr.Print("too many arguments, only shell type is expected") return 254 } // Right now only bash completion is supported, but zsh could be // supported in a future as well. completion, ok := completionShells[args[0]] if !ok { stderr.Printf("'%s' shell is not supported", args[0]) return 254 } // Write the shell completion to the specified writer. err := completion(w, cmd.Parent()) if err != nil { stderr.PrintE("completion failed", err) return 254 } return 0 }
go
func runCompletion(w io.Writer, cmd *cobra.Command, args []string) (exit int) { if len(args) == 0 { stderr.Print("shell type is not specified") return 254 } if len(args) > 1 { stderr.Print("too many arguments, only shell type is expected") return 254 } // Right now only bash completion is supported, but zsh could be // supported in a future as well. completion, ok := completionShells[args[0]] if !ok { stderr.Printf("'%s' shell is not supported", args[0]) return 254 } // Write the shell completion to the specified writer. err := completion(w, cmd.Parent()) if err != nil { stderr.PrintE("completion failed", err) return 254 } return 0 }
[ "func", "runCompletion", "(", "w", "io", ".", "Writer", ",", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "(", "exit", "int", ")", "{", "if", "len", "(", "args", ")", "==", "0", "{", "stderr", ".", "Print", "(", "\"", "\"", ")", "\n", "return", "254", "\n", "}", "\n\n", "if", "len", "(", "args", ")", ">", "1", "{", "stderr", ".", "Print", "(", "\"", "\"", ")", "\n", "return", "254", "\n", "}", "\n\n", "// Right now only bash completion is supported, but zsh could be", "// supported in a future as well.", "completion", ",", "ok", ":=", "completionShells", "[", "args", "[", "0", "]", "]", "\n", "if", "!", "ok", "{", "stderr", ".", "Printf", "(", "\"", "\"", ",", "args", "[", "0", "]", ")", "\n", "return", "254", "\n", "}", "\n\n", "// Write the shell completion to the specified writer.", "err", ":=", "completion", "(", "w", ",", "cmd", ".", "Parent", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "stderr", ".", "PrintE", "(", "\"", "\"", ",", "err", ")", "\n", "return", "254", "\n", "}", "\n\n", "return", "0", "\n", "}" ]
// runCompletion is a command handler to generate the shell script with // shell completion functions. // // It ensures that there are enough arguments to generate the completion // scripts.
[ "runCompletion", "is", "a", "command", "handler", "to", "generate", "the", "shell", "script", "with", "shell", "completion", "functions", ".", "It", "ensures", "that", "there", "are", "enough", "arguments", "to", "generate", "the", "completion", "scripts", "." ]
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/completion.go#L128-L155