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
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
|---|---|---|---|---|---|---|---|---|---|---|---|
20,900
|
rkt/rkt
|
pkg/sys/capability.go
|
HasChrootCapability
|
func HasChrootCapability() bool {
// Checking the capabilities should be enough, but in case there're
// problem retrieving them, fallback checking for the effective uid
// (hoping it hasn't dropped its CAP_SYS_CHROOT).
caps, err := capability.NewPid(0)
if err == nil {
return caps.Get(capability.EFFECTIVE, capability.CAP_SYS_CHROOT)
} else {
return os.Geteuid() == 0
}
}
|
go
|
func HasChrootCapability() bool {
// Checking the capabilities should be enough, but in case there're
// problem retrieving them, fallback checking for the effective uid
// (hoping it hasn't dropped its CAP_SYS_CHROOT).
caps, err := capability.NewPid(0)
if err == nil {
return caps.Get(capability.EFFECTIVE, capability.CAP_SYS_CHROOT)
} else {
return os.Geteuid() == 0
}
}
|
[
"func",
"HasChrootCapability",
"(",
")",
"bool",
"{",
"// Checking the capabilities should be enough, but in case there're",
"// problem retrieving them, fallback checking for the effective uid",
"// (hoping it hasn't dropped its CAP_SYS_CHROOT).",
"caps",
",",
"err",
":=",
"capability",
".",
"NewPid",
"(",
"0",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"caps",
".",
"Get",
"(",
"capability",
".",
"EFFECTIVE",
",",
"capability",
".",
"CAP_SYS_CHROOT",
")",
"\n",
"}",
"else",
"{",
"return",
"os",
".",
"Geteuid",
"(",
")",
"==",
"0",
"\n",
"}",
"\n",
"}"
] |
// HasChrootCapability checks if the current process has the CAP_SYS_CHROOT
// capability
|
[
"HasChrootCapability",
"checks",
"if",
"the",
"current",
"process",
"has",
"the",
"CAP_SYS_CHROOT",
"capability"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/sys/capability.go#L25-L35
|
20,901
|
rkt/rkt
|
pkg/group/group.go
|
LookupGidFromFile
|
func LookupGidFromFile(groupName, groupFile string) (gid int, err error) {
groups, err := parseGroupFile(groupFile)
if err != nil {
return -1, errwrap.Wrap(fmt.Errorf("error parsing %q file", groupFile), err)
}
group, ok := groups[groupName]
if !ok {
return -1, fmt.Errorf("%q group not found", groupName)
}
return group.Gid, nil
}
|
go
|
func LookupGidFromFile(groupName, groupFile string) (gid int, err error) {
groups, err := parseGroupFile(groupFile)
if err != nil {
return -1, errwrap.Wrap(fmt.Errorf("error parsing %q file", groupFile), err)
}
group, ok := groups[groupName]
if !ok {
return -1, fmt.Errorf("%q group not found", groupName)
}
return group.Gid, nil
}
|
[
"func",
"LookupGidFromFile",
"(",
"groupName",
",",
"groupFile",
"string",
")",
"(",
"gid",
"int",
",",
"err",
"error",
")",
"{",
"groups",
",",
"err",
":=",
"parseGroupFile",
"(",
"groupFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"groupFile",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"group",
",",
"ok",
":=",
"groups",
"[",
"groupName",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"groupName",
")",
"\n",
"}",
"\n\n",
"return",
"group",
".",
"Gid",
",",
"nil",
"\n",
"}"
] |
// LookupGid reads the group file specified by groupFile, and returns the gid of the group
// specified by groupName.
|
[
"LookupGid",
"reads",
"the",
"group",
"file",
"specified",
"by",
"groupFile",
"and",
"returns",
"the",
"gid",
"of",
"the",
"group",
"specified",
"by",
"groupName",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/group/group.go#L43-L55
|
20,902
|
rkt/rkt
|
pkg/lock/keylock.go
|
TryExclusiveKeyLock
|
func TryExclusiveKeyLock(lockDir string, key string) (*KeyLock, error) {
return createAndLock(lockDir, key, keyLockExclusive|keyLockNonBlocking)
}
|
go
|
func TryExclusiveKeyLock(lockDir string, key string) (*KeyLock, error) {
return createAndLock(lockDir, key, keyLockExclusive|keyLockNonBlocking)
}
|
[
"func",
"TryExclusiveKeyLock",
"(",
"lockDir",
"string",
",",
"key",
"string",
")",
"(",
"*",
"KeyLock",
",",
"error",
")",
"{",
"return",
"createAndLock",
"(",
"lockDir",
",",
"key",
",",
"keyLockExclusive",
"|",
"keyLockNonBlocking",
")",
"\n",
"}"
] |
// TryExclusiveLock takes an exclusive lock on the key without blocking.
// lockDir is the directory where the lock file will be created.
// It will return ErrLocked if any lock is already held.
|
[
"TryExclusiveLock",
"takes",
"an",
"exclusive",
"lock",
"on",
"the",
"key",
"without",
"blocking",
".",
"lockDir",
"is",
"the",
"directory",
"where",
"the",
"lock",
"file",
"will",
"be",
"created",
".",
"It",
"will",
"return",
"ErrLocked",
"if",
"any",
"lock",
"is",
"already",
"held",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/lock/keylock.go#L94-L96
|
20,903
|
rkt/rkt
|
pkg/lock/keylock.go
|
ExclusiveKeyLock
|
func ExclusiveKeyLock(lockDir string, key string) (*KeyLock, error) {
return createAndLock(lockDir, key, keyLockExclusive)
}
|
go
|
func ExclusiveKeyLock(lockDir string, key string) (*KeyLock, error) {
return createAndLock(lockDir, key, keyLockExclusive)
}
|
[
"func",
"ExclusiveKeyLock",
"(",
"lockDir",
"string",
",",
"key",
"string",
")",
"(",
"*",
"KeyLock",
",",
"error",
")",
"{",
"return",
"createAndLock",
"(",
"lockDir",
",",
"key",
",",
"keyLockExclusive",
")",
"\n",
"}"
] |
// ExclusiveLock takes an exclusive lock on a key.
// lockDir is the directory where the lock file will be created.
// It will block if an exclusive lock is already held on the key.
|
[
"ExclusiveLock",
"takes",
"an",
"exclusive",
"lock",
"on",
"a",
"key",
".",
"lockDir",
"is",
"the",
"directory",
"where",
"the",
"lock",
"file",
"will",
"be",
"created",
".",
"It",
"will",
"block",
"if",
"an",
"exclusive",
"lock",
"is",
"already",
"held",
"on",
"the",
"key",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/lock/keylock.go#L109-L111
|
20,904
|
rkt/rkt
|
pkg/lock/keylock.go
|
Unlock
|
func (l *KeyLock) Unlock() error {
err := l.keyLock.Unlock()
if err != nil {
return err
}
return nil
}
|
go
|
func (l *KeyLock) Unlock() error {
err := l.keyLock.Unlock()
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"l",
"*",
"KeyLock",
")",
"Unlock",
"(",
")",
"error",
"{",
"err",
":=",
"l",
".",
"keyLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Unlock unlocks the key lock.
|
[
"Unlock",
"unlocks",
"the",
"key",
"lock",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/lock/keylock.go#L238-L244
|
20,905
|
rkt/rkt
|
pkg/lock/keylock.go
|
CleanKeyLocks
|
func CleanKeyLocks(lockDir string) error {
f, err := os.Open(lockDir)
if err != nil {
return errwrap.Wrap(errors.New("error opening lockDir"), err)
}
defer f.Close()
files, err := f.Readdir(0)
if err != nil {
return errwrap.Wrap(errors.New("error getting lock files list"), err)
}
for _, f := range files {
filename := filepath.Join(lockDir, f.Name())
keyLock, err := TryExclusiveKeyLock(lockDir, f.Name())
if err == ErrLocked {
continue
}
if err != nil {
return err
}
err = os.Remove(filename)
if err != nil {
keyLock.Close()
return errwrap.Wrap(errors.New("error removing lock file"), err)
}
keyLock.Close()
}
return nil
}
|
go
|
func CleanKeyLocks(lockDir string) error {
f, err := os.Open(lockDir)
if err != nil {
return errwrap.Wrap(errors.New("error opening lockDir"), err)
}
defer f.Close()
files, err := f.Readdir(0)
if err != nil {
return errwrap.Wrap(errors.New("error getting lock files list"), err)
}
for _, f := range files {
filename := filepath.Join(lockDir, f.Name())
keyLock, err := TryExclusiveKeyLock(lockDir, f.Name())
if err == ErrLocked {
continue
}
if err != nil {
return err
}
err = os.Remove(filename)
if err != nil {
keyLock.Close()
return errwrap.Wrap(errors.New("error removing lock file"), err)
}
keyLock.Close()
}
return nil
}
|
[
"func",
"CleanKeyLocks",
"(",
"lockDir",
"string",
")",
"error",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"lockDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"files",
",",
"err",
":=",
"f",
".",
"Readdir",
"(",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"files",
"{",
"filename",
":=",
"filepath",
".",
"Join",
"(",
"lockDir",
",",
"f",
".",
"Name",
"(",
")",
")",
"\n",
"keyLock",
",",
"err",
":=",
"TryExclusiveKeyLock",
"(",
"lockDir",
",",
"f",
".",
"Name",
"(",
")",
")",
"\n",
"if",
"err",
"==",
"ErrLocked",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"os",
".",
"Remove",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"keyLock",
".",
"Close",
"(",
")",
"\n",
"return",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"keyLock",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CleanKeyLocks remove lock files from the lockDir.
// For every key it tries to take an Exclusive lock on it and skip it if it
// fails with ErrLocked
|
[
"CleanKeyLocks",
"remove",
"lock",
"files",
"from",
"the",
"lockDir",
".",
"For",
"every",
"key",
"it",
"tries",
"to",
"take",
"an",
"Exclusive",
"lock",
"on",
"it",
"and",
"skip",
"it",
"if",
"it",
"fails",
"with",
"ErrLocked"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/lock/keylock.go#L249-L277
|
20,906
|
rkt/rkt
|
rkt/pubkey/pubkey.go
|
GetPubKeyLocations
|
func (m *Manager) GetPubKeyLocations(prefix string) ([]string, error) {
ensureLogger(m.Debug)
if prefix == "" {
return nil, fmt.Errorf("empty prefix")
}
kls, err := m.metaDiscoverPubKeyLocations(prefix)
if err != nil {
return nil, errwrap.Wrap(errors.New("prefix meta discovery error"), err)
}
if len(kls) == 0 {
return nil, fmt.Errorf("meta discovery on %s resulted in no keys", prefix)
}
return kls, nil
}
|
go
|
func (m *Manager) GetPubKeyLocations(prefix string) ([]string, error) {
ensureLogger(m.Debug)
if prefix == "" {
return nil, fmt.Errorf("empty prefix")
}
kls, err := m.metaDiscoverPubKeyLocations(prefix)
if err != nil {
return nil, errwrap.Wrap(errors.New("prefix meta discovery error"), err)
}
if len(kls) == 0 {
return nil, fmt.Errorf("meta discovery on %s resulted in no keys", prefix)
}
return kls, nil
}
|
[
"func",
"(",
"m",
"*",
"Manager",
")",
"GetPubKeyLocations",
"(",
"prefix",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"ensureLogger",
"(",
"m",
".",
"Debug",
")",
"\n",
"if",
"prefix",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"kls",
",",
"err",
":=",
"m",
".",
"metaDiscoverPubKeyLocations",
"(",
"prefix",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"kls",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"prefix",
")",
"\n",
"}",
"\n\n",
"return",
"kls",
",",
"nil",
"\n",
"}"
] |
// GetPubKeyLocations discovers locations at prefix
|
[
"GetPubKeyLocations",
"discovers",
"locations",
"at",
"prefix"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/pubkey/pubkey.go#L72-L88
|
20,907
|
rkt/rkt
|
rkt/pubkey/pubkey.go
|
AddKeys
|
func (m *Manager) AddKeys(pkls []string, prefix string, accept AcceptOption) error {
ensureLogger(m.Debug)
if m.Ks == nil {
return fmt.Errorf("no keystore available to add keys to")
}
for _, pkl := range pkls {
u, err := url.Parse(pkl)
if err != nil {
return err
}
pk, err := m.getPubKey(u)
if err != nil {
return errwrap.Wrap(fmt.Errorf("error accessing the key %s", pkl), err)
}
defer pk.Close()
err = displayKey(prefix, pkl, pk)
if err != nil {
return errwrap.Wrap(fmt.Errorf("error displaying the key %s", pkl), err)
}
if m.TrustKeysFromHTTPS && u.Scheme == "https" {
accept = AcceptForce
}
if accept == AcceptAsk {
if !terminal.IsTerminal(int(os.Stdin.Fd())) || !terminal.IsTerminal(int(os.Stderr.Fd())) {
log.Printf("To trust the key for %q, do one of the following:", prefix)
log.Printf(" - call rkt with --trust-keys-from-https")
log.Printf(" - run: rkt trust --prefix %q", prefix)
return fmt.Errorf("error reviewing key: unable to ask user to review fingerprint due to lack of tty")
}
accepted, err := reviewKey()
if err != nil {
return errwrap.Wrap(errors.New("error reviewing key"), err)
}
if !accepted {
log.Printf("not trusting %q", pkl)
continue
}
}
if accept == AcceptForce {
stdout.Printf("Trusting %q for prefix %q without fingerprint review.", pkl, prefix)
} else {
stdout.Printf("Trusting %q for prefix %q after fingerprint review.", pkl, prefix)
}
if prefix == "" {
path, err := m.Ks.StoreTrustedKeyRoot(pk)
if err != nil {
return errwrap.Wrap(errors.New("error adding root key"), err)
}
stdout.Printf("Added root key at %q", path)
} else {
path, err := m.Ks.StoreTrustedKeyPrefix(prefix, pk)
if err != nil {
return errwrap.Wrap(fmt.Errorf("error adding key for prefix %q", prefix), err)
}
stdout.Printf("Added key for prefix %q at %q", prefix, path)
}
}
return nil
}
|
go
|
func (m *Manager) AddKeys(pkls []string, prefix string, accept AcceptOption) error {
ensureLogger(m.Debug)
if m.Ks == nil {
return fmt.Errorf("no keystore available to add keys to")
}
for _, pkl := range pkls {
u, err := url.Parse(pkl)
if err != nil {
return err
}
pk, err := m.getPubKey(u)
if err != nil {
return errwrap.Wrap(fmt.Errorf("error accessing the key %s", pkl), err)
}
defer pk.Close()
err = displayKey(prefix, pkl, pk)
if err != nil {
return errwrap.Wrap(fmt.Errorf("error displaying the key %s", pkl), err)
}
if m.TrustKeysFromHTTPS && u.Scheme == "https" {
accept = AcceptForce
}
if accept == AcceptAsk {
if !terminal.IsTerminal(int(os.Stdin.Fd())) || !terminal.IsTerminal(int(os.Stderr.Fd())) {
log.Printf("To trust the key for %q, do one of the following:", prefix)
log.Printf(" - call rkt with --trust-keys-from-https")
log.Printf(" - run: rkt trust --prefix %q", prefix)
return fmt.Errorf("error reviewing key: unable to ask user to review fingerprint due to lack of tty")
}
accepted, err := reviewKey()
if err != nil {
return errwrap.Wrap(errors.New("error reviewing key"), err)
}
if !accepted {
log.Printf("not trusting %q", pkl)
continue
}
}
if accept == AcceptForce {
stdout.Printf("Trusting %q for prefix %q without fingerprint review.", pkl, prefix)
} else {
stdout.Printf("Trusting %q for prefix %q after fingerprint review.", pkl, prefix)
}
if prefix == "" {
path, err := m.Ks.StoreTrustedKeyRoot(pk)
if err != nil {
return errwrap.Wrap(errors.New("error adding root key"), err)
}
stdout.Printf("Added root key at %q", path)
} else {
path, err := m.Ks.StoreTrustedKeyPrefix(prefix, pk)
if err != nil {
return errwrap.Wrap(fmt.Errorf("error adding key for prefix %q", prefix), err)
}
stdout.Printf("Added key for prefix %q at %q", prefix, path)
}
}
return nil
}
|
[
"func",
"(",
"m",
"*",
"Manager",
")",
"AddKeys",
"(",
"pkls",
"[",
"]",
"string",
",",
"prefix",
"string",
",",
"accept",
"AcceptOption",
")",
"error",
"{",
"ensureLogger",
"(",
"m",
".",
"Debug",
")",
"\n",
"if",
"m",
".",
"Ks",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"pkl",
":=",
"range",
"pkls",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"pkl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"pk",
",",
"err",
":=",
"m",
".",
"getPubKey",
"(",
"u",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pkl",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"pk",
".",
"Close",
"(",
")",
"\n\n",
"err",
"=",
"displayKey",
"(",
"prefix",
",",
"pkl",
",",
"pk",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pkl",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"m",
".",
"TrustKeysFromHTTPS",
"&&",
"u",
".",
"Scheme",
"==",
"\"",
"\"",
"{",
"accept",
"=",
"AcceptForce",
"\n",
"}",
"\n\n",
"if",
"accept",
"==",
"AcceptAsk",
"{",
"if",
"!",
"terminal",
".",
"IsTerminal",
"(",
"int",
"(",
"os",
".",
"Stdin",
".",
"Fd",
"(",
")",
")",
")",
"||",
"!",
"terminal",
".",
"IsTerminal",
"(",
"int",
"(",
"os",
".",
"Stderr",
".",
"Fd",
"(",
")",
")",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"prefix",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"prefix",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"accepted",
",",
"err",
":=",
"reviewKey",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"!",
"accepted",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"pkl",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"accept",
"==",
"AcceptForce",
"{",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
",",
"pkl",
",",
"prefix",
")",
"\n",
"}",
"else",
"{",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
",",
"pkl",
",",
"prefix",
")",
"\n",
"}",
"\n\n",
"if",
"prefix",
"==",
"\"",
"\"",
"{",
"path",
",",
"err",
":=",
"m",
".",
"Ks",
".",
"StoreTrustedKeyRoot",
"(",
"pk",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
",",
"path",
")",
"\n",
"}",
"else",
"{",
"path",
",",
"err",
":=",
"m",
".",
"Ks",
".",
"StoreTrustedKeyPrefix",
"(",
"prefix",
",",
"pk",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"prefix",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
",",
"prefix",
",",
"path",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// AddKeys adds the keys listed in pkls at prefix
|
[
"AddKeys",
"adds",
"the",
"keys",
"listed",
"in",
"pkls",
"at",
"prefix"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/pubkey/pubkey.go#L91-L155
|
20,908
|
rkt/rkt
|
rkt/pubkey/pubkey.go
|
metaDiscoverPubKeyLocations
|
func (m *Manager) metaDiscoverPubKeyLocations(prefix string) ([]string, error) {
app, err := discovery.NewAppFromString(prefix)
if err != nil {
return nil, err
}
hostHeaders := config.ResolveAuthPerHost(m.AuthPerHost)
insecure := discovery.InsecureNone
if m.InsecureAllowHTTP {
insecure = insecure | discovery.InsecureHTTP
}
if m.InsecureSkipTLSCheck {
insecure = insecure | discovery.InsecureTLS
}
keys, attempts, err := discovery.DiscoverPublicKeys(*app, hostHeaders, insecure, 0)
if err != nil && m.Debug {
for _, a := range attempts {
log.PrintE(fmt.Sprintf("meta tag 'ac-discovery-pubkeys' not found on %s", a.Prefix), a.Error)
}
}
return keys, err
}
|
go
|
func (m *Manager) metaDiscoverPubKeyLocations(prefix string) ([]string, error) {
app, err := discovery.NewAppFromString(prefix)
if err != nil {
return nil, err
}
hostHeaders := config.ResolveAuthPerHost(m.AuthPerHost)
insecure := discovery.InsecureNone
if m.InsecureAllowHTTP {
insecure = insecure | discovery.InsecureHTTP
}
if m.InsecureSkipTLSCheck {
insecure = insecure | discovery.InsecureTLS
}
keys, attempts, err := discovery.DiscoverPublicKeys(*app, hostHeaders, insecure, 0)
if err != nil && m.Debug {
for _, a := range attempts {
log.PrintE(fmt.Sprintf("meta tag 'ac-discovery-pubkeys' not found on %s", a.Prefix), a.Error)
}
}
return keys, err
}
|
[
"func",
"(",
"m",
"*",
"Manager",
")",
"metaDiscoverPubKeyLocations",
"(",
"prefix",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"app",
",",
"err",
":=",
"discovery",
".",
"NewAppFromString",
"(",
"prefix",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"hostHeaders",
":=",
"config",
".",
"ResolveAuthPerHost",
"(",
"m",
".",
"AuthPerHost",
")",
"\n",
"insecure",
":=",
"discovery",
".",
"InsecureNone",
"\n",
"if",
"m",
".",
"InsecureAllowHTTP",
"{",
"insecure",
"=",
"insecure",
"|",
"discovery",
".",
"InsecureHTTP",
"\n",
"}",
"\n",
"if",
"m",
".",
"InsecureSkipTLSCheck",
"{",
"insecure",
"=",
"insecure",
"|",
"discovery",
".",
"InsecureTLS",
"\n",
"}",
"\n\n",
"keys",
",",
"attempts",
",",
"err",
":=",
"discovery",
".",
"DiscoverPublicKeys",
"(",
"*",
"app",
",",
"hostHeaders",
",",
"insecure",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"m",
".",
"Debug",
"{",
"for",
"_",
",",
"a",
":=",
"range",
"attempts",
"{",
"log",
".",
"PrintE",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"a",
".",
"Prefix",
")",
",",
"a",
".",
"Error",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"keys",
",",
"err",
"\n",
"}"
] |
// metaDiscoverPubKeyLocations discovers the locations of public keys through ACDiscovery by applying prefix as an ACApp
|
[
"metaDiscoverPubKeyLocations",
"discovers",
"the",
"locations",
"of",
"public",
"keys",
"through",
"ACDiscovery",
"by",
"applying",
"prefix",
"as",
"an",
"ACApp"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/pubkey/pubkey.go#L158-L181
|
20,909
|
rkt/rkt
|
rkt/pubkey/pubkey.go
|
downloadKey
|
func downloadKey(u *url.URL, skipTLSCheck bool) (*os.File, error) {
tf, err := ioutil.TempFile("", "")
if err != nil {
return nil, errwrap.Wrap(errors.New("error creating tempfile"), err)
}
os.Remove(tf.Name()) // no need to keep the tempfile around
defer func() {
if tf != nil {
tf.Close()
}
}()
// TODO(krnowak): we should probably apply credential headers
// from config here
var client *http.Client
if skipTLSCheck {
client = insecureClient
} else {
client = secureClient
}
res, err := client.Get(u.String())
if err != nil {
return nil, errwrap.Wrap(errors.New("error getting key"), err)
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("bad HTTP status code: %d", res.StatusCode)
}
if _, err := io.Copy(tf, res.Body); err != nil {
return nil, errwrap.Wrap(errors.New("error copying key"), err)
}
if _, err = tf.Seek(0, os.SEEK_SET); err != nil {
return nil, errwrap.Wrap(errors.New("error seeking"), err)
}
retTf := tf
tf = nil
return retTf, nil
}
|
go
|
func downloadKey(u *url.URL, skipTLSCheck bool) (*os.File, error) {
tf, err := ioutil.TempFile("", "")
if err != nil {
return nil, errwrap.Wrap(errors.New("error creating tempfile"), err)
}
os.Remove(tf.Name()) // no need to keep the tempfile around
defer func() {
if tf != nil {
tf.Close()
}
}()
// TODO(krnowak): we should probably apply credential headers
// from config here
var client *http.Client
if skipTLSCheck {
client = insecureClient
} else {
client = secureClient
}
res, err := client.Get(u.String())
if err != nil {
return nil, errwrap.Wrap(errors.New("error getting key"), err)
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("bad HTTP status code: %d", res.StatusCode)
}
if _, err := io.Copy(tf, res.Body); err != nil {
return nil, errwrap.Wrap(errors.New("error copying key"), err)
}
if _, err = tf.Seek(0, os.SEEK_SET); err != nil {
return nil, errwrap.Wrap(errors.New("error seeking"), err)
}
retTf := tf
tf = nil
return retTf, nil
}
|
[
"func",
"downloadKey",
"(",
"u",
"*",
"url",
".",
"URL",
",",
"skipTLSCheck",
"bool",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"tf",
",",
"err",
":=",
"ioutil",
".",
"TempFile",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"os",
".",
"Remove",
"(",
"tf",
".",
"Name",
"(",
")",
")",
"// no need to keep the tempfile around",
"\n\n",
"defer",
"func",
"(",
")",
"{",
"if",
"tf",
"!=",
"nil",
"{",
"tf",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"// TODO(krnowak): we should probably apply credential headers",
"// from config here",
"var",
"client",
"*",
"http",
".",
"Client",
"\n",
"if",
"skipTLSCheck",
"{",
"client",
"=",
"insecureClient",
"\n",
"}",
"else",
"{",
"client",
"=",
"secureClient",
"\n",
"}",
"\n\n",
"res",
",",
"err",
":=",
"client",
".",
"Get",
"(",
"u",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"res",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"res",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"res",
".",
"StatusCode",
")",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"Copy",
"(",
"tf",
",",
"res",
".",
"Body",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
"=",
"tf",
".",
"Seek",
"(",
"0",
",",
"os",
".",
"SEEK_SET",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"retTf",
":=",
"tf",
"\n",
"tf",
"=",
"nil",
"\n",
"return",
"retTf",
",",
"nil",
"\n",
"}"
] |
// downloadKey retrieves the file, storing it in a deleted tempfile
|
[
"downloadKey",
"retrieves",
"the",
"file",
"storing",
"it",
"in",
"a",
"deleted",
"tempfile"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/pubkey/pubkey.go#L201-L244
|
20,910
|
rkt/rkt
|
rkt/pubkey/pubkey.go
|
displayKey
|
func displayKey(prefix, location string, key *os.File) error {
defer key.Seek(0, os.SEEK_SET)
kr, err := openpgp.ReadArmoredKeyRing(key)
if err != nil {
return errwrap.Wrap(errors.New("error reading key"), err)
}
log.Printf("prefix: %q\nkey: %q", prefix, location)
for _, k := range kr {
stdout.Printf("gpg key fingerprint is: %s", fingerToString(k.PrimaryKey.Fingerprint))
for _, sk := range k.Subkeys {
stdout.Printf(" Subkey fingerprint: %s", fingerToString(sk.PublicKey.Fingerprint))
}
for n := range k.Identities {
stdout.Printf("\t%s", n)
}
}
return nil
}
|
go
|
func displayKey(prefix, location string, key *os.File) error {
defer key.Seek(0, os.SEEK_SET)
kr, err := openpgp.ReadArmoredKeyRing(key)
if err != nil {
return errwrap.Wrap(errors.New("error reading key"), err)
}
log.Printf("prefix: %q\nkey: %q", prefix, location)
for _, k := range kr {
stdout.Printf("gpg key fingerprint is: %s", fingerToString(k.PrimaryKey.Fingerprint))
for _, sk := range k.Subkeys {
stdout.Printf(" Subkey fingerprint: %s", fingerToString(sk.PublicKey.Fingerprint))
}
for n := range k.Identities {
stdout.Printf("\t%s", n)
}
}
return nil
}
|
[
"func",
"displayKey",
"(",
"prefix",
",",
"location",
"string",
",",
"key",
"*",
"os",
".",
"File",
")",
"error",
"{",
"defer",
"key",
".",
"Seek",
"(",
"0",
",",
"os",
".",
"SEEK_SET",
")",
"\n\n",
"kr",
",",
"err",
":=",
"openpgp",
".",
"ReadArmoredKeyRing",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"prefix",
",",
"location",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"kr",
"{",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
",",
"fingerToString",
"(",
"k",
".",
"PrimaryKey",
".",
"Fingerprint",
")",
")",
"\n",
"for",
"_",
",",
"sk",
":=",
"range",
"k",
".",
"Subkeys",
"{",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
",",
"fingerToString",
"(",
"sk",
".",
"PublicKey",
".",
"Fingerprint",
")",
")",
"\n",
"}",
"\n\n",
"for",
"n",
":=",
"range",
"k",
".",
"Identities",
"{",
"stdout",
".",
"Printf",
"(",
"\"",
"\\t",
"\"",
",",
"n",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// displayKey shows the key summary
|
[
"displayKey",
"shows",
"the",
"key",
"summary"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/pubkey/pubkey.go#L275-L296
|
20,911
|
rkt/rkt
|
rkt/pubkey/pubkey.go
|
reviewKey
|
func reviewKey() (bool, error) {
in := bufio.NewReader(os.Stdin)
for {
stdout.Printf("Are you sure you want to trust this key (yes/no)?")
input, err := in.ReadString('\n')
if err != nil {
return false, errwrap.Wrap(errors.New("error reading input"), err)
}
switch input {
case "yes\n":
return true, nil
case "no\n":
return false, nil
default:
stdout.Printf("Please enter 'yes' or 'no'")
}
}
}
|
go
|
func reviewKey() (bool, error) {
in := bufio.NewReader(os.Stdin)
for {
stdout.Printf("Are you sure you want to trust this key (yes/no)?")
input, err := in.ReadString('\n')
if err != nil {
return false, errwrap.Wrap(errors.New("error reading input"), err)
}
switch input {
case "yes\n":
return true, nil
case "no\n":
return false, nil
default:
stdout.Printf("Please enter 'yes' or 'no'")
}
}
}
|
[
"func",
"reviewKey",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"in",
":=",
"bufio",
".",
"NewReader",
"(",
"os",
".",
"Stdin",
")",
"\n",
"for",
"{",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"input",
",",
"err",
":=",
"in",
".",
"ReadString",
"(",
"'\\n'",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"switch",
"input",
"{",
"case",
"\"",
"\\n",
"\"",
":",
"return",
"true",
",",
"nil",
"\n",
"case",
"\"",
"\\n",
"\"",
":",
"return",
"false",
",",
"nil",
"\n",
"default",
":",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// reviewKey asks the user to accept the key
|
[
"reviewKey",
"asks",
"the",
"user",
"to",
"accept",
"the",
"key"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/pubkey/pubkey.go#L299-L316
|
20,912
|
rkt/rkt
|
networking/kvm.go
|
setupTapDevice
|
func setupTapDevice(podID types.UUID) (netlink.Link, error) {
// network device names are limited to 16 characters
// the suffix %d will be replaced by the kernel with a suitable number
nameTemplate := fmt.Sprintf("rkt-%s-tap%%d", podID.String()[0:4])
ifName, err := tuntap.CreatePersistentIface(nameTemplate, tuntap.Tap)
if err != nil {
return nil, errwrap.Wrap(errors.New("tuntap persist"), err)
}
link, err := netlink.LinkByName(ifName)
if err != nil {
return nil, errwrap.Wrap(fmt.Errorf("cannot find link %q", ifName), err)
}
if err := netlink.LinkSetUp(link); err != nil {
return nil, errwrap.Wrap(fmt.Errorf("cannot set link up %q", ifName), err)
}
return link, nil
}
|
go
|
func setupTapDevice(podID types.UUID) (netlink.Link, error) {
// network device names are limited to 16 characters
// the suffix %d will be replaced by the kernel with a suitable number
nameTemplate := fmt.Sprintf("rkt-%s-tap%%d", podID.String()[0:4])
ifName, err := tuntap.CreatePersistentIface(nameTemplate, tuntap.Tap)
if err != nil {
return nil, errwrap.Wrap(errors.New("tuntap persist"), err)
}
link, err := netlink.LinkByName(ifName)
if err != nil {
return nil, errwrap.Wrap(fmt.Errorf("cannot find link %q", ifName), err)
}
if err := netlink.LinkSetUp(link); err != nil {
return nil, errwrap.Wrap(fmt.Errorf("cannot set link up %q", ifName), err)
}
return link, nil
}
|
[
"func",
"setupTapDevice",
"(",
"podID",
"types",
".",
"UUID",
")",
"(",
"netlink",
".",
"Link",
",",
"error",
")",
"{",
"// network device names are limited to 16 characters",
"// the suffix %d will be replaced by the kernel with a suitable number",
"nameTemplate",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"podID",
".",
"String",
"(",
")",
"[",
"0",
":",
"4",
"]",
")",
"\n",
"ifName",
",",
"err",
":=",
"tuntap",
".",
"CreatePersistentIface",
"(",
"nameTemplate",
",",
"tuntap",
".",
"Tap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"link",
",",
"err",
":=",
"netlink",
".",
"LinkByName",
"(",
"ifName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ifName",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"netlink",
".",
"LinkSetUp",
"(",
"link",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ifName",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"link",
",",
"nil",
"\n",
"}"
] |
// setupTapDevice creates persistent tap device
// and returns a newly created netlink.Link structure
|
[
"setupTapDevice",
"creates",
"persistent",
"tap",
"device",
"and",
"returns",
"a",
"newly",
"created",
"netlink",
".",
"Link",
"structure"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/kvm.go#L59-L77
|
20,913
|
rkt/rkt
|
networking/kvm.go
|
setupMacVTapDevice
|
func setupMacVTapDevice(podID types.UUID, config MacVTapNetConf, interfaceNumber int) (netlink.Link, error) {
master, err := netlink.LinkByName(config.Master)
if err != nil {
return nil, errwrap.Wrap(fmt.Errorf("cannot find master device '%v'", config.Master), err)
}
var mode netlink.MacvlanMode
switch config.Mode {
// if not set - defaults to bridge mode as in:
// https://github.com/rkt/rkt/blob/master/Documentation/networking.md#macvlan
case "", "bridge":
mode = netlink.MACVLAN_MODE_BRIDGE
case "private":
mode = netlink.MACVLAN_MODE_PRIVATE
case "vepa":
mode = netlink.MACVLAN_MODE_VEPA
case "passthru":
mode = netlink.MACVLAN_MODE_PASSTHRU
default:
return nil, fmt.Errorf("unsupported macvtap mode: %v", config.Mode)
}
mtu := master.Attrs().MTU
if config.MTU != 0 {
mtu = config.MTU
}
interfaceName := fmt.Sprintf("rkt-%s-vtap%d", podID.String()[0:4], interfaceNumber)
link := &netlink.Macvtap{
Macvlan: netlink.Macvlan{
LinkAttrs: netlink.LinkAttrs{
Name: interfaceName,
MTU: mtu,
ParentIndex: master.Attrs().Index,
},
Mode: mode,
},
}
if err := netlink.LinkAdd(link); err != nil {
return nil, errwrap.Wrap(errors.New("cannot create macvtap interface"), err)
}
// TODO: duplicate following lines for ipv6 support, when it will be added in other places
ipv4SysctlValueName := fmt.Sprintf(IPv4InterfaceArpProxySysctlTemplate, interfaceName)
if _, err := cnisysctl.Sysctl(ipv4SysctlValueName, "1"); err != nil {
// remove the newly added link and ignore errors, because we already are in a failed state
_ = netlink.LinkDel(link)
return nil, errwrap.Wrap(fmt.Errorf("failed to set proxy_arp on newly added interface %q", interfaceName), err)
}
if err := netlink.LinkSetUp(link); err != nil {
// remove the newly added link and ignore errors, because we already are in a failed state
_ = netlink.LinkDel(link)
return nil, errwrap.Wrap(errors.New("cannot set up macvtap interface"), err)
}
return link, nil
}
|
go
|
func setupMacVTapDevice(podID types.UUID, config MacVTapNetConf, interfaceNumber int) (netlink.Link, error) {
master, err := netlink.LinkByName(config.Master)
if err != nil {
return nil, errwrap.Wrap(fmt.Errorf("cannot find master device '%v'", config.Master), err)
}
var mode netlink.MacvlanMode
switch config.Mode {
// if not set - defaults to bridge mode as in:
// https://github.com/rkt/rkt/blob/master/Documentation/networking.md#macvlan
case "", "bridge":
mode = netlink.MACVLAN_MODE_BRIDGE
case "private":
mode = netlink.MACVLAN_MODE_PRIVATE
case "vepa":
mode = netlink.MACVLAN_MODE_VEPA
case "passthru":
mode = netlink.MACVLAN_MODE_PASSTHRU
default:
return nil, fmt.Errorf("unsupported macvtap mode: %v", config.Mode)
}
mtu := master.Attrs().MTU
if config.MTU != 0 {
mtu = config.MTU
}
interfaceName := fmt.Sprintf("rkt-%s-vtap%d", podID.String()[0:4], interfaceNumber)
link := &netlink.Macvtap{
Macvlan: netlink.Macvlan{
LinkAttrs: netlink.LinkAttrs{
Name: interfaceName,
MTU: mtu,
ParentIndex: master.Attrs().Index,
},
Mode: mode,
},
}
if err := netlink.LinkAdd(link); err != nil {
return nil, errwrap.Wrap(errors.New("cannot create macvtap interface"), err)
}
// TODO: duplicate following lines for ipv6 support, when it will be added in other places
ipv4SysctlValueName := fmt.Sprintf(IPv4InterfaceArpProxySysctlTemplate, interfaceName)
if _, err := cnisysctl.Sysctl(ipv4SysctlValueName, "1"); err != nil {
// remove the newly added link and ignore errors, because we already are in a failed state
_ = netlink.LinkDel(link)
return nil, errwrap.Wrap(fmt.Errorf("failed to set proxy_arp on newly added interface %q", interfaceName), err)
}
if err := netlink.LinkSetUp(link); err != nil {
// remove the newly added link and ignore errors, because we already are in a failed state
_ = netlink.LinkDel(link)
return nil, errwrap.Wrap(errors.New("cannot set up macvtap interface"), err)
}
return link, nil
}
|
[
"func",
"setupMacVTapDevice",
"(",
"podID",
"types",
".",
"UUID",
",",
"config",
"MacVTapNetConf",
",",
"interfaceNumber",
"int",
")",
"(",
"netlink",
".",
"Link",
",",
"error",
")",
"{",
"master",
",",
"err",
":=",
"netlink",
".",
"LinkByName",
"(",
"config",
".",
"Master",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"config",
".",
"Master",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"var",
"mode",
"netlink",
".",
"MacvlanMode",
"\n",
"switch",
"config",
".",
"Mode",
"{",
"// if not set - defaults to bridge mode as in:",
"// https://github.com/rkt/rkt/blob/master/Documentation/networking.md#macvlan",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"mode",
"=",
"netlink",
".",
"MACVLAN_MODE_BRIDGE",
"\n",
"case",
"\"",
"\"",
":",
"mode",
"=",
"netlink",
".",
"MACVLAN_MODE_PRIVATE",
"\n",
"case",
"\"",
"\"",
":",
"mode",
"=",
"netlink",
".",
"MACVLAN_MODE_VEPA",
"\n",
"case",
"\"",
"\"",
":",
"mode",
"=",
"netlink",
".",
"MACVLAN_MODE_PASSTHRU",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"config",
".",
"Mode",
")",
"\n",
"}",
"\n",
"mtu",
":=",
"master",
".",
"Attrs",
"(",
")",
".",
"MTU",
"\n",
"if",
"config",
".",
"MTU",
"!=",
"0",
"{",
"mtu",
"=",
"config",
".",
"MTU",
"\n",
"}",
"\n",
"interfaceName",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"podID",
".",
"String",
"(",
")",
"[",
"0",
":",
"4",
"]",
",",
"interfaceNumber",
")",
"\n",
"link",
":=",
"&",
"netlink",
".",
"Macvtap",
"{",
"Macvlan",
":",
"netlink",
".",
"Macvlan",
"{",
"LinkAttrs",
":",
"netlink",
".",
"LinkAttrs",
"{",
"Name",
":",
"interfaceName",
",",
"MTU",
":",
"mtu",
",",
"ParentIndex",
":",
"master",
".",
"Attrs",
"(",
")",
".",
"Index",
",",
"}",
",",
"Mode",
":",
"mode",
",",
"}",
",",
"}",
"\n\n",
"if",
"err",
":=",
"netlink",
".",
"LinkAdd",
"(",
"link",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// TODO: duplicate following lines for ipv6 support, when it will be added in other places",
"ipv4SysctlValueName",
":=",
"fmt",
".",
"Sprintf",
"(",
"IPv4InterfaceArpProxySysctlTemplate",
",",
"interfaceName",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"cnisysctl",
".",
"Sysctl",
"(",
"ipv4SysctlValueName",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"// remove the newly added link and ignore errors, because we already are in a failed state",
"_",
"=",
"netlink",
".",
"LinkDel",
"(",
"link",
")",
"\n",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"interfaceName",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"netlink",
".",
"LinkSetUp",
"(",
"link",
")",
";",
"err",
"!=",
"nil",
"{",
"// remove the newly added link and ignore errors, because we already are in a failed state",
"_",
"=",
"netlink",
".",
"LinkDel",
"(",
"link",
")",
"\n",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"link",
",",
"nil",
"\n",
"}"
] |
// setupTapDevice creates persistent macvtap device
// and returns a newly created netlink.Link structure
// using part of pod hash and interface number in interface name
|
[
"setupTapDevice",
"creates",
"persistent",
"macvtap",
"device",
"and",
"returns",
"a",
"newly",
"created",
"netlink",
".",
"Link",
"structure",
"using",
"part",
"of",
"pod",
"hash",
"and",
"interface",
"number",
"in",
"interface",
"name"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/kvm.go#L92-L146
|
20,914
|
rkt/rkt
|
networking/kvm.go
|
kvmTeardown
|
func (n *Networking) kvmTeardown() {
if err := n.teardownForwarding(); err != nil {
stderr.PrintE("error removing forwarded ports (kvm)", err)
}
n.teardownKvmNets()
}
|
go
|
func (n *Networking) kvmTeardown() {
if err := n.teardownForwarding(); err != nil {
stderr.PrintE("error removing forwarded ports (kvm)", err)
}
n.teardownKvmNets()
}
|
[
"func",
"(",
"n",
"*",
"Networking",
")",
"kvmTeardown",
"(",
")",
"{",
"if",
"err",
":=",
"n",
".",
"teardownForwarding",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"stderr",
".",
"PrintE",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"n",
".",
"teardownKvmNets",
"(",
")",
"\n",
"}"
] |
// kvmTeardown network teardown for kvm flavor based pods
// similar to Networking.Teardown but without host namespaces
|
[
"kvmTeardown",
"network",
"teardown",
"for",
"kvm",
"flavor",
"based",
"pods",
"similar",
"to",
"Networking",
".",
"Teardown",
"but",
"without",
"host",
"namespaces"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/kvm.go#L705-L711
|
20,915
|
rkt/rkt
|
rkt/image/filefetcher.go
|
Hash
|
func (f *fileFetcher) Hash(aciPath string, a *asc) (string, error) {
ensureLogger(f.Debug)
absPath, err := filepath.Abs(aciPath)
if err != nil {
return "", errwrap.Wrap(fmt.Errorf("failed to get an absolute path for %q", aciPath), err)
}
aciPath = absPath
aciFile, err := f.getFile(aciPath, a)
if err != nil {
return "", err
}
defer aciFile.Close()
key, err := f.S.WriteACI(aciFile, imagestore.ACIFetchInfo{
Latest: false,
})
if err != nil {
return "", err
}
return key, nil
}
|
go
|
func (f *fileFetcher) Hash(aciPath string, a *asc) (string, error) {
ensureLogger(f.Debug)
absPath, err := filepath.Abs(aciPath)
if err != nil {
return "", errwrap.Wrap(fmt.Errorf("failed to get an absolute path for %q", aciPath), err)
}
aciPath = absPath
aciFile, err := f.getFile(aciPath, a)
if err != nil {
return "", err
}
defer aciFile.Close()
key, err := f.S.WriteACI(aciFile, imagestore.ACIFetchInfo{
Latest: false,
})
if err != nil {
return "", err
}
return key, nil
}
|
[
"func",
"(",
"f",
"*",
"fileFetcher",
")",
"Hash",
"(",
"aciPath",
"string",
",",
"a",
"*",
"asc",
")",
"(",
"string",
",",
"error",
")",
"{",
"ensureLogger",
"(",
"f",
".",
"Debug",
")",
"\n",
"absPath",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"aciPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"aciPath",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"aciPath",
"=",
"absPath",
"\n\n",
"aciFile",
",",
"err",
":=",
"f",
".",
"getFile",
"(",
"aciPath",
",",
"a",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"defer",
"aciFile",
".",
"Close",
"(",
")",
"\n\n",
"key",
",",
"err",
":=",
"f",
".",
"S",
".",
"WriteACI",
"(",
"aciFile",
",",
"imagestore",
".",
"ACIFetchInfo",
"{",
"Latest",
":",
"false",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"key",
",",
"nil",
"\n",
"}"
] |
// Hash opens a file, optionally verifies it against passed asc,
// stores it in the store and returns the hash.
|
[
"Hash",
"opens",
"a",
"file",
"optionally",
"verifies",
"it",
"against",
"passed",
"asc",
"stores",
"it",
"in",
"the",
"store",
"and",
"returns",
"the",
"hash",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/filefetcher.go#L39-L61
|
20,916
|
rkt/rkt
|
rkt/image/filefetcher.go
|
getVerifiedFile
|
func (f *fileFetcher) getVerifiedFile(aciPath string, a *asc) (*os.File, error) {
var aciFile *os.File // closed on error
var errClose error // error signaling to close aciFile
f.maybeOverrideAsc(aciPath, a)
ascFile, err := a.Get()
if err != nil {
return nil, errwrap.Wrap(errors.New("error opening signature file"), err)
}
defer ascFile.Close()
aciFile, err = os.Open(aciPath)
if err != nil {
return nil, errwrap.Wrap(errors.New("error opening ACI file"), err)
}
defer func() {
if errClose != nil {
aciFile.Close()
}
}()
validator, errClose := newValidator(aciFile)
if errClose != nil {
return nil, errClose
}
entity, errClose := validator.ValidateWithSignature(f.Ks, ascFile)
if errClose != nil {
return nil, errwrap.Wrap(fmt.Errorf("image %q verification failed", validator.ImageName()), errClose)
}
printIdentities(entity)
return aciFile, nil
}
|
go
|
func (f *fileFetcher) getVerifiedFile(aciPath string, a *asc) (*os.File, error) {
var aciFile *os.File // closed on error
var errClose error // error signaling to close aciFile
f.maybeOverrideAsc(aciPath, a)
ascFile, err := a.Get()
if err != nil {
return nil, errwrap.Wrap(errors.New("error opening signature file"), err)
}
defer ascFile.Close()
aciFile, err = os.Open(aciPath)
if err != nil {
return nil, errwrap.Wrap(errors.New("error opening ACI file"), err)
}
defer func() {
if errClose != nil {
aciFile.Close()
}
}()
validator, errClose := newValidator(aciFile)
if errClose != nil {
return nil, errClose
}
entity, errClose := validator.ValidateWithSignature(f.Ks, ascFile)
if errClose != nil {
return nil, errwrap.Wrap(fmt.Errorf("image %q verification failed", validator.ImageName()), errClose)
}
printIdentities(entity)
return aciFile, nil
}
|
[
"func",
"(",
"f",
"*",
"fileFetcher",
")",
"getVerifiedFile",
"(",
"aciPath",
"string",
",",
"a",
"*",
"asc",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"var",
"aciFile",
"*",
"os",
".",
"File",
"// closed on error",
"\n",
"var",
"errClose",
"error",
"// error signaling to close aciFile",
"\n\n",
"f",
".",
"maybeOverrideAsc",
"(",
"aciPath",
",",
"a",
")",
"\n",
"ascFile",
",",
"err",
":=",
"a",
".",
"Get",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ascFile",
".",
"Close",
"(",
")",
"\n\n",
"aciFile",
",",
"err",
"=",
"os",
".",
"Open",
"(",
"aciPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"defer",
"func",
"(",
")",
"{",
"if",
"errClose",
"!=",
"nil",
"{",
"aciFile",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"validator",
",",
"errClose",
":=",
"newValidator",
"(",
"aciFile",
")",
"\n",
"if",
"errClose",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errClose",
"\n",
"}",
"\n\n",
"entity",
",",
"errClose",
":=",
"validator",
".",
"ValidateWithSignature",
"(",
"f",
".",
"Ks",
",",
"ascFile",
")",
"\n",
"if",
"errClose",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"validator",
".",
"ImageName",
"(",
")",
")",
",",
"errClose",
")",
"\n",
"}",
"\n",
"printIdentities",
"(",
"entity",
")",
"\n\n",
"return",
"aciFile",
",",
"nil",
"\n",
"}"
] |
// fetch opens and verifies the ACI.
|
[
"fetch",
"opens",
"and",
"verifies",
"the",
"ACI",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/filefetcher.go#L82-L116
|
20,917
|
rkt/rkt
|
pkg/fs/mount.go
|
NewLoggingMounter
|
func NewLoggingMounter(m Mounter, um Unmounter, logf func(string, ...interface{})) MountUnmounter {
return &loggingMounter{m, um, logf}
}
|
go
|
func NewLoggingMounter(m Mounter, um Unmounter, logf func(string, ...interface{})) MountUnmounter {
return &loggingMounter{m, um, logf}
}
|
[
"func",
"NewLoggingMounter",
"(",
"m",
"Mounter",
",",
"um",
"Unmounter",
",",
"logf",
"func",
"(",
"string",
",",
"...",
"interface",
"{",
"}",
")",
")",
"MountUnmounter",
"{",
"return",
"&",
"loggingMounter",
"{",
"m",
",",
"um",
",",
"logf",
"}",
"\n",
"}"
] |
// NewLoggingMounter returns a MountUnmounter that logs mount events using the given logger func.
|
[
"NewLoggingMounter",
"returns",
"a",
"MountUnmounter",
"that",
"logs",
"mount",
"events",
"using",
"the",
"given",
"logger",
"func",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/fs/mount.go#L56-L58
|
20,918
|
rkt/rkt
|
pkg/tpm/tpm.go
|
Extend
|
func Extend(description string) error {
connection := tpmclient.New("localhost:12041", timeout)
err := connection.Extend(15, 0x1000, nil, description)
return err
}
|
go
|
func Extend(description string) error {
connection := tpmclient.New("localhost:12041", timeout)
err := connection.Extend(15, 0x1000, nil, description)
return err
}
|
[
"func",
"Extend",
"(",
"description",
"string",
")",
"error",
"{",
"connection",
":=",
"tpmclient",
".",
"New",
"(",
"\"",
"\"",
",",
"timeout",
")",
"\n",
"err",
":=",
"connection",
".",
"Extend",
"(",
"15",
",",
"0x1000",
",",
"nil",
",",
"description",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Extend extends the TPM log with the provided string. Returns any error.
|
[
"Extend",
"extends",
"the",
"TPM",
"log",
"with",
"the",
"provided",
"string",
".",
"Returns",
"any",
"error",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/tpm/tpm.go#L29-L33
|
20,919
|
rkt/rkt
|
common/common.go
|
Stage1RootfsPath
|
func Stage1RootfsPath(root string) string {
return filepath.Join(Stage1ImagePath(root), aci.RootfsDir)
}
|
go
|
func Stage1RootfsPath(root string) string {
return filepath.Join(Stage1ImagePath(root), aci.RootfsDir)
}
|
[
"func",
"Stage1RootfsPath",
"(",
"root",
"string",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"Stage1ImagePath",
"(",
"root",
")",
",",
"aci",
".",
"RootfsDir",
")",
"\n",
"}"
] |
// Stage1RootfsPath returns the path to the stage1 rootfs
|
[
"Stage1RootfsPath",
"returns",
"the",
"path",
"to",
"the",
"stage1",
"rootfs"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L101-L103
|
20,920
|
rkt/rkt
|
common/common.go
|
Stage1ManifestPath
|
func Stage1ManifestPath(root string) string {
return filepath.Join(Stage1ImagePath(root), aci.ManifestFile)
}
|
go
|
func Stage1ManifestPath(root string) string {
return filepath.Join(Stage1ImagePath(root), aci.ManifestFile)
}
|
[
"func",
"Stage1ManifestPath",
"(",
"root",
"string",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"Stage1ImagePath",
"(",
"root",
")",
",",
"aci",
".",
"ManifestFile",
")",
"\n",
"}"
] |
// Stage1ManifestPath returns the path to the stage1's manifest file inside the expanded ACI.
|
[
"Stage1ManifestPath",
"returns",
"the",
"path",
"to",
"the",
"stage1",
"s",
"manifest",
"file",
"inside",
"the",
"expanded",
"ACI",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L106-L108
|
20,921
|
rkt/rkt
|
common/common.go
|
AppStatusPath
|
func AppStatusPath(root, appName string) string {
return filepath.Join(AppsStatusesPath(root), appName)
}
|
go
|
func AppStatusPath(root, appName string) string {
return filepath.Join(AppsStatusesPath(root), appName)
}
|
[
"func",
"AppStatusPath",
"(",
"root",
",",
"appName",
"string",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"AppsStatusesPath",
"(",
"root",
")",
",",
"appName",
")",
"\n",
"}"
] |
// AppStatusPath returns the path of the status file of an app.
|
[
"AppStatusPath",
"returns",
"the",
"path",
"of",
"the",
"status",
"file",
"of",
"an",
"app",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L140-L142
|
20,922
|
rkt/rkt
|
common/common.go
|
AppStatusPathFromStage1Rootfs
|
func AppStatusPathFromStage1Rootfs(rootfs, appName string) string {
return filepath.Join(AppsStatusesPathFromStage1Rootfs(rootfs), appName)
}
|
go
|
func AppStatusPathFromStage1Rootfs(rootfs, appName string) string {
return filepath.Join(AppsStatusesPathFromStage1Rootfs(rootfs), appName)
}
|
[
"func",
"AppStatusPathFromStage1Rootfs",
"(",
"rootfs",
",",
"appName",
"string",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"AppsStatusesPathFromStage1Rootfs",
"(",
"rootfs",
")",
",",
"appName",
")",
"\n",
"}"
] |
// AppStatusPathFromStage1Rootfs returns the path of the status file of an app.
// It receives the stage1 rootfs as parameter instead of the pod root.
|
[
"AppStatusPathFromStage1Rootfs",
"returns",
"the",
"path",
"of",
"the",
"status",
"file",
"of",
"an",
"app",
".",
"It",
"receives",
"the",
"stage1",
"rootfs",
"as",
"parameter",
"instead",
"of",
"the",
"pod",
"root",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L146-L148
|
20,923
|
rkt/rkt
|
common/common.go
|
AppPath
|
func AppPath(root string, appName types.ACName) string {
return filepath.Join(AppsPath(root), appName.String())
}
|
go
|
func AppPath(root string, appName types.ACName) string {
return filepath.Join(AppsPath(root), appName.String())
}
|
[
"func",
"AppPath",
"(",
"root",
"string",
",",
"appName",
"types",
".",
"ACName",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"AppsPath",
"(",
"root",
")",
",",
"appName",
".",
"String",
"(",
")",
")",
"\n",
"}"
] |
// AppPath returns the path to an app's rootfs.
|
[
"AppPath",
"returns",
"the",
"path",
"to",
"an",
"app",
"s",
"rootfs",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L182-L184
|
20,924
|
rkt/rkt
|
common/common.go
|
AppRootfsPath
|
func AppRootfsPath(root string, appName types.ACName) string {
return filepath.Join(AppPath(root, appName), aci.RootfsDir)
}
|
go
|
func AppRootfsPath(root string, appName types.ACName) string {
return filepath.Join(AppPath(root, appName), aci.RootfsDir)
}
|
[
"func",
"AppRootfsPath",
"(",
"root",
"string",
",",
"appName",
"types",
".",
"ACName",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"AppPath",
"(",
"root",
",",
"appName",
")",
",",
"aci",
".",
"RootfsDir",
")",
"\n",
"}"
] |
// AppRootfsPath returns the path to an app's rootfs.
|
[
"AppRootfsPath",
"returns",
"the",
"path",
"to",
"an",
"app",
"s",
"rootfs",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L187-L189
|
20,925
|
rkt/rkt
|
common/common.go
|
RelAppPath
|
func RelAppPath(appName types.ACName) string {
return filepath.Join(stage2Dir, appName.String())
}
|
go
|
func RelAppPath(appName types.ACName) string {
return filepath.Join(stage2Dir, appName.String())
}
|
[
"func",
"RelAppPath",
"(",
"appName",
"types",
".",
"ACName",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"stage2Dir",
",",
"appName",
".",
"String",
"(",
")",
")",
"\n",
"}"
] |
// RelAppPath returns the path of an app relative to the stage1 chroot.
|
[
"RelAppPath",
"returns",
"the",
"path",
"of",
"an",
"app",
"relative",
"to",
"the",
"stage1",
"chroot",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L192-L194
|
20,926
|
rkt/rkt
|
common/common.go
|
RelAppRootfsPath
|
func RelAppRootfsPath(appName types.ACName) string {
return filepath.Join(RelAppPath(appName), aci.RootfsDir)
}
|
go
|
func RelAppRootfsPath(appName types.ACName) string {
return filepath.Join(RelAppPath(appName), aci.RootfsDir)
}
|
[
"func",
"RelAppRootfsPath",
"(",
"appName",
"types",
".",
"ACName",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"RelAppPath",
"(",
"appName",
")",
",",
"aci",
".",
"RootfsDir",
")",
"\n",
"}"
] |
// RelAppRootfsPath returns the path of an app's rootfs relative to the stage1 chroot.
|
[
"RelAppRootfsPath",
"returns",
"the",
"path",
"of",
"an",
"app",
"s",
"rootfs",
"relative",
"to",
"the",
"stage1",
"chroot",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L197-L199
|
20,927
|
rkt/rkt
|
common/common.go
|
ImageManifestPath
|
func ImageManifestPath(root string, appName types.ACName) string {
return filepath.Join(AppPath(root, appName), aci.ManifestFile)
}
|
go
|
func ImageManifestPath(root string, appName types.ACName) string {
return filepath.Join(AppPath(root, appName), aci.ManifestFile)
}
|
[
"func",
"ImageManifestPath",
"(",
"root",
"string",
",",
"appName",
"types",
".",
"ACName",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"AppPath",
"(",
"root",
",",
"appName",
")",
",",
"aci",
".",
"ManifestFile",
")",
"\n",
"}"
] |
// ImageManifestPath returns the path to the app's manifest file of a pod.
|
[
"ImageManifestPath",
"returns",
"the",
"path",
"to",
"the",
"app",
"s",
"manifest",
"file",
"of",
"a",
"pod",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L202-L204
|
20,928
|
rkt/rkt
|
common/common.go
|
AppInfoPath
|
func AppInfoPath(root string, appName types.ACName) string {
return filepath.Join(AppsInfoPath(root), appName.String())
}
|
go
|
func AppInfoPath(root string, appName types.ACName) string {
return filepath.Join(AppsInfoPath(root), appName.String())
}
|
[
"func",
"AppInfoPath",
"(",
"root",
"string",
",",
"appName",
"types",
".",
"ACName",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"AppsInfoPath",
"(",
"root",
")",
",",
"appName",
".",
"String",
"(",
")",
")",
"\n",
"}"
] |
// AppInfoPath returns the path to the app's appsinfo directory of a pod.
|
[
"AppInfoPath",
"returns",
"the",
"path",
"to",
"the",
"app",
"s",
"appsinfo",
"directory",
"of",
"a",
"pod",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L212-L214
|
20,929
|
rkt/rkt
|
common/common.go
|
AppTreeStoreIDPath
|
func AppTreeStoreIDPath(root string, appName types.ACName) string {
return filepath.Join(AppInfoPath(root, appName), AppTreeStoreIDFilename)
}
|
go
|
func AppTreeStoreIDPath(root string, appName types.ACName) string {
return filepath.Join(AppInfoPath(root, appName), AppTreeStoreIDFilename)
}
|
[
"func",
"AppTreeStoreIDPath",
"(",
"root",
"string",
",",
"appName",
"types",
".",
"ACName",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"AppInfoPath",
"(",
"root",
",",
"appName",
")",
",",
"AppTreeStoreIDFilename",
")",
"\n",
"}"
] |
// AppTreeStoreIDPath returns the path to the app's treeStoreID file of a pod.
|
[
"AppTreeStoreIDPath",
"returns",
"the",
"path",
"to",
"the",
"app",
"s",
"treeStoreID",
"file",
"of",
"a",
"pod",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L217-L219
|
20,930
|
rkt/rkt
|
common/common.go
|
AppImageManifestPath
|
func AppImageManifestPath(root string, appName types.ACName) string {
return filepath.Join(AppInfoPath(root, appName), aci.ManifestFile)
}
|
go
|
func AppImageManifestPath(root string, appName types.ACName) string {
return filepath.Join(AppInfoPath(root, appName), aci.ManifestFile)
}
|
[
"func",
"AppImageManifestPath",
"(",
"root",
"string",
",",
"appName",
"types",
".",
"ACName",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"AppInfoPath",
"(",
"root",
",",
"appName",
")",
",",
"aci",
".",
"ManifestFile",
")",
"\n",
"}"
] |
// AppImageManifestPath returns the path to the app's ImageManifest file
|
[
"AppImageManifestPath",
"returns",
"the",
"path",
"to",
"the",
"app",
"s",
"ImageManifest",
"file"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L222-L224
|
20,931
|
rkt/rkt
|
common/common.go
|
CreateSharedVolumesPath
|
func CreateSharedVolumesPath(root string) (string, error) {
sharedVolPath := SharedVolumesPath(root)
if err := os.MkdirAll(sharedVolPath, SharedVolumePerm); err != nil {
return "", errwrap.Wrap(errors.New("could not create shared volumes directory"), err)
}
// In case it already existed and we didn't make it, ensure permissions are
// what the caller expects them to be.
if err := os.Chmod(sharedVolPath, SharedVolumePerm); err != nil {
return "", errwrap.Wrap(fmt.Errorf("could not change permissions of %q", sharedVolPath), err)
}
return sharedVolPath, nil
}
|
go
|
func CreateSharedVolumesPath(root string) (string, error) {
sharedVolPath := SharedVolumesPath(root)
if err := os.MkdirAll(sharedVolPath, SharedVolumePerm); err != nil {
return "", errwrap.Wrap(errors.New("could not create shared volumes directory"), err)
}
// In case it already existed and we didn't make it, ensure permissions are
// what the caller expects them to be.
if err := os.Chmod(sharedVolPath, SharedVolumePerm); err != nil {
return "", errwrap.Wrap(fmt.Errorf("could not change permissions of %q", sharedVolPath), err)
}
return sharedVolPath, nil
}
|
[
"func",
"CreateSharedVolumesPath",
"(",
"root",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"sharedVolPath",
":=",
"SharedVolumesPath",
"(",
"root",
")",
"\n\n",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"sharedVolPath",
",",
"SharedVolumePerm",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"// In case it already existed and we didn't make it, ensure permissions are",
"// what the caller expects them to be.",
"if",
"err",
":=",
"os",
".",
"Chmod",
"(",
"sharedVolPath",
",",
"SharedVolumePerm",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sharedVolPath",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"sharedVolPath",
",",
"nil",
"\n",
"}"
] |
// CreateSharedVolumesPath ensures the sharedVolumePath for the pod root passed
// in exists. It returns the shared volume path or an error.
|
[
"CreateSharedVolumesPath",
"ensures",
"the",
"sharedVolumePath",
"for",
"the",
"pod",
"root",
"passed",
"in",
"exists",
".",
"It",
"returns",
"the",
"shared",
"volume",
"path",
"or",
"an",
"error",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L233-L246
|
20,932
|
rkt/rkt
|
common/common.go
|
MetadataServicePublicURL
|
func MetadataServicePublicURL(ip net.IP, token string) string {
return fmt.Sprintf("http://%v:%v/%v", ip, MetadataServicePort, token)
}
|
go
|
func MetadataServicePublicURL(ip net.IP, token string) string {
return fmt.Sprintf("http://%v:%v/%v", ip, MetadataServicePort, token)
}
|
[
"func",
"MetadataServicePublicURL",
"(",
"ip",
"net",
".",
"IP",
",",
"token",
"string",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ip",
",",
"MetadataServicePort",
",",
"token",
")",
"\n",
"}"
] |
// MetadataServicePublicURL returns the public URL used to host the metadata service
|
[
"MetadataServicePublicURL",
"returns",
"the",
"public",
"URL",
"used",
"to",
"host",
"the",
"metadata",
"service"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L249-L251
|
20,933
|
rkt/rkt
|
common/common.go
|
LookupPath
|
func LookupPath(bin string, paths string) (string, error) {
pathsArr := filepath.SplitList(paths)
for _, path := range pathsArr {
binPath := filepath.Join(path, bin)
binAbsPath, err := filepath.Abs(binPath)
if err != nil {
return "", fmt.Errorf("unable to find absolute path for %s", binPath)
}
if fileutil.IsExecutable(binAbsPath) {
return binAbsPath, nil
}
}
return "", fmt.Errorf("unable to find %q in %q", bin, paths)
}
|
go
|
func LookupPath(bin string, paths string) (string, error) {
pathsArr := filepath.SplitList(paths)
for _, path := range pathsArr {
binPath := filepath.Join(path, bin)
binAbsPath, err := filepath.Abs(binPath)
if err != nil {
return "", fmt.Errorf("unable to find absolute path for %s", binPath)
}
if fileutil.IsExecutable(binAbsPath) {
return binAbsPath, nil
}
}
return "", fmt.Errorf("unable to find %q in %q", bin, paths)
}
|
[
"func",
"LookupPath",
"(",
"bin",
"string",
",",
"paths",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"pathsArr",
":=",
"filepath",
".",
"SplitList",
"(",
"paths",
")",
"\n",
"for",
"_",
",",
"path",
":=",
"range",
"pathsArr",
"{",
"binPath",
":=",
"filepath",
".",
"Join",
"(",
"path",
",",
"bin",
")",
"\n",
"binAbsPath",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"binPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"binPath",
")",
"\n",
"}",
"\n",
"if",
"fileutil",
".",
"IsExecutable",
"(",
"binAbsPath",
")",
"{",
"return",
"binAbsPath",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"bin",
",",
"paths",
")",
"\n",
"}"
] |
// LookupPath search for bin in paths. If found, it returns its absolute path,
// if not, an error
|
[
"LookupPath",
"search",
"for",
"bin",
"in",
"paths",
".",
"If",
"found",
"it",
"returns",
"its",
"absolute",
"path",
"if",
"not",
"an",
"error"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L375-L388
|
20,934
|
rkt/rkt
|
common/common.go
|
SystemdVersion
|
func SystemdVersion(systemdBinaryPath string) (int, error) {
versionBytes, err := exec.Command(systemdBinaryPath, "--version").CombinedOutput()
if err != nil {
return -1, errwrap.Wrap(fmt.Errorf("unable to probe %s version", systemdBinaryPath), err)
}
versionStr := strings.SplitN(string(versionBytes), "\n", 2)[0]
var version int
n, err := fmt.Sscanf(versionStr, "systemd %d", &version)
if err != nil || n != 1 {
return -1, fmt.Errorf("cannot parse version: %q", versionStr)
}
return version, nil
}
|
go
|
func SystemdVersion(systemdBinaryPath string) (int, error) {
versionBytes, err := exec.Command(systemdBinaryPath, "--version").CombinedOutput()
if err != nil {
return -1, errwrap.Wrap(fmt.Errorf("unable to probe %s version", systemdBinaryPath), err)
}
versionStr := strings.SplitN(string(versionBytes), "\n", 2)[0]
var version int
n, err := fmt.Sscanf(versionStr, "systemd %d", &version)
if err != nil || n != 1 {
return -1, fmt.Errorf("cannot parse version: %q", versionStr)
}
return version, nil
}
|
[
"func",
"SystemdVersion",
"(",
"systemdBinaryPath",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"versionBytes",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"systemdBinaryPath",
",",
"\"",
"\"",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"systemdBinaryPath",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"versionStr",
":=",
"strings",
".",
"SplitN",
"(",
"string",
"(",
"versionBytes",
")",
",",
"\"",
"\\n",
"\"",
",",
"2",
")",
"[",
"0",
"]",
"\n",
"var",
"version",
"int",
"\n",
"n",
",",
"err",
":=",
"fmt",
".",
"Sscanf",
"(",
"versionStr",
",",
"\"",
"\"",
",",
"&",
"version",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"n",
"!=",
"1",
"{",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"versionStr",
")",
"\n",
"}",
"\n\n",
"return",
"version",
",",
"nil",
"\n",
"}"
] |
// SystemdVersion parses and returns the version of a given systemd binary
|
[
"SystemdVersion",
"parses",
"and",
"returns",
"the",
"version",
"of",
"a",
"given",
"systemd",
"binary"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L391-L404
|
20,935
|
rkt/rkt
|
common/common.go
|
SupportsOverlay
|
func SupportsOverlay() error {
// ignore exec.Command error, modprobe may not be present on the system,
// or the kernel module will fail to load.
// we'll find out by reading the side effect in /proc/filesystems
_ = exec.Command("modprobe", "overlay").Run()
f, err := os.Open("/proc/filesystems")
if err != nil {
// don't use errwrap so consumers can type-check on ErrOverlayUnsupported
return ErrOverlayUnsupported(fmt.Sprintf("cannot open /proc/filesystems: %v", err))
}
defer f.Close()
s := bufio.NewScanner(f)
for s.Scan() {
if s.Text() == "nodev\toverlay" {
return nil
}
}
return ErrOverlayUnsupported("overlay entry not present in /proc/filesystems")
}
|
go
|
func SupportsOverlay() error {
// ignore exec.Command error, modprobe may not be present on the system,
// or the kernel module will fail to load.
// we'll find out by reading the side effect in /proc/filesystems
_ = exec.Command("modprobe", "overlay").Run()
f, err := os.Open("/proc/filesystems")
if err != nil {
// don't use errwrap so consumers can type-check on ErrOverlayUnsupported
return ErrOverlayUnsupported(fmt.Sprintf("cannot open /proc/filesystems: %v", err))
}
defer f.Close()
s := bufio.NewScanner(f)
for s.Scan() {
if s.Text() == "nodev\toverlay" {
return nil
}
}
return ErrOverlayUnsupported("overlay entry not present in /proc/filesystems")
}
|
[
"func",
"SupportsOverlay",
"(",
")",
"error",
"{",
"// ignore exec.Command error, modprobe may not be present on the system,",
"// or the kernel module will fail to load.",
"// we'll find out by reading the side effect in /proc/filesystems",
"_",
"=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"Run",
"(",
")",
"\n\n",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// don't use errwrap so consumers can type-check on ErrOverlayUnsupported",
"return",
"ErrOverlayUnsupported",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"s",
":=",
"bufio",
".",
"NewScanner",
"(",
"f",
")",
"\n",
"for",
"s",
".",
"Scan",
"(",
")",
"{",
"if",
"s",
".",
"Text",
"(",
")",
"==",
"\"",
"\\t",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"ErrOverlayUnsupported",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// SupportsOverlay returns whether the operating system generally supports OverlayFS,
// returning an instance of ErrOverlayUnsupported which encodes the reason.
// It is sufficient to check for nil if the reason is not of interest.
|
[
"SupportsOverlay",
"returns",
"whether",
"the",
"operating",
"system",
"generally",
"supports",
"OverlayFS",
"returning",
"an",
"instance",
"of",
"ErrOverlayUnsupported",
"which",
"encodes",
"the",
"reason",
".",
"It",
"is",
"sufficient",
"to",
"check",
"for",
"nil",
"if",
"the",
"reason",
"is",
"not",
"of",
"interest",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L409-L430
|
20,936
|
rkt/rkt
|
common/common.go
|
RemoveEmptyLines
|
func RemoveEmptyLines(str string) []string {
lines := make([]string, 0)
for _, v := range strings.Split(str, "\n") {
if len(v) > 0 {
lines = append(lines, v)
}
}
return lines
}
|
go
|
func RemoveEmptyLines(str string) []string {
lines := make([]string, 0)
for _, v := range strings.Split(str, "\n") {
if len(v) > 0 {
lines = append(lines, v)
}
}
return lines
}
|
[
"func",
"RemoveEmptyLines",
"(",
"str",
"string",
")",
"[",
"]",
"string",
"{",
"lines",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n\n",
"for",
"_",
",",
"v",
":=",
"range",
"strings",
".",
"Split",
"(",
"str",
",",
"\"",
"\\n",
"\"",
")",
"{",
"if",
"len",
"(",
"v",
")",
">",
"0",
"{",
"lines",
"=",
"append",
"(",
"lines",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"lines",
"\n",
"}"
] |
// RemoveEmptyLines removes empty lines from the given string
// and breaks it up into a list of strings at newline characters
|
[
"RemoveEmptyLines",
"removes",
"empty",
"lines",
"from",
"the",
"given",
"string",
"and",
"breaks",
"it",
"up",
"into",
"a",
"list",
"of",
"strings",
"at",
"newline",
"characters"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L490-L500
|
20,937
|
rkt/rkt
|
common/common.go
|
GetExitStatus
|
func GetExitStatus(err error) (int, error) {
if err == nil {
return 0, nil
}
if exiterr, ok := err.(*exec.ExitError); ok {
// the program has exited with an exit code != 0
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
return status.ExitStatus(), nil
}
}
return -1, err
}
|
go
|
func GetExitStatus(err error) (int, error) {
if err == nil {
return 0, nil
}
if exiterr, ok := err.(*exec.ExitError); ok {
// the program has exited with an exit code != 0
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
return status.ExitStatus(), nil
}
}
return -1, err
}
|
[
"func",
"GetExitStatus",
"(",
"err",
"error",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"if",
"exiterr",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"exec",
".",
"ExitError",
")",
";",
"ok",
"{",
"// the program has exited with an exit code != 0",
"if",
"status",
",",
"ok",
":=",
"exiterr",
".",
"Sys",
"(",
")",
".",
"(",
"syscall",
".",
"WaitStatus",
")",
";",
"ok",
"{",
"return",
"status",
".",
"ExitStatus",
"(",
")",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
",",
"err",
"\n",
"}"
] |
// GetExitStatus converts an error to an exit status. If it wasn't an exit
// status != 0 it returns the same error that it was called with
|
[
"GetExitStatus",
"converts",
"an",
"error",
"to",
"an",
"exit",
"status",
".",
"If",
"it",
"wasn",
"t",
"an",
"exit",
"status",
"!",
"=",
"0",
"it",
"returns",
"the",
"same",
"error",
"that",
"it",
"was",
"called",
"with"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L504-L515
|
20,938
|
rkt/rkt
|
common/common.go
|
ImageNameToAppName
|
func ImageNameToAppName(name types.ACIdentifier) (*types.ACName, error) {
parts := strings.Split(name.String(), "/")
last := parts[len(parts)-1]
sn, err := types.SanitizeACName(last)
if err != nil {
return nil, err
}
return types.MustACName(sn), nil
}
|
go
|
func ImageNameToAppName(name types.ACIdentifier) (*types.ACName, error) {
parts := strings.Split(name.String(), "/")
last := parts[len(parts)-1]
sn, err := types.SanitizeACName(last)
if err != nil {
return nil, err
}
return types.MustACName(sn), nil
}
|
[
"func",
"ImageNameToAppName",
"(",
"name",
"types",
".",
"ACIdentifier",
")",
"(",
"*",
"types",
".",
"ACName",
",",
"error",
")",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"name",
".",
"String",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"last",
":=",
"parts",
"[",
"len",
"(",
"parts",
")",
"-",
"1",
"]",
"\n\n",
"sn",
",",
"err",
":=",
"types",
".",
"SanitizeACName",
"(",
"last",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"types",
".",
"MustACName",
"(",
"sn",
")",
",",
"nil",
"\n",
"}"
] |
// ImageNameToAppName converts the full name of image to an app name without special
// characters - we use it as a default app name when specyfing it is optional
|
[
"ImageNameToAppName",
"converts",
"the",
"full",
"name",
"of",
"image",
"to",
"an",
"app",
"name",
"without",
"special",
"characters",
"-",
"we",
"use",
"it",
"as",
"a",
"default",
"app",
"name",
"when",
"specyfing",
"it",
"is",
"optional"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/common/common.go#L545-L555
|
20,939
|
rkt/rkt
|
stage1/init/kvm/network.go
|
GetNetworkDescriptions
|
func GetNetworkDescriptions(n *networking.Networking) []NetDescriber {
var nds []NetDescriber
for _, an := range n.GetActiveNetworks() {
nds = append(nds, an)
}
return nds
}
|
go
|
func GetNetworkDescriptions(n *networking.Networking) []NetDescriber {
var nds []NetDescriber
for _, an := range n.GetActiveNetworks() {
nds = append(nds, an)
}
return nds
}
|
[
"func",
"GetNetworkDescriptions",
"(",
"n",
"*",
"networking",
".",
"Networking",
")",
"[",
"]",
"NetDescriber",
"{",
"var",
"nds",
"[",
"]",
"NetDescriber",
"\n",
"for",
"_",
",",
"an",
":=",
"range",
"n",
".",
"GetActiveNetworks",
"(",
")",
"{",
"nds",
"=",
"append",
"(",
"nds",
",",
"an",
")",
"\n",
"}",
"\n",
"return",
"nds",
"\n",
"}"
] |
// GetNetworkDescriptions converts activeNets to netDescribers
|
[
"GetNetworkDescriptions",
"converts",
"activeNets",
"to",
"netDescribers"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/kvm/network.go#L32-L38
|
20,940
|
rkt/rkt
|
stage1/init/kvm/network.go
|
GetKVMNetArgs
|
func GetKVMNetArgs(nds []NetDescriber) ([]string, error) {
var lkvmArgs []string
for _, nd := range nds {
lkvmArgs = append(lkvmArgs, "--network")
lkvmArg := fmt.Sprintf("mode=tap,tapif=%s,host_ip=%s,guest_ip=%s", nd.IfName(), nd.Gateway(), nd.GuestIP())
lkvmArgs = append(lkvmArgs, lkvmArg)
}
return lkvmArgs, nil
}
|
go
|
func GetKVMNetArgs(nds []NetDescriber) ([]string, error) {
var lkvmArgs []string
for _, nd := range nds {
lkvmArgs = append(lkvmArgs, "--network")
lkvmArg := fmt.Sprintf("mode=tap,tapif=%s,host_ip=%s,guest_ip=%s", nd.IfName(), nd.Gateway(), nd.GuestIP())
lkvmArgs = append(lkvmArgs, lkvmArg)
}
return lkvmArgs, nil
}
|
[
"func",
"GetKVMNetArgs",
"(",
"nds",
"[",
"]",
"NetDescriber",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"lkvmArgs",
"[",
"]",
"string",
"\n\n",
"for",
"_",
",",
"nd",
":=",
"range",
"nds",
"{",
"lkvmArgs",
"=",
"append",
"(",
"lkvmArgs",
",",
"\"",
"\"",
")",
"\n",
"lkvmArg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"nd",
".",
"IfName",
"(",
")",
",",
"nd",
".",
"Gateway",
"(",
")",
",",
"nd",
".",
"GuestIP",
"(",
")",
")",
"\n",
"lkvmArgs",
"=",
"append",
"(",
"lkvmArgs",
",",
"lkvmArg",
")",
"\n",
"}",
"\n\n",
"return",
"lkvmArgs",
",",
"nil",
"\n",
"}"
] |
// GetKVMNetArgs returns additional arguments that need to be passed
// to lkvm tool to configure networks properly.
// Logic is based on Network configuration extracted from Networking struct
// and essentially from activeNets that expose netDescriber behavior
|
[
"GetKVMNetArgs",
"returns",
"additional",
"arguments",
"that",
"need",
"to",
"be",
"passed",
"to",
"lkvm",
"tool",
"to",
"configure",
"networks",
"properly",
".",
"Logic",
"is",
"based",
"on",
"Network",
"configuration",
"extracted",
"from",
"Networking",
"struct",
"and",
"essentially",
"from",
"activeNets",
"that",
"expose",
"netDescriber",
"behavior"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/kvm/network.go#L55-L66
|
20,941
|
rkt/rkt
|
stage1/init/kvm/network.go
|
generateMacAddress
|
func generateMacAddress() (net.HardwareAddr, error) {
mac := []byte{
2, // locally administered unicast
0x65, 0x02, // OUI (randomly chosen by jell)
0, 0, 0, // bytes to randomly overwrite
}
_, err := rand.Read(mac[3:6])
if err != nil {
return nil, errwrap.Wrap(errors.New("cannot generate random mac address"), err)
}
return mac, nil
}
|
go
|
func generateMacAddress() (net.HardwareAddr, error) {
mac := []byte{
2, // locally administered unicast
0x65, 0x02, // OUI (randomly chosen by jell)
0, 0, 0, // bytes to randomly overwrite
}
_, err := rand.Read(mac[3:6])
if err != nil {
return nil, errwrap.Wrap(errors.New("cannot generate random mac address"), err)
}
return mac, nil
}
|
[
"func",
"generateMacAddress",
"(",
")",
"(",
"net",
".",
"HardwareAddr",
",",
"error",
")",
"{",
"mac",
":=",
"[",
"]",
"byte",
"{",
"2",
",",
"// locally administered unicast",
"0x65",
",",
"0x02",
",",
"// OUI (randomly chosen by jell)",
"0",
",",
"0",
",",
"0",
",",
"// bytes to randomly overwrite",
"}",
"\n\n",
"_",
",",
"err",
":=",
"rand",
".",
"Read",
"(",
"mac",
"[",
"3",
":",
"6",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"mac",
",",
"nil",
"\n",
"}"
] |
// generateMacAddress returns net.HardwareAddr filled with fixed 3 byte prefix
// complemented by 3 random bytes.
|
[
"generateMacAddress",
"returns",
"net",
".",
"HardwareAddr",
"filled",
"with",
"fixed",
"3",
"byte",
"prefix",
"complemented",
"by",
"3",
"random",
"bytes",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/kvm/network.go#L70-L83
|
20,942
|
rkt/rkt
|
tools/depsgen/util.go
|
replacePlaceholders
|
func replacePlaceholders(str string, kv ...string) string {
for ph, value := range toMap(kv...) {
str = strings.Replace(str, "!!!"+ph+"!!!", value, -1)
}
return str
}
|
go
|
func replacePlaceholders(str string, kv ...string) string {
for ph, value := range toMap(kv...) {
str = strings.Replace(str, "!!!"+ph+"!!!", value, -1)
}
return str
}
|
[
"func",
"replacePlaceholders",
"(",
"str",
"string",
",",
"kv",
"...",
"string",
")",
"string",
"{",
"for",
"ph",
",",
"value",
":=",
"range",
"toMap",
"(",
"kv",
"...",
")",
"{",
"str",
"=",
"strings",
".",
"Replace",
"(",
"str",
",",
"\"",
"\"",
"+",
"ph",
"+",
"\"",
"\"",
",",
"value",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"return",
"str",
"\n",
"}"
] |
// replacePlaceholders replaces placeholders with values in kv in
// initial str. Placeholders are in form of !!!FOO!!!, but those
// passed here should be without exclamation marks.
|
[
"replacePlaceholders",
"replaces",
"placeholders",
"with",
"values",
"in",
"kv",
"in",
"initial",
"str",
".",
"Placeholders",
"are",
"in",
"form",
"of",
"!!!FOO!!!",
"but",
"those",
"passed",
"here",
"should",
"be",
"without",
"exclamation",
"marks",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/depsgen/util.go#L54-L59
|
20,943
|
rkt/rkt
|
tools/depsgen/util.go
|
standardFlags
|
func standardFlags(cmd string) (*flag.FlagSet, *string) {
f := flag.NewFlagSet(appName()+" "+cmd, flag.ExitOnError)
target := f.String("target", "", "Make target (example: $(FOO_BINARY))")
return f, target
}
|
go
|
func standardFlags(cmd string) (*flag.FlagSet, *string) {
f := flag.NewFlagSet(appName()+" "+cmd, flag.ExitOnError)
target := f.String("target", "", "Make target (example: $(FOO_BINARY))")
return f, target
}
|
[
"func",
"standardFlags",
"(",
"cmd",
"string",
")",
"(",
"*",
"flag",
".",
"FlagSet",
",",
"*",
"string",
")",
"{",
"f",
":=",
"flag",
".",
"NewFlagSet",
"(",
"appName",
"(",
")",
"+",
"\"",
"\"",
"+",
"cmd",
",",
"flag",
".",
"ExitOnError",
")",
"\n",
"target",
":=",
"f",
".",
"String",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"return",
"f",
",",
"target",
"\n",
"}"
] |
// standardFlags returns a new flag set with target flag already set up
|
[
"standardFlags",
"returns",
"a",
"new",
"flag",
"set",
"with",
"target",
"flag",
"already",
"set",
"up"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/depsgen/util.go#L62-L66
|
20,944
|
rkt/rkt
|
networking/net_plugin.go
|
netPluginAdd
|
func (e *podEnv) netPluginAdd(n *activeNet, netns string) error {
output, err := e.execNetPlugin("ADD", n, netns)
if err != nil {
return pluginErr(err, output)
}
pr := cnitypes.Result{}
if err = json.Unmarshal(output, &pr); err != nil {
err = errwrap.Wrap(fmt.Errorf("parsing %q", string(output)), err)
return errwrap.Wrap(fmt.Errorf("error parsing %q result", n.conf.Name), err)
}
if pr.IP4 == nil {
return nil // TODO(casey) should this be an error?
}
// All is well - mutate the runtime
n.runtime.MergeCNIResult(pr)
return nil
}
|
go
|
func (e *podEnv) netPluginAdd(n *activeNet, netns string) error {
output, err := e.execNetPlugin("ADD", n, netns)
if err != nil {
return pluginErr(err, output)
}
pr := cnitypes.Result{}
if err = json.Unmarshal(output, &pr); err != nil {
err = errwrap.Wrap(fmt.Errorf("parsing %q", string(output)), err)
return errwrap.Wrap(fmt.Errorf("error parsing %q result", n.conf.Name), err)
}
if pr.IP4 == nil {
return nil // TODO(casey) should this be an error?
}
// All is well - mutate the runtime
n.runtime.MergeCNIResult(pr)
return nil
}
|
[
"func",
"(",
"e",
"*",
"podEnv",
")",
"netPluginAdd",
"(",
"n",
"*",
"activeNet",
",",
"netns",
"string",
")",
"error",
"{",
"output",
",",
"err",
":=",
"e",
".",
"execNetPlugin",
"(",
"\"",
"\"",
",",
"n",
",",
"netns",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"pluginErr",
"(",
"err",
",",
"output",
")",
"\n",
"}",
"\n\n",
"pr",
":=",
"cnitypes",
".",
"Result",
"{",
"}",
"\n",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"output",
",",
"&",
"pr",
")",
";",
"err",
"!=",
"nil",
"{",
"err",
"=",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"string",
"(",
"output",
")",
")",
",",
"err",
")",
"\n",
"return",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"n",
".",
"conf",
".",
"Name",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"pr",
".",
"IP4",
"==",
"nil",
"{",
"return",
"nil",
"// TODO(casey) should this be an error?",
"\n",
"}",
"\n\n",
"// All is well - mutate the runtime",
"n",
".",
"runtime",
".",
"MergeCNIResult",
"(",
"pr",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Executes a given network plugin. If successful, mutates n.runtime with
// the runtime information
|
[
"Executes",
"a",
"given",
"network",
"plugin",
".",
"If",
"successful",
"mutates",
"n",
".",
"runtime",
"with",
"the",
"runtime",
"information"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/networking/net_plugin.go#L54-L73
|
20,945
|
rkt/rkt
|
rkt/api_service.go
|
copyPod
|
func copyPod(pod *v1alpha.Pod) *v1alpha.Pod {
p := &v1alpha.Pod{
Id: pod.Id,
Manifest: pod.Manifest,
Annotations: pod.Annotations,
}
for _, app := range pod.Apps {
p.Apps = append(p.Apps, &v1alpha.App{
Name: app.Name,
Image: app.Image,
Annotations: app.Annotations,
})
}
return p
}
|
go
|
func copyPod(pod *v1alpha.Pod) *v1alpha.Pod {
p := &v1alpha.Pod{
Id: pod.Id,
Manifest: pod.Manifest,
Annotations: pod.Annotations,
}
for _, app := range pod.Apps {
p.Apps = append(p.Apps, &v1alpha.App{
Name: app.Name,
Image: app.Image,
Annotations: app.Annotations,
})
}
return p
}
|
[
"func",
"copyPod",
"(",
"pod",
"*",
"v1alpha",
".",
"Pod",
")",
"*",
"v1alpha",
".",
"Pod",
"{",
"p",
":=",
"&",
"v1alpha",
".",
"Pod",
"{",
"Id",
":",
"pod",
".",
"Id",
",",
"Manifest",
":",
"pod",
".",
"Manifest",
",",
"Annotations",
":",
"pod",
".",
"Annotations",
",",
"}",
"\n\n",
"for",
"_",
",",
"app",
":=",
"range",
"pod",
".",
"Apps",
"{",
"p",
".",
"Apps",
"=",
"append",
"(",
"p",
".",
"Apps",
",",
"&",
"v1alpha",
".",
"App",
"{",
"Name",
":",
"app",
".",
"Name",
",",
"Image",
":",
"app",
".",
"Image",
",",
"Annotations",
":",
"app",
".",
"Annotations",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"p",
"\n",
"}"
] |
// copyPod copies the immutable information of the pod into the new pod.
|
[
"copyPod",
"copies",
"the",
"immutable",
"information",
"of",
"the",
"pod",
"into",
"the",
"new",
"pod",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L89-L104
|
20,946
|
rkt/rkt
|
rkt/api_service.go
|
copyImage
|
func copyImage(img *v1alpha.Image) *v1alpha.Image {
return &v1alpha.Image{
BaseFormat: img.BaseFormat,
Id: img.Id,
Name: img.Name,
Version: img.Version,
ImportTimestamp: img.ImportTimestamp,
Manifest: img.Manifest,
Size: img.Size,
Annotations: img.Annotations,
Labels: img.Labels,
}
}
|
go
|
func copyImage(img *v1alpha.Image) *v1alpha.Image {
return &v1alpha.Image{
BaseFormat: img.BaseFormat,
Id: img.Id,
Name: img.Name,
Version: img.Version,
ImportTimestamp: img.ImportTimestamp,
Manifest: img.Manifest,
Size: img.Size,
Annotations: img.Annotations,
Labels: img.Labels,
}
}
|
[
"func",
"copyImage",
"(",
"img",
"*",
"v1alpha",
".",
"Image",
")",
"*",
"v1alpha",
".",
"Image",
"{",
"return",
"&",
"v1alpha",
".",
"Image",
"{",
"BaseFormat",
":",
"img",
".",
"BaseFormat",
",",
"Id",
":",
"img",
".",
"Id",
",",
"Name",
":",
"img",
".",
"Name",
",",
"Version",
":",
"img",
".",
"Version",
",",
"ImportTimestamp",
":",
"img",
".",
"ImportTimestamp",
",",
"Manifest",
":",
"img",
".",
"Manifest",
",",
"Size",
":",
"img",
".",
"Size",
",",
"Annotations",
":",
"img",
".",
"Annotations",
",",
"Labels",
":",
"img",
".",
"Labels",
",",
"}",
"\n",
"}"
] |
// copyImage copies the image object to avoid modification on the original one.
|
[
"copyImage",
"copies",
"the",
"image",
"object",
"to",
"avoid",
"modification",
"on",
"the",
"original",
"one",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L107-L119
|
20,947
|
rkt/rkt
|
rkt/api_service.go
|
GetInfo
|
func (s *v1AlphaAPIServer) GetInfo(context.Context, *v1alpha.GetInfoRequest) (*v1alpha.GetInfoResponse, error) {
return &v1alpha.GetInfoResponse{
Info: &v1alpha.Info{
RktVersion: version.Version,
AppcVersion: schema.AppContainerVersion.String(),
ApiVersion: supportedAPIVersion,
GlobalFlags: &v1alpha.GlobalFlags{
Dir: getDataDir(),
SystemConfigDir: globalFlags.SystemConfigDir,
LocalConfigDir: globalFlags.LocalConfigDir,
UserConfigDir: globalFlags.UserConfigDir,
InsecureFlags: globalFlags.InsecureFlags.String(),
TrustKeysFromHttps: globalFlags.TrustKeysFromHTTPS,
},
},
}, nil
}
|
go
|
func (s *v1AlphaAPIServer) GetInfo(context.Context, *v1alpha.GetInfoRequest) (*v1alpha.GetInfoResponse, error) {
return &v1alpha.GetInfoResponse{
Info: &v1alpha.Info{
RktVersion: version.Version,
AppcVersion: schema.AppContainerVersion.String(),
ApiVersion: supportedAPIVersion,
GlobalFlags: &v1alpha.GlobalFlags{
Dir: getDataDir(),
SystemConfigDir: globalFlags.SystemConfigDir,
LocalConfigDir: globalFlags.LocalConfigDir,
UserConfigDir: globalFlags.UserConfigDir,
InsecureFlags: globalFlags.InsecureFlags.String(),
TrustKeysFromHttps: globalFlags.TrustKeysFromHTTPS,
},
},
}, nil
}
|
[
"func",
"(",
"s",
"*",
"v1AlphaAPIServer",
")",
"GetInfo",
"(",
"context",
".",
"Context",
",",
"*",
"v1alpha",
".",
"GetInfoRequest",
")",
"(",
"*",
"v1alpha",
".",
"GetInfoResponse",
",",
"error",
")",
"{",
"return",
"&",
"v1alpha",
".",
"GetInfoResponse",
"{",
"Info",
":",
"&",
"v1alpha",
".",
"Info",
"{",
"RktVersion",
":",
"version",
".",
"Version",
",",
"AppcVersion",
":",
"schema",
".",
"AppContainerVersion",
".",
"String",
"(",
")",
",",
"ApiVersion",
":",
"supportedAPIVersion",
",",
"GlobalFlags",
":",
"&",
"v1alpha",
".",
"GlobalFlags",
"{",
"Dir",
":",
"getDataDir",
"(",
")",
",",
"SystemConfigDir",
":",
"globalFlags",
".",
"SystemConfigDir",
",",
"LocalConfigDir",
":",
"globalFlags",
".",
"LocalConfigDir",
",",
"UserConfigDir",
":",
"globalFlags",
".",
"UserConfigDir",
",",
"InsecureFlags",
":",
"globalFlags",
".",
"InsecureFlags",
".",
"String",
"(",
")",
",",
"TrustKeysFromHttps",
":",
"globalFlags",
".",
"TrustKeysFromHTTPS",
",",
"}",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// GetInfo returns the information about the rkt, appc, api server version.
|
[
"GetInfo",
"returns",
"the",
"information",
"about",
"the",
"rkt",
"appc",
"api",
"server",
"version",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L154-L170
|
20,948
|
rkt/rkt
|
rkt/api_service.go
|
containsAllKeyValues
|
func containsAllKeyValues(actualKVs []*v1alpha.KeyValue, requiredKVs []*v1alpha.KeyValue) bool {
for _, requiredKV := range requiredKVs {
actualValue, ok := findInKeyValues(actualKVs, requiredKV.Key)
if !ok || actualValue != requiredKV.Value {
return false
}
}
return true
}
|
go
|
func containsAllKeyValues(actualKVs []*v1alpha.KeyValue, requiredKVs []*v1alpha.KeyValue) bool {
for _, requiredKV := range requiredKVs {
actualValue, ok := findInKeyValues(actualKVs, requiredKV.Key)
if !ok || actualValue != requiredKV.Value {
return false
}
}
return true
}
|
[
"func",
"containsAllKeyValues",
"(",
"actualKVs",
"[",
"]",
"*",
"v1alpha",
".",
"KeyValue",
",",
"requiredKVs",
"[",
"]",
"*",
"v1alpha",
".",
"KeyValue",
")",
"bool",
"{",
"for",
"_",
",",
"requiredKV",
":=",
"range",
"requiredKVs",
"{",
"actualValue",
",",
"ok",
":=",
"findInKeyValues",
"(",
"actualKVs",
",",
"requiredKV",
".",
"Key",
")",
"\n",
"if",
"!",
"ok",
"||",
"actualValue",
"!=",
"requiredKV",
".",
"Value",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// containsAllKeyValues returns true if the actualKVs contains all of the key-value
// pairs listed in requiredKVs, otherwise it returns false.
|
[
"containsAllKeyValues",
"returns",
"true",
"if",
"the",
"actualKVs",
"contains",
"all",
"of",
"the",
"key",
"-",
"value",
"pairs",
"listed",
"in",
"requiredKVs",
"otherwise",
"it",
"returns",
"false",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L183-L191
|
20,949
|
rkt/rkt
|
rkt/api_service.go
|
satisfiesPodFilter
|
func satisfiesPodFilter(pod v1alpha.Pod, filter v1alpha.PodFilter) bool {
// Filter according to the ID.
if len(filter.Ids) > 0 {
s := set.NewString(filter.Ids...)
if !s.Has(pod.Id) {
return false
}
}
// Filter according to the state.
if len(filter.States) > 0 {
foundState := false
for _, state := range filter.States {
if pod.State == state {
foundState = true
break
}
}
if !foundState {
return false
}
}
// Filter according to the app names.
if len(filter.AppNames) > 0 {
s := set.NewString()
for _, app := range pod.Apps {
s.Insert(app.Name)
}
if !s.HasAll(filter.AppNames...) {
return false
}
}
// Filter according to the image IDs.
if len(filter.ImageIds) > 0 {
s := set.NewString()
for _, app := range pod.Apps {
s.Insert(app.Image.Id)
}
if !s.HasAll(filter.ImageIds...) {
return false
}
}
// Filter according to the network names.
if len(filter.NetworkNames) > 0 {
s := set.NewString()
for _, network := range pod.Networks {
s.Insert(network.Name)
}
if !s.HasAll(filter.NetworkNames...) {
return false
}
}
// Filter according to the annotations.
if len(filter.Annotations) > 0 {
if !containsAllKeyValues(pod.Annotations, filter.Annotations) {
return false
}
}
// Filter according to the cgroup.
if len(filter.Cgroups) > 0 {
s := set.NewString(filter.Cgroups...)
if !s.Has(pod.Cgroup) {
return false
}
}
// Filter if pod's cgroup is a prefix of the passed in cgroup
if len(filter.PodSubCgroups) > 0 {
matched := false
if pod.Cgroup != "" {
for _, cgroup := range filter.PodSubCgroups {
if strings.HasPrefix(cgroup, pod.Cgroup) {
matched = true
break
}
}
}
if !matched {
return false
}
}
return true
}
|
go
|
func satisfiesPodFilter(pod v1alpha.Pod, filter v1alpha.PodFilter) bool {
// Filter according to the ID.
if len(filter.Ids) > 0 {
s := set.NewString(filter.Ids...)
if !s.Has(pod.Id) {
return false
}
}
// Filter according to the state.
if len(filter.States) > 0 {
foundState := false
for _, state := range filter.States {
if pod.State == state {
foundState = true
break
}
}
if !foundState {
return false
}
}
// Filter according to the app names.
if len(filter.AppNames) > 0 {
s := set.NewString()
for _, app := range pod.Apps {
s.Insert(app.Name)
}
if !s.HasAll(filter.AppNames...) {
return false
}
}
// Filter according to the image IDs.
if len(filter.ImageIds) > 0 {
s := set.NewString()
for _, app := range pod.Apps {
s.Insert(app.Image.Id)
}
if !s.HasAll(filter.ImageIds...) {
return false
}
}
// Filter according to the network names.
if len(filter.NetworkNames) > 0 {
s := set.NewString()
for _, network := range pod.Networks {
s.Insert(network.Name)
}
if !s.HasAll(filter.NetworkNames...) {
return false
}
}
// Filter according to the annotations.
if len(filter.Annotations) > 0 {
if !containsAllKeyValues(pod.Annotations, filter.Annotations) {
return false
}
}
// Filter according to the cgroup.
if len(filter.Cgroups) > 0 {
s := set.NewString(filter.Cgroups...)
if !s.Has(pod.Cgroup) {
return false
}
}
// Filter if pod's cgroup is a prefix of the passed in cgroup
if len(filter.PodSubCgroups) > 0 {
matched := false
if pod.Cgroup != "" {
for _, cgroup := range filter.PodSubCgroups {
if strings.HasPrefix(cgroup, pod.Cgroup) {
matched = true
break
}
}
}
if !matched {
return false
}
}
return true
}
|
[
"func",
"satisfiesPodFilter",
"(",
"pod",
"v1alpha",
".",
"Pod",
",",
"filter",
"v1alpha",
".",
"PodFilter",
")",
"bool",
"{",
"// Filter according to the ID.",
"if",
"len",
"(",
"filter",
".",
"Ids",
")",
">",
"0",
"{",
"s",
":=",
"set",
".",
"NewString",
"(",
"filter",
".",
"Ids",
"...",
")",
"\n",
"if",
"!",
"s",
".",
"Has",
"(",
"pod",
".",
"Id",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter according to the state.",
"if",
"len",
"(",
"filter",
".",
"States",
")",
">",
"0",
"{",
"foundState",
":=",
"false",
"\n",
"for",
"_",
",",
"state",
":=",
"range",
"filter",
".",
"States",
"{",
"if",
"pod",
".",
"State",
"==",
"state",
"{",
"foundState",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"foundState",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter according to the app names.",
"if",
"len",
"(",
"filter",
".",
"AppNames",
")",
">",
"0",
"{",
"s",
":=",
"set",
".",
"NewString",
"(",
")",
"\n",
"for",
"_",
",",
"app",
":=",
"range",
"pod",
".",
"Apps",
"{",
"s",
".",
"Insert",
"(",
"app",
".",
"Name",
")",
"\n",
"}",
"\n",
"if",
"!",
"s",
".",
"HasAll",
"(",
"filter",
".",
"AppNames",
"...",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter according to the image IDs.",
"if",
"len",
"(",
"filter",
".",
"ImageIds",
")",
">",
"0",
"{",
"s",
":=",
"set",
".",
"NewString",
"(",
")",
"\n",
"for",
"_",
",",
"app",
":=",
"range",
"pod",
".",
"Apps",
"{",
"s",
".",
"Insert",
"(",
"app",
".",
"Image",
".",
"Id",
")",
"\n",
"}",
"\n",
"if",
"!",
"s",
".",
"HasAll",
"(",
"filter",
".",
"ImageIds",
"...",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter according to the network names.",
"if",
"len",
"(",
"filter",
".",
"NetworkNames",
")",
">",
"0",
"{",
"s",
":=",
"set",
".",
"NewString",
"(",
")",
"\n",
"for",
"_",
",",
"network",
":=",
"range",
"pod",
".",
"Networks",
"{",
"s",
".",
"Insert",
"(",
"network",
".",
"Name",
")",
"\n",
"}",
"\n",
"if",
"!",
"s",
".",
"HasAll",
"(",
"filter",
".",
"NetworkNames",
"...",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter according to the annotations.",
"if",
"len",
"(",
"filter",
".",
"Annotations",
")",
">",
"0",
"{",
"if",
"!",
"containsAllKeyValues",
"(",
"pod",
".",
"Annotations",
",",
"filter",
".",
"Annotations",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter according to the cgroup.",
"if",
"len",
"(",
"filter",
".",
"Cgroups",
")",
">",
"0",
"{",
"s",
":=",
"set",
".",
"NewString",
"(",
"filter",
".",
"Cgroups",
"...",
")",
"\n",
"if",
"!",
"s",
".",
"Has",
"(",
"pod",
".",
"Cgroup",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter if pod's cgroup is a prefix of the passed in cgroup",
"if",
"len",
"(",
"filter",
".",
"PodSubCgroups",
")",
">",
"0",
"{",
"matched",
":=",
"false",
"\n",
"if",
"pod",
".",
"Cgroup",
"!=",
"\"",
"\"",
"{",
"for",
"_",
",",
"cgroup",
":=",
"range",
"filter",
".",
"PodSubCgroups",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"cgroup",
",",
"pod",
".",
"Cgroup",
")",
"{",
"matched",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"matched",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] |
// satisfiesPodFilter returns true if the pod satisfies the filter.
// The pod, filter must not be nil.
|
[
"satisfiesPodFilter",
"returns",
"true",
"if",
"the",
"pod",
"satisfies",
"the",
"filter",
".",
"The",
"pod",
"filter",
"must",
"not",
"be",
"nil",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L210-L299
|
20,950
|
rkt/rkt
|
rkt/api_service.go
|
satisfiesAnyPodFilters
|
func satisfiesAnyPodFilters(pod *v1alpha.Pod, filters []*v1alpha.PodFilter) bool {
// No filters, return true directly.
if len(filters) == 0 {
return true
}
for _, filter := range filters {
if satisfiesPodFilter(*pod, *filter) {
return true
}
}
return false
}
|
go
|
func satisfiesAnyPodFilters(pod *v1alpha.Pod, filters []*v1alpha.PodFilter) bool {
// No filters, return true directly.
if len(filters) == 0 {
return true
}
for _, filter := range filters {
if satisfiesPodFilter(*pod, *filter) {
return true
}
}
return false
}
|
[
"func",
"satisfiesAnyPodFilters",
"(",
"pod",
"*",
"v1alpha",
".",
"Pod",
",",
"filters",
"[",
"]",
"*",
"v1alpha",
".",
"PodFilter",
")",
"bool",
"{",
"// No filters, return true directly.",
"if",
"len",
"(",
"filters",
")",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"filter",
":=",
"range",
"filters",
"{",
"if",
"satisfiesPodFilter",
"(",
"*",
"pod",
",",
"*",
"filter",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// satisfiesAnyPodFilters returns true if any of the filter conditions is satisfied
// by the pod, or there's no filters.
|
[
"satisfiesAnyPodFilters",
"returns",
"true",
"if",
"any",
"of",
"the",
"filter",
"conditions",
"is",
"satisfied",
"by",
"the",
"pod",
"or",
"there",
"s",
"no",
"filters",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L303-L315
|
20,951
|
rkt/rkt
|
rkt/api_service.go
|
getApplist
|
func getApplist(manifest *schema.PodManifest) []*v1alpha.App {
var apps []*v1alpha.App
for _, app := range manifest.Apps {
img := &v1alpha.Image{
BaseFormat: &v1alpha.ImageFormat{
// Only support appc image now. If it's a docker image, then it
// will be transformed to appc before storing in the disk store.
Type: v1alpha.ImageType_IMAGE_TYPE_APPC,
Version: schema.AppContainerVersion.String(),
},
Id: app.Image.ID.String(),
// Only image format and image ID are returned in 'ListPods()'.
}
apps = append(apps, &v1alpha.App{
Name: app.Name.String(),
Image: img,
Annotations: convertAnnotationsToKeyValue(app.Annotations),
State: v1alpha.AppState_APP_STATE_UNDEFINED,
ExitCode: -1,
})
}
return apps
}
|
go
|
func getApplist(manifest *schema.PodManifest) []*v1alpha.App {
var apps []*v1alpha.App
for _, app := range manifest.Apps {
img := &v1alpha.Image{
BaseFormat: &v1alpha.ImageFormat{
// Only support appc image now. If it's a docker image, then it
// will be transformed to appc before storing in the disk store.
Type: v1alpha.ImageType_IMAGE_TYPE_APPC,
Version: schema.AppContainerVersion.String(),
},
Id: app.Image.ID.String(),
// Only image format and image ID are returned in 'ListPods()'.
}
apps = append(apps, &v1alpha.App{
Name: app.Name.String(),
Image: img,
Annotations: convertAnnotationsToKeyValue(app.Annotations),
State: v1alpha.AppState_APP_STATE_UNDEFINED,
ExitCode: -1,
})
}
return apps
}
|
[
"func",
"getApplist",
"(",
"manifest",
"*",
"schema",
".",
"PodManifest",
")",
"[",
"]",
"*",
"v1alpha",
".",
"App",
"{",
"var",
"apps",
"[",
"]",
"*",
"v1alpha",
".",
"App",
"\n",
"for",
"_",
",",
"app",
":=",
"range",
"manifest",
".",
"Apps",
"{",
"img",
":=",
"&",
"v1alpha",
".",
"Image",
"{",
"BaseFormat",
":",
"&",
"v1alpha",
".",
"ImageFormat",
"{",
"// Only support appc image now. If it's a docker image, then it",
"// will be transformed to appc before storing in the disk store.",
"Type",
":",
"v1alpha",
".",
"ImageType_IMAGE_TYPE_APPC",
",",
"Version",
":",
"schema",
".",
"AppContainerVersion",
".",
"String",
"(",
")",
",",
"}",
",",
"Id",
":",
"app",
".",
"Image",
".",
"ID",
".",
"String",
"(",
")",
",",
"// Only image format and image ID are returned in 'ListPods()'.",
"}",
"\n\n",
"apps",
"=",
"append",
"(",
"apps",
",",
"&",
"v1alpha",
".",
"App",
"{",
"Name",
":",
"app",
".",
"Name",
".",
"String",
"(",
")",
",",
"Image",
":",
"img",
",",
"Annotations",
":",
"convertAnnotationsToKeyValue",
"(",
"app",
".",
"Annotations",
")",
",",
"State",
":",
"v1alpha",
".",
"AppState_APP_STATE_UNDEFINED",
",",
"ExitCode",
":",
"-",
"1",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"apps",
"\n",
"}"
] |
// getApplist returns a list of apps in the pod.
|
[
"getApplist",
"returns",
"a",
"list",
"of",
"apps",
"in",
"the",
"pod",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L370-L393
|
20,952
|
rkt/rkt
|
rkt/api_service.go
|
getNetworks
|
func getNetworks(p *pkgPod.Pod) []*v1alpha.Network {
var networks []*v1alpha.Network
for _, n := range p.Nets {
networks = append(networks, &v1alpha.Network{
Name: n.NetName,
// There will be IPv6 support soon so distinguish between v4 and v6
Ipv4: n.IP.String(),
})
}
return networks
}
|
go
|
func getNetworks(p *pkgPod.Pod) []*v1alpha.Network {
var networks []*v1alpha.Network
for _, n := range p.Nets {
networks = append(networks, &v1alpha.Network{
Name: n.NetName,
// There will be IPv6 support soon so distinguish between v4 and v6
Ipv4: n.IP.String(),
})
}
return networks
}
|
[
"func",
"getNetworks",
"(",
"p",
"*",
"pkgPod",
".",
"Pod",
")",
"[",
"]",
"*",
"v1alpha",
".",
"Network",
"{",
"var",
"networks",
"[",
"]",
"*",
"v1alpha",
".",
"Network",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"p",
".",
"Nets",
"{",
"networks",
"=",
"append",
"(",
"networks",
",",
"&",
"v1alpha",
".",
"Network",
"{",
"Name",
":",
"n",
".",
"NetName",
",",
"// There will be IPv6 support soon so distinguish between v4 and v6",
"Ipv4",
":",
"n",
".",
"IP",
".",
"String",
"(",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"networks",
"\n",
"}"
] |
// getNetworks returns the list of the info of the network that the pod belongs to.
|
[
"getNetworks",
"returns",
"the",
"list",
"of",
"the",
"info",
"of",
"the",
"network",
"that",
"the",
"pod",
"belongs",
"to",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L396-L406
|
20,953
|
rkt/rkt
|
rkt/api_service.go
|
fillStaticAppInfo
|
func fillStaticAppInfo(store *imagestore.Store, pod *pkgPod.Pod, v1pod *v1alpha.Pod) error {
var errlist []error
// Fill static app image info.
for _, app := range v1pod.Apps {
// Fill app's image info.
app.Image = &v1alpha.Image{
BaseFormat: &v1alpha.ImageFormat{
// Only support appc image now. If it's a docker image, then it
// will be transformed to appc before storing in the disk store.
Type: v1alpha.ImageType_IMAGE_TYPE_APPC,
Version: schema.AppContainerVersion.String(),
},
Id: app.Image.Id,
// Other information are not available because they require the image
// info from store. Some of it is filled in below if possible.
}
im, err := pod.AppImageManifest(app.Name)
if err != nil {
stderr.PrintE(fmt.Sprintf("failed to get image manifests for app %q", app.Name), err)
errlist = append(errlist, err)
} else {
app.Image.Name = im.Name.String()
version, ok := im.Labels.Get("version")
if !ok {
version = "latest"
}
app.Image.Version = version
}
}
if len(errlist) != 0 {
return errs{errlist}
}
return nil
}
|
go
|
func fillStaticAppInfo(store *imagestore.Store, pod *pkgPod.Pod, v1pod *v1alpha.Pod) error {
var errlist []error
// Fill static app image info.
for _, app := range v1pod.Apps {
// Fill app's image info.
app.Image = &v1alpha.Image{
BaseFormat: &v1alpha.ImageFormat{
// Only support appc image now. If it's a docker image, then it
// will be transformed to appc before storing in the disk store.
Type: v1alpha.ImageType_IMAGE_TYPE_APPC,
Version: schema.AppContainerVersion.String(),
},
Id: app.Image.Id,
// Other information are not available because they require the image
// info from store. Some of it is filled in below if possible.
}
im, err := pod.AppImageManifest(app.Name)
if err != nil {
stderr.PrintE(fmt.Sprintf("failed to get image manifests for app %q", app.Name), err)
errlist = append(errlist, err)
} else {
app.Image.Name = im.Name.String()
version, ok := im.Labels.Get("version")
if !ok {
version = "latest"
}
app.Image.Version = version
}
}
if len(errlist) != 0 {
return errs{errlist}
}
return nil
}
|
[
"func",
"fillStaticAppInfo",
"(",
"store",
"*",
"imagestore",
".",
"Store",
",",
"pod",
"*",
"pkgPod",
".",
"Pod",
",",
"v1pod",
"*",
"v1alpha",
".",
"Pod",
")",
"error",
"{",
"var",
"errlist",
"[",
"]",
"error",
"\n\n",
"// Fill static app image info.",
"for",
"_",
",",
"app",
":=",
"range",
"v1pod",
".",
"Apps",
"{",
"// Fill app's image info.",
"app",
".",
"Image",
"=",
"&",
"v1alpha",
".",
"Image",
"{",
"BaseFormat",
":",
"&",
"v1alpha",
".",
"ImageFormat",
"{",
"// Only support appc image now. If it's a docker image, then it",
"// will be transformed to appc before storing in the disk store.",
"Type",
":",
"v1alpha",
".",
"ImageType_IMAGE_TYPE_APPC",
",",
"Version",
":",
"schema",
".",
"AppContainerVersion",
".",
"String",
"(",
")",
",",
"}",
",",
"Id",
":",
"app",
".",
"Image",
".",
"Id",
",",
"// Other information are not available because they require the image",
"// info from store. Some of it is filled in below if possible.",
"}",
"\n\n",
"im",
",",
"err",
":=",
"pod",
".",
"AppImageManifest",
"(",
"app",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"stderr",
".",
"PrintE",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"app",
".",
"Name",
")",
",",
"err",
")",
"\n",
"errlist",
"=",
"append",
"(",
"errlist",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"app",
".",
"Image",
".",
"Name",
"=",
"im",
".",
"Name",
".",
"String",
"(",
")",
"\n\n",
"version",
",",
"ok",
":=",
"im",
".",
"Labels",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"!",
"ok",
"{",
"version",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"app",
".",
"Image",
".",
"Version",
"=",
"version",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"errlist",
")",
"!=",
"0",
"{",
"return",
"errs",
"{",
"errlist",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// fillStaticAppInfo will modify the 'v1pod' in place with the information retrieved with 'pod'.
// Today, these information are static and will not change during the pod's lifecycle.
|
[
"fillStaticAppInfo",
"will",
"modify",
"the",
"v1pod",
"in",
"place",
"with",
"the",
"information",
"retrieved",
"with",
"pod",
".",
"Today",
"these",
"information",
"are",
"static",
"and",
"will",
"not",
"change",
"during",
"the",
"pod",
"s",
"lifecycle",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L419-L456
|
20,954
|
rkt/rkt
|
rkt/api_service.go
|
getBasicPod
|
func (s *v1AlphaAPIServer) getBasicPod(p *pkgPod.Pod) *v1alpha.Pod {
mtime, mtimeErr := getPodManifestModTime(p)
if mtimeErr != nil {
stderr.PrintE(fmt.Sprintf("failed to read the pod manifest's mtime for pod %q", p.UUID), mtimeErr)
}
// Couldn't use pod.uuid directly as it's a pointer.
itemValue, found := s.podCache.Get(p.UUID.String())
if found && mtimeErr == nil {
cacheItem := itemValue.(*podCacheItem)
// Check the mtime to make sure we are not returning stale manifests.
if !mtime.After(cacheItem.mtime) {
return copyPod(cacheItem.pod)
}
}
pod, err := s.getBasicPodFromDisk(p)
if mtimeErr != nil || err != nil {
// If any error happens or the mtime is unknown,
// returns the raw pod directly without adding it to the cache.
return pod
}
cacheItem := &podCacheItem{pod, mtime}
s.podCache.Add(p.UUID.String(), cacheItem)
// Return a copy of the pod, so the cached pod is not mutated later.
return copyPod(cacheItem.pod)
}
|
go
|
func (s *v1AlphaAPIServer) getBasicPod(p *pkgPod.Pod) *v1alpha.Pod {
mtime, mtimeErr := getPodManifestModTime(p)
if mtimeErr != nil {
stderr.PrintE(fmt.Sprintf("failed to read the pod manifest's mtime for pod %q", p.UUID), mtimeErr)
}
// Couldn't use pod.uuid directly as it's a pointer.
itemValue, found := s.podCache.Get(p.UUID.String())
if found && mtimeErr == nil {
cacheItem := itemValue.(*podCacheItem)
// Check the mtime to make sure we are not returning stale manifests.
if !mtime.After(cacheItem.mtime) {
return copyPod(cacheItem.pod)
}
}
pod, err := s.getBasicPodFromDisk(p)
if mtimeErr != nil || err != nil {
// If any error happens or the mtime is unknown,
// returns the raw pod directly without adding it to the cache.
return pod
}
cacheItem := &podCacheItem{pod, mtime}
s.podCache.Add(p.UUID.String(), cacheItem)
// Return a copy of the pod, so the cached pod is not mutated later.
return copyPod(cacheItem.pod)
}
|
[
"func",
"(",
"s",
"*",
"v1AlphaAPIServer",
")",
"getBasicPod",
"(",
"p",
"*",
"pkgPod",
".",
"Pod",
")",
"*",
"v1alpha",
".",
"Pod",
"{",
"mtime",
",",
"mtimeErr",
":=",
"getPodManifestModTime",
"(",
"p",
")",
"\n",
"if",
"mtimeErr",
"!=",
"nil",
"{",
"stderr",
".",
"PrintE",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"UUID",
")",
",",
"mtimeErr",
")",
"\n",
"}",
"\n\n",
"// Couldn't use pod.uuid directly as it's a pointer.",
"itemValue",
",",
"found",
":=",
"s",
".",
"podCache",
".",
"Get",
"(",
"p",
".",
"UUID",
".",
"String",
"(",
")",
")",
"\n",
"if",
"found",
"&&",
"mtimeErr",
"==",
"nil",
"{",
"cacheItem",
":=",
"itemValue",
".",
"(",
"*",
"podCacheItem",
")",
"\n\n",
"// Check the mtime to make sure we are not returning stale manifests.",
"if",
"!",
"mtime",
".",
"After",
"(",
"cacheItem",
".",
"mtime",
")",
"{",
"return",
"copyPod",
"(",
"cacheItem",
".",
"pod",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"pod",
",",
"err",
":=",
"s",
".",
"getBasicPodFromDisk",
"(",
"p",
")",
"\n",
"if",
"mtimeErr",
"!=",
"nil",
"||",
"err",
"!=",
"nil",
"{",
"// If any error happens or the mtime is unknown,",
"// returns the raw pod directly without adding it to the cache.",
"return",
"pod",
"\n",
"}",
"\n\n",
"cacheItem",
":=",
"&",
"podCacheItem",
"{",
"pod",
",",
"mtime",
"}",
"\n",
"s",
".",
"podCache",
".",
"Add",
"(",
"p",
".",
"UUID",
".",
"String",
"(",
")",
",",
"cacheItem",
")",
"\n\n",
"// Return a copy of the pod, so the cached pod is not mutated later.",
"return",
"copyPod",
"(",
"cacheItem",
".",
"pod",
")",
"\n",
"}"
] |
// getBasicPod returns v1alpha.Pod with basic pod information.
|
[
"getBasicPod",
"returns",
"v1alpha",
".",
"Pod",
"with",
"basic",
"pod",
"information",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L484-L513
|
20,955
|
rkt/rkt
|
rkt/api_service.go
|
aciInfoToV1AlphaAPIImage
|
func aciInfoToV1AlphaAPIImage(store *imagestore.Store, aciInfo *imagestore.ACIInfo) (*v1alpha.Image, error) {
manifest, err := store.GetImageManifestJSON(aciInfo.BlobKey)
if err != nil {
stderr.PrintE("failed to read the image manifest", err)
return nil, err
}
var im schema.ImageManifest
if err = json.Unmarshal(manifest, &im); err != nil {
stderr.PrintE("failed to unmarshal image manifest", err)
return nil, err
}
version, ok := im.Labels.Get("version")
if !ok {
version = "latest"
}
return &v1alpha.Image{
BaseFormat: &v1alpha.ImageFormat{
// Only support appc image now. If it's a docker image, then it
// will be transformed to appc before storing in the disk store.
Type: v1alpha.ImageType_IMAGE_TYPE_APPC,
Version: schema.AppContainerVersion.String(),
},
Id: aciInfo.BlobKey,
Name: im.Name.String(),
Version: version,
ImportTimestamp: aciInfo.ImportTime.Unix(),
Manifest: manifest,
Size: aciInfo.Size + aciInfo.TreeStoreSize,
Annotations: convertAnnotationsToKeyValue(im.Annotations),
Labels: convertLabelsToKeyValue(im.Labels),
}, nil
}
|
go
|
func aciInfoToV1AlphaAPIImage(store *imagestore.Store, aciInfo *imagestore.ACIInfo) (*v1alpha.Image, error) {
manifest, err := store.GetImageManifestJSON(aciInfo.BlobKey)
if err != nil {
stderr.PrintE("failed to read the image manifest", err)
return nil, err
}
var im schema.ImageManifest
if err = json.Unmarshal(manifest, &im); err != nil {
stderr.PrintE("failed to unmarshal image manifest", err)
return nil, err
}
version, ok := im.Labels.Get("version")
if !ok {
version = "latest"
}
return &v1alpha.Image{
BaseFormat: &v1alpha.ImageFormat{
// Only support appc image now. If it's a docker image, then it
// will be transformed to appc before storing in the disk store.
Type: v1alpha.ImageType_IMAGE_TYPE_APPC,
Version: schema.AppContainerVersion.String(),
},
Id: aciInfo.BlobKey,
Name: im.Name.String(),
Version: version,
ImportTimestamp: aciInfo.ImportTime.Unix(),
Manifest: manifest,
Size: aciInfo.Size + aciInfo.TreeStoreSize,
Annotations: convertAnnotationsToKeyValue(im.Annotations),
Labels: convertLabelsToKeyValue(im.Labels),
}, nil
}
|
[
"func",
"aciInfoToV1AlphaAPIImage",
"(",
"store",
"*",
"imagestore",
".",
"Store",
",",
"aciInfo",
"*",
"imagestore",
".",
"ACIInfo",
")",
"(",
"*",
"v1alpha",
".",
"Image",
",",
"error",
")",
"{",
"manifest",
",",
"err",
":=",
"store",
".",
"GetImageManifestJSON",
"(",
"aciInfo",
".",
"BlobKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"stderr",
".",
"PrintE",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"im",
"schema",
".",
"ImageManifest",
"\n",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"manifest",
",",
"&",
"im",
")",
";",
"err",
"!=",
"nil",
"{",
"stderr",
".",
"PrintE",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"version",
",",
"ok",
":=",
"im",
".",
"Labels",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"!",
"ok",
"{",
"version",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"&",
"v1alpha",
".",
"Image",
"{",
"BaseFormat",
":",
"&",
"v1alpha",
".",
"ImageFormat",
"{",
"// Only support appc image now. If it's a docker image, then it",
"// will be transformed to appc before storing in the disk store.",
"Type",
":",
"v1alpha",
".",
"ImageType_IMAGE_TYPE_APPC",
",",
"Version",
":",
"schema",
".",
"AppContainerVersion",
".",
"String",
"(",
")",
",",
"}",
",",
"Id",
":",
"aciInfo",
".",
"BlobKey",
",",
"Name",
":",
"im",
".",
"Name",
".",
"String",
"(",
")",
",",
"Version",
":",
"version",
",",
"ImportTimestamp",
":",
"aciInfo",
".",
"ImportTime",
".",
"Unix",
"(",
")",
",",
"Manifest",
":",
"manifest",
",",
"Size",
":",
"aciInfo",
".",
"Size",
"+",
"aciInfo",
".",
"TreeStoreSize",
",",
"Annotations",
":",
"convertAnnotationsToKeyValue",
"(",
"im",
".",
"Annotations",
")",
",",
"Labels",
":",
"convertLabelsToKeyValue",
"(",
"im",
".",
"Labels",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// aciInfoToV1AlphaAPIImage takes an aciInfo object and construct the v1alpha.Image object.
|
[
"aciInfoToV1AlphaAPIImage",
"takes",
"an",
"aciInfo",
"object",
"and",
"construct",
"the",
"v1alpha",
".",
"Image",
"object",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L654-L688
|
20,956
|
rkt/rkt
|
rkt/api_service.go
|
satisfiesImageFilter
|
func satisfiesImageFilter(image v1alpha.Image, filter v1alpha.ImageFilter) bool {
// Filter according to the IDs.
if len(filter.Ids) > 0 {
s := set.NewString(filter.Ids...)
if !s.Has(image.Id) {
return false
}
}
// Filter according to the image full names.
if len(filter.FullNames) > 0 {
s := set.NewString(filter.FullNames...)
if !s.Has(image.Name) {
return false
}
}
// Filter according to the image name prefixes.
if len(filter.Prefixes) > 0 {
s := set.NewString(filter.Prefixes...)
if !s.ConditionalHas(isPrefixOf, image.Name) {
return false
}
}
// Filter according to the image base name.
if len(filter.BaseNames) > 0 {
s := set.NewString(filter.BaseNames...)
if !s.ConditionalHas(isBaseNameOf, image.Name) {
return false
}
}
// Filter according to the image keywords.
if len(filter.Keywords) > 0 {
s := set.NewString(filter.Keywords...)
if !s.ConditionalHas(isPartOf, image.Name) {
return false
}
}
// Filter according to the imported time.
if filter.ImportedAfter > 0 {
if image.ImportTimestamp <= filter.ImportedAfter {
return false
}
}
if filter.ImportedBefore > 0 {
if image.ImportTimestamp >= filter.ImportedBefore {
return false
}
}
// Filter according to the image labels.
if len(filter.Labels) > 0 {
if !containsAllKeyValues(image.Labels, filter.Labels) {
return false
}
}
// Filter according to the annotations.
if len(filter.Annotations) > 0 {
if !containsAllKeyValues(image.Annotations, filter.Annotations) {
return false
}
}
return true
}
|
go
|
func satisfiesImageFilter(image v1alpha.Image, filter v1alpha.ImageFilter) bool {
// Filter according to the IDs.
if len(filter.Ids) > 0 {
s := set.NewString(filter.Ids...)
if !s.Has(image.Id) {
return false
}
}
// Filter according to the image full names.
if len(filter.FullNames) > 0 {
s := set.NewString(filter.FullNames...)
if !s.Has(image.Name) {
return false
}
}
// Filter according to the image name prefixes.
if len(filter.Prefixes) > 0 {
s := set.NewString(filter.Prefixes...)
if !s.ConditionalHas(isPrefixOf, image.Name) {
return false
}
}
// Filter according to the image base name.
if len(filter.BaseNames) > 0 {
s := set.NewString(filter.BaseNames...)
if !s.ConditionalHas(isBaseNameOf, image.Name) {
return false
}
}
// Filter according to the image keywords.
if len(filter.Keywords) > 0 {
s := set.NewString(filter.Keywords...)
if !s.ConditionalHas(isPartOf, image.Name) {
return false
}
}
// Filter according to the imported time.
if filter.ImportedAfter > 0 {
if image.ImportTimestamp <= filter.ImportedAfter {
return false
}
}
if filter.ImportedBefore > 0 {
if image.ImportTimestamp >= filter.ImportedBefore {
return false
}
}
// Filter according to the image labels.
if len(filter.Labels) > 0 {
if !containsAllKeyValues(image.Labels, filter.Labels) {
return false
}
}
// Filter according to the annotations.
if len(filter.Annotations) > 0 {
if !containsAllKeyValues(image.Annotations, filter.Annotations) {
return false
}
}
return true
}
|
[
"func",
"satisfiesImageFilter",
"(",
"image",
"v1alpha",
".",
"Image",
",",
"filter",
"v1alpha",
".",
"ImageFilter",
")",
"bool",
"{",
"// Filter according to the IDs.",
"if",
"len",
"(",
"filter",
".",
"Ids",
")",
">",
"0",
"{",
"s",
":=",
"set",
".",
"NewString",
"(",
"filter",
".",
"Ids",
"...",
")",
"\n",
"if",
"!",
"s",
".",
"Has",
"(",
"image",
".",
"Id",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter according to the image full names.",
"if",
"len",
"(",
"filter",
".",
"FullNames",
")",
">",
"0",
"{",
"s",
":=",
"set",
".",
"NewString",
"(",
"filter",
".",
"FullNames",
"...",
")",
"\n",
"if",
"!",
"s",
".",
"Has",
"(",
"image",
".",
"Name",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter according to the image name prefixes.",
"if",
"len",
"(",
"filter",
".",
"Prefixes",
")",
">",
"0",
"{",
"s",
":=",
"set",
".",
"NewString",
"(",
"filter",
".",
"Prefixes",
"...",
")",
"\n",
"if",
"!",
"s",
".",
"ConditionalHas",
"(",
"isPrefixOf",
",",
"image",
".",
"Name",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter according to the image base name.",
"if",
"len",
"(",
"filter",
".",
"BaseNames",
")",
">",
"0",
"{",
"s",
":=",
"set",
".",
"NewString",
"(",
"filter",
".",
"BaseNames",
"...",
")",
"\n",
"if",
"!",
"s",
".",
"ConditionalHas",
"(",
"isBaseNameOf",
",",
"image",
".",
"Name",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter according to the image keywords.",
"if",
"len",
"(",
"filter",
".",
"Keywords",
")",
">",
"0",
"{",
"s",
":=",
"set",
".",
"NewString",
"(",
"filter",
".",
"Keywords",
"...",
")",
"\n",
"if",
"!",
"s",
".",
"ConditionalHas",
"(",
"isPartOf",
",",
"image",
".",
"Name",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter according to the imported time.",
"if",
"filter",
".",
"ImportedAfter",
">",
"0",
"{",
"if",
"image",
".",
"ImportTimestamp",
"<=",
"filter",
".",
"ImportedAfter",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"filter",
".",
"ImportedBefore",
">",
"0",
"{",
"if",
"image",
".",
"ImportTimestamp",
">=",
"filter",
".",
"ImportedBefore",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter according to the image labels.",
"if",
"len",
"(",
"filter",
".",
"Labels",
")",
">",
"0",
"{",
"if",
"!",
"containsAllKeyValues",
"(",
"image",
".",
"Labels",
",",
"filter",
".",
"Labels",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Filter according to the annotations.",
"if",
"len",
"(",
"filter",
".",
"Annotations",
")",
">",
"0",
"{",
"if",
"!",
"containsAllKeyValues",
"(",
"image",
".",
"Annotations",
",",
"filter",
".",
"Annotations",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] |
// satisfiesImageFilter returns true if the image satisfies the filter.
// The image, filter must not be nil.
|
[
"satisfiesImageFilter",
"returns",
"true",
"if",
"the",
"image",
"satisfies",
"the",
"filter",
".",
"The",
"image",
"filter",
"must",
"not",
"be",
"nil",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L716-L784
|
20,957
|
rkt/rkt
|
rkt/api_service.go
|
satisfiesAnyImageFilters
|
func satisfiesAnyImageFilters(image *v1alpha.Image, filters []*v1alpha.ImageFilter) bool {
// No filters, return true directly.
if len(filters) == 0 {
return true
}
for _, filter := range filters {
if satisfiesImageFilter(*image, *filter) {
return true
}
}
return false
}
|
go
|
func satisfiesAnyImageFilters(image *v1alpha.Image, filters []*v1alpha.ImageFilter) bool {
// No filters, return true directly.
if len(filters) == 0 {
return true
}
for _, filter := range filters {
if satisfiesImageFilter(*image, *filter) {
return true
}
}
return false
}
|
[
"func",
"satisfiesAnyImageFilters",
"(",
"image",
"*",
"v1alpha",
".",
"Image",
",",
"filters",
"[",
"]",
"*",
"v1alpha",
".",
"ImageFilter",
")",
"bool",
"{",
"// No filters, return true directly.",
"if",
"len",
"(",
"filters",
")",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"for",
"_",
",",
"filter",
":=",
"range",
"filters",
"{",
"if",
"satisfiesImageFilter",
"(",
"*",
"image",
",",
"*",
"filter",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// satisfiesAnyImageFilters returns true if any of the filter conditions is satisfied
// by the image, or there's no filters.
|
[
"satisfiesAnyImageFilters",
"returns",
"true",
"if",
"any",
"of",
"the",
"filter",
"conditions",
"is",
"satisfied",
"by",
"the",
"image",
"or",
"there",
"s",
"no",
"filters",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L788-L799
|
20,958
|
rkt/rkt
|
rkt/api_service.go
|
runAPIService
|
func runAPIService(cmd *cobra.Command, args []string) (exit int) {
// Set up the signal handler here so we can make sure the
// signals are caught after print the starting message.
signal.Notify(exitCh, syscall.SIGINT, syscall.SIGTERM)
stderr.Print("API service starting...")
listeners, err := openAPISockets()
if err != nil {
stderr.PrintE("Failed to open sockets", err)
return 254
}
if len(listeners) == 0 { // This is unlikely...
stderr.Println("No sockets to listen to. Quitting.")
return 254
}
publicServer := grpc.NewServer() // TODO(yifan): Add TLS credential option.
v1AlphaAPIServer, err := newV1AlphaAPIServer()
if err != nil {
stderr.PrintE("failed to create API service", err)
return 254
}
v1alpha.RegisterPublicAPIServer(publicServer, v1AlphaAPIServer)
for _, l := range listeners {
defer l.Close()
go publicServer.Serve(l)
}
stderr.Printf("API service running")
<-exitCh
stderr.Print("API service exiting...")
return
}
|
go
|
func runAPIService(cmd *cobra.Command, args []string) (exit int) {
// Set up the signal handler here so we can make sure the
// signals are caught after print the starting message.
signal.Notify(exitCh, syscall.SIGINT, syscall.SIGTERM)
stderr.Print("API service starting...")
listeners, err := openAPISockets()
if err != nil {
stderr.PrintE("Failed to open sockets", err)
return 254
}
if len(listeners) == 0 { // This is unlikely...
stderr.Println("No sockets to listen to. Quitting.")
return 254
}
publicServer := grpc.NewServer() // TODO(yifan): Add TLS credential option.
v1AlphaAPIServer, err := newV1AlphaAPIServer()
if err != nil {
stderr.PrintE("failed to create API service", err)
return 254
}
v1alpha.RegisterPublicAPIServer(publicServer, v1AlphaAPIServer)
for _, l := range listeners {
defer l.Close()
go publicServer.Serve(l)
}
stderr.Printf("API service running")
<-exitCh
stderr.Print("API service exiting...")
return
}
|
[
"func",
"runAPIService",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"(",
"exit",
"int",
")",
"{",
"// Set up the signal handler here so we can make sure the",
"// signals are caught after print the starting message.",
"signal",
".",
"Notify",
"(",
"exitCh",
",",
"syscall",
".",
"SIGINT",
",",
"syscall",
".",
"SIGTERM",
")",
"\n\n",
"stderr",
".",
"Print",
"(",
"\"",
"\"",
")",
"\n\n",
"listeners",
",",
"err",
":=",
"openAPISockets",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"stderr",
".",
"PrintE",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"254",
"\n",
"}",
"\n",
"if",
"len",
"(",
"listeners",
")",
"==",
"0",
"{",
"// This is unlikely...",
"stderr",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"return",
"254",
"\n",
"}",
"\n\n",
"publicServer",
":=",
"grpc",
".",
"NewServer",
"(",
")",
"// TODO(yifan): Add TLS credential option.",
"\n\n",
"v1AlphaAPIServer",
",",
"err",
":=",
"newV1AlphaAPIServer",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"stderr",
".",
"PrintE",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"254",
"\n",
"}",
"\n\n",
"v1alpha",
".",
"RegisterPublicAPIServer",
"(",
"publicServer",
",",
"v1AlphaAPIServer",
")",
"\n\n",
"for",
"_",
",",
"l",
":=",
"range",
"listeners",
"{",
"defer",
"l",
".",
"Close",
"(",
")",
"\n",
"go",
"publicServer",
".",
"Serve",
"(",
"l",
")",
"\n",
"}",
"\n\n",
"stderr",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n\n",
"<-",
"exitCh",
"\n\n",
"stderr",
".",
"Print",
"(",
"\"",
"\"",
")",
"\n\n",
"return",
"\n",
"}"
] |
// Open one or more listening sockets, then start the gRPC server
|
[
"Open",
"one",
"or",
"more",
"listening",
"sockets",
"then",
"start",
"the",
"gRPC",
"server"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/api_service.go#L902-L941
|
20,959
|
rkt/rkt
|
stage1/init/common/units.go
|
WriteUnit
|
func (uw *UnitWriter) WriteUnit(path string, errmsg string, opts ...*unit.UnitOption) {
if uw.err != nil {
return
}
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
uw.err = errwrap.Wrap(errors.New(errmsg), err)
return
}
defer file.Close()
if _, err = io.Copy(file, unit.Serialize(opts)); err != nil {
uw.err = errwrap.Wrap(errors.New(errmsg), err)
return
}
if err := user.ShiftFiles([]string{path}, &uw.p.UidRange); err != nil {
uw.err = errwrap.Wrap(errors.New(errmsg), err)
return
}
}
|
go
|
func (uw *UnitWriter) WriteUnit(path string, errmsg string, opts ...*unit.UnitOption) {
if uw.err != nil {
return
}
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
uw.err = errwrap.Wrap(errors.New(errmsg), err)
return
}
defer file.Close()
if _, err = io.Copy(file, unit.Serialize(opts)); err != nil {
uw.err = errwrap.Wrap(errors.New(errmsg), err)
return
}
if err := user.ShiftFiles([]string{path}, &uw.p.UidRange); err != nil {
uw.err = errwrap.Wrap(errors.New(errmsg), err)
return
}
}
|
[
"func",
"(",
"uw",
"*",
"UnitWriter",
")",
"WriteUnit",
"(",
"path",
"string",
",",
"errmsg",
"string",
",",
"opts",
"...",
"*",
"unit",
".",
"UnitOption",
")",
"{",
"if",
"uw",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"file",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"path",
",",
"os",
".",
"O_WRONLY",
"|",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_TRUNC",
",",
"0644",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"uw",
".",
"err",
"=",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"errmsg",
")",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n\n",
"if",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"file",
",",
"unit",
".",
"Serialize",
"(",
"opts",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"uw",
".",
"err",
"=",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"errmsg",
")",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
":=",
"user",
".",
"ShiftFiles",
"(",
"[",
"]",
"string",
"{",
"path",
"}",
",",
"&",
"uw",
".",
"p",
".",
"UidRange",
")",
";",
"err",
"!=",
"nil",
"{",
"uw",
".",
"err",
"=",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"errmsg",
")",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}"
] |
// WriteUnit writes a systemd unit in the given path with the given unit options
// if no previous error occurred.
|
[
"WriteUnit",
"writes",
"a",
"systemd",
"unit",
"in",
"the",
"given",
"path",
"with",
"the",
"given",
"unit",
"options",
"if",
"no",
"previous",
"error",
"occurred",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L367-L387
|
20,960
|
rkt/rkt
|
stage1/init/common/units.go
|
writeShutdownService
|
func (uw *UnitWriter) writeShutdownService(exec string, opts ...*unit.UnitOption) {
if uw.err != nil {
return
}
flavor, systemdVersion, err := GetFlavor(uw.p)
if err != nil {
uw.err = errwrap.Wrap(errors.New("failed to create shutdown service"), err)
return
}
opts = append(opts, []*unit.UnitOption{
// The default stdout is /dev/console (the tty created by nspawn).
// But the tty might be destroyed if rkt is executed via ssh and
// the user terminates the ssh session. We still want
// shutdown.service to succeed in that case, so don't use
// /dev/console.
unit.NewUnitOption("Service", "StandardInput", "null"),
unit.NewUnitOption("Service", "StandardOutput", "null"),
unit.NewUnitOption("Service", "StandardError", "null"),
}...)
shutdownVerb := "exit"
// systemd <v227 doesn't allow the "exit" verb when running as PID 1, so
// use "halt".
// If systemdVersion is 0 it means it couldn't be guessed, assume it's new
// enough for "systemctl exit".
// This can happen, for example, when building rkt with:
//
// ./configure --with-stage1-flavors=src --with-stage1-systemd-version=master
//
// The patches for the "exit" verb are backported to the "coreos" flavor, so
// don't rely on the systemd version on the "coreos" flavor.
if flavor != "coreos" && systemdVersion != 0 && systemdVersion < 227 {
shutdownVerb = "halt"
}
opts = append(
opts,
unit.NewUnitOption("Service", exec, fmt.Sprintf("/usr/bin/systemctl --force %s", shutdownVerb)),
)
uw.WriteUnit(
ServiceUnitPath(uw.p.Root, "shutdown"),
"failed to create shutdown service",
opts...,
)
}
|
go
|
func (uw *UnitWriter) writeShutdownService(exec string, opts ...*unit.UnitOption) {
if uw.err != nil {
return
}
flavor, systemdVersion, err := GetFlavor(uw.p)
if err != nil {
uw.err = errwrap.Wrap(errors.New("failed to create shutdown service"), err)
return
}
opts = append(opts, []*unit.UnitOption{
// The default stdout is /dev/console (the tty created by nspawn).
// But the tty might be destroyed if rkt is executed via ssh and
// the user terminates the ssh session. We still want
// shutdown.service to succeed in that case, so don't use
// /dev/console.
unit.NewUnitOption("Service", "StandardInput", "null"),
unit.NewUnitOption("Service", "StandardOutput", "null"),
unit.NewUnitOption("Service", "StandardError", "null"),
}...)
shutdownVerb := "exit"
// systemd <v227 doesn't allow the "exit" verb when running as PID 1, so
// use "halt".
// If systemdVersion is 0 it means it couldn't be guessed, assume it's new
// enough for "systemctl exit".
// This can happen, for example, when building rkt with:
//
// ./configure --with-stage1-flavors=src --with-stage1-systemd-version=master
//
// The patches for the "exit" verb are backported to the "coreos" flavor, so
// don't rely on the systemd version on the "coreos" flavor.
if flavor != "coreos" && systemdVersion != 0 && systemdVersion < 227 {
shutdownVerb = "halt"
}
opts = append(
opts,
unit.NewUnitOption("Service", exec, fmt.Sprintf("/usr/bin/systemctl --force %s", shutdownVerb)),
)
uw.WriteUnit(
ServiceUnitPath(uw.p.Root, "shutdown"),
"failed to create shutdown service",
opts...,
)
}
|
[
"func",
"(",
"uw",
"*",
"UnitWriter",
")",
"writeShutdownService",
"(",
"exec",
"string",
",",
"opts",
"...",
"*",
"unit",
".",
"UnitOption",
")",
"{",
"if",
"uw",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"flavor",
",",
"systemdVersion",
",",
"err",
":=",
"GetFlavor",
"(",
"uw",
".",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"uw",
".",
"err",
"=",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"opts",
"=",
"append",
"(",
"opts",
",",
"[",
"]",
"*",
"unit",
".",
"UnitOption",
"{",
"// The default stdout is /dev/console (the tty created by nspawn).",
"// But the tty might be destroyed if rkt is executed via ssh and",
"// the user terminates the ssh session. We still want",
"// shutdown.service to succeed in that case, so don't use",
"// /dev/console.",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"}",
"...",
")",
"\n\n",
"shutdownVerb",
":=",
"\"",
"\"",
"\n",
"// systemd <v227 doesn't allow the \"exit\" verb when running as PID 1, so",
"// use \"halt\".",
"// If systemdVersion is 0 it means it couldn't be guessed, assume it's new",
"// enough for \"systemctl exit\".",
"// This can happen, for example, when building rkt with:",
"//",
"// ./configure --with-stage1-flavors=src --with-stage1-systemd-version=master",
"//",
"// The patches for the \"exit\" verb are backported to the \"coreos\" flavor, so",
"// don't rely on the systemd version on the \"coreos\" flavor.",
"if",
"flavor",
"!=",
"\"",
"\"",
"&&",
"systemdVersion",
"!=",
"0",
"&&",
"systemdVersion",
"<",
"227",
"{",
"shutdownVerb",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"opts",
"=",
"append",
"(",
"opts",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"exec",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"shutdownVerb",
")",
")",
",",
")",
"\n\n",
"uw",
".",
"WriteUnit",
"(",
"ServiceUnitPath",
"(",
"uw",
".",
"p",
".",
"Root",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"opts",
"...",
",",
")",
"\n",
"}"
] |
// writeShutdownService writes a shutdown.service unit with the given unit options
// if no previous error occurred.
// exec specifies how systemctl should be invoked, i.e. ExecStart, or ExecStop.
|
[
"writeShutdownService",
"writes",
"a",
"shutdown",
".",
"service",
"unit",
"with",
"the",
"given",
"unit",
"options",
"if",
"no",
"previous",
"error",
"occurred",
".",
"exec",
"specifies",
"how",
"systemctl",
"should",
"be",
"invoked",
"i",
".",
"e",
".",
"ExecStart",
"or",
"ExecStop",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L392-L439
|
20,961
|
rkt/rkt
|
stage1/init/common/units.go
|
Activate
|
func (uw *UnitWriter) Activate(unit, wantPath string) {
if uw.err != nil {
return
}
if err := os.Symlink(path.Join("..", unit), wantPath); err != nil && !os.IsExist(err) {
uw.err = errwrap.Wrap(errors.New("failed to link service want"), err)
}
}
|
go
|
func (uw *UnitWriter) Activate(unit, wantPath string) {
if uw.err != nil {
return
}
if err := os.Symlink(path.Join("..", unit), wantPath); err != nil && !os.IsExist(err) {
uw.err = errwrap.Wrap(errors.New("failed to link service want"), err)
}
}
|
[
"func",
"(",
"uw",
"*",
"UnitWriter",
")",
"Activate",
"(",
"unit",
",",
"wantPath",
"string",
")",
"{",
"if",
"uw",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"os",
".",
"Symlink",
"(",
"path",
".",
"Join",
"(",
"\"",
"\"",
",",
"unit",
")",
",",
"wantPath",
")",
";",
"err",
"!=",
"nil",
"&&",
"!",
"os",
".",
"IsExist",
"(",
"err",
")",
"{",
"uw",
".",
"err",
"=",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// Activate actives the given unit in the given wantPath.
|
[
"Activate",
"actives",
"the",
"given",
"unit",
"in",
"the",
"given",
"wantPath",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L442-L450
|
20,962
|
rkt/rkt
|
stage1/init/common/units.go
|
AppUnit
|
func (uw *UnitWriter) AppUnit(ra *schema.RuntimeApp, binPath string, opts ...*unit.UnitOption) {
if uw.err != nil {
return
}
if len(ra.App.Exec) == 0 {
uw.err = fmt.Errorf(`image %q has an empty "exec" (try --exec=BINARY)`,
uw.p.AppNameToImageName(ra.Name))
return
}
pa, err := prepareApp(uw.p, ra)
if err != nil {
uw.err = err
return
}
appName := ra.Name.String()
imgName := uw.p.AppNameToImageName(ra.Name)
/* Write the generic unit options */
opts = append(opts, []*unit.UnitOption{
unit.NewUnitOption("Unit", "Description", fmt.Sprintf("Application=%v Image=%v", appName, imgName)),
unit.NewUnitOption("Unit", "DefaultDependencies", "false"),
unit.NewUnitOption("Unit", "Wants", fmt.Sprintf("reaper-%s.service", appName)),
unit.NewUnitOption("Service", "Restart", "no"),
// This helps working around a race
// (https://github.com/systemd/systemd/issues/2913) that causes the
// systemd unit name not getting written to the journal if the unit is
// short-lived and runs as non-root.
unit.NewUnitOption("Service", "SyslogIdentifier", appName),
}...)
// Setup I/O for iottymux (stdin/stdout/stderr)
opts = append(opts, uw.SetupAppIO(uw.p, ra, binPath)...)
if supportsNotify(uw.p, ra.Name.String()) {
opts = append(opts, unit.NewUnitOption("Service", "Type", "notify"))
}
// Some pre-start jobs take a long time, set the timeout to 0
opts = append(opts, unit.NewUnitOption("Service", "TimeoutStartSec", "0"))
opts = append(opts, unit.NewUnitOption("Unit", "Requires", "sysusers.service"))
opts = append(opts, unit.NewUnitOption("Unit", "After", "sysusers.service"))
opts = uw.appSystemdUnit(pa, binPath, opts)
uw.WriteUnit(ServiceUnitPath(uw.p.Root, ra.Name), "failed to create service unit file", opts...)
uw.Activate(ServiceUnitName(ra.Name), ServiceWantPath(uw.p.Root, ra.Name))
}
|
go
|
func (uw *UnitWriter) AppUnit(ra *schema.RuntimeApp, binPath string, opts ...*unit.UnitOption) {
if uw.err != nil {
return
}
if len(ra.App.Exec) == 0 {
uw.err = fmt.Errorf(`image %q has an empty "exec" (try --exec=BINARY)`,
uw.p.AppNameToImageName(ra.Name))
return
}
pa, err := prepareApp(uw.p, ra)
if err != nil {
uw.err = err
return
}
appName := ra.Name.String()
imgName := uw.p.AppNameToImageName(ra.Name)
/* Write the generic unit options */
opts = append(opts, []*unit.UnitOption{
unit.NewUnitOption("Unit", "Description", fmt.Sprintf("Application=%v Image=%v", appName, imgName)),
unit.NewUnitOption("Unit", "DefaultDependencies", "false"),
unit.NewUnitOption("Unit", "Wants", fmt.Sprintf("reaper-%s.service", appName)),
unit.NewUnitOption("Service", "Restart", "no"),
// This helps working around a race
// (https://github.com/systemd/systemd/issues/2913) that causes the
// systemd unit name not getting written to the journal if the unit is
// short-lived and runs as non-root.
unit.NewUnitOption("Service", "SyslogIdentifier", appName),
}...)
// Setup I/O for iottymux (stdin/stdout/stderr)
opts = append(opts, uw.SetupAppIO(uw.p, ra, binPath)...)
if supportsNotify(uw.p, ra.Name.String()) {
opts = append(opts, unit.NewUnitOption("Service", "Type", "notify"))
}
// Some pre-start jobs take a long time, set the timeout to 0
opts = append(opts, unit.NewUnitOption("Service", "TimeoutStartSec", "0"))
opts = append(opts, unit.NewUnitOption("Unit", "Requires", "sysusers.service"))
opts = append(opts, unit.NewUnitOption("Unit", "After", "sysusers.service"))
opts = uw.appSystemdUnit(pa, binPath, opts)
uw.WriteUnit(ServiceUnitPath(uw.p.Root, ra.Name), "failed to create service unit file", opts...)
uw.Activate(ServiceUnitName(ra.Name), ServiceWantPath(uw.p.Root, ra.Name))
}
|
[
"func",
"(",
"uw",
"*",
"UnitWriter",
")",
"AppUnit",
"(",
"ra",
"*",
"schema",
".",
"RuntimeApp",
",",
"binPath",
"string",
",",
"opts",
"...",
"*",
"unit",
".",
"UnitOption",
")",
"{",
"if",
"uw",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"ra",
".",
"App",
".",
"Exec",
")",
"==",
"0",
"{",
"uw",
".",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"`image %q has an empty \"exec\" (try --exec=BINARY)`",
",",
"uw",
".",
"p",
".",
"AppNameToImageName",
"(",
"ra",
".",
"Name",
")",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"pa",
",",
"err",
":=",
"prepareApp",
"(",
"uw",
".",
"p",
",",
"ra",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"uw",
".",
"err",
"=",
"err",
"\n",
"return",
"\n",
"}",
"\n\n",
"appName",
":=",
"ra",
".",
"Name",
".",
"String",
"(",
")",
"\n",
"imgName",
":=",
"uw",
".",
"p",
".",
"AppNameToImageName",
"(",
"ra",
".",
"Name",
")",
"\n",
"/* Write the generic unit options */",
"opts",
"=",
"append",
"(",
"opts",
",",
"[",
"]",
"*",
"unit",
".",
"UnitOption",
"{",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"appName",
",",
"imgName",
")",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"appName",
")",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"// This helps working around a race",
"// (https://github.com/systemd/systemd/issues/2913) that causes the",
"// systemd unit name not getting written to the journal if the unit is",
"// short-lived and runs as non-root.",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"appName",
")",
",",
"}",
"...",
")",
"\n\n",
"// Setup I/O for iottymux (stdin/stdout/stderr)",
"opts",
"=",
"append",
"(",
"opts",
",",
"uw",
".",
"SetupAppIO",
"(",
"uw",
".",
"p",
",",
"ra",
",",
"binPath",
")",
"...",
")",
"\n\n",
"if",
"supportsNotify",
"(",
"uw",
".",
"p",
",",
"ra",
".",
"Name",
".",
"String",
"(",
")",
")",
"{",
"opts",
"=",
"append",
"(",
"opts",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"// Some pre-start jobs take a long time, set the timeout to 0",
"opts",
"=",
"append",
"(",
"opts",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
")",
"\n\n",
"opts",
"=",
"append",
"(",
"opts",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
")",
"\n",
"opts",
"=",
"append",
"(",
"opts",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
")",
"\n\n",
"opts",
"=",
"uw",
".",
"appSystemdUnit",
"(",
"pa",
",",
"binPath",
",",
"opts",
")",
"\n\n",
"uw",
".",
"WriteUnit",
"(",
"ServiceUnitPath",
"(",
"uw",
".",
"p",
".",
"Root",
",",
"ra",
".",
"Name",
")",
",",
"\"",
"\"",
",",
"opts",
"...",
")",
"\n",
"uw",
".",
"Activate",
"(",
"ServiceUnitName",
"(",
"ra",
".",
"Name",
")",
",",
"ServiceWantPath",
"(",
"uw",
".",
"p",
".",
"Root",
",",
"ra",
".",
"Name",
")",
")",
"\n\n",
"}"
] |
// AppUnit sets up the main systemd service unit for the application.
|
[
"AppUnit",
"sets",
"up",
"the",
"main",
"systemd",
"service",
"unit",
"for",
"the",
"application",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L458-L509
|
20,963
|
rkt/rkt
|
stage1/init/common/units.go
|
AppReaperUnit
|
func (uw *UnitWriter) AppReaperUnit(appName types.ACName, binPath string, opts ...*unit.UnitOption) {
if uw.err != nil {
return
}
opts = append(opts, []*unit.UnitOption{
unit.NewUnitOption("Unit", "Description", fmt.Sprintf("%s Reaper", appName)),
unit.NewUnitOption("Unit", "DefaultDependencies", "false"),
unit.NewUnitOption("Unit", "StopWhenUnneeded", "yes"),
unit.NewUnitOption("Unit", "Before", "halt.target"),
unit.NewUnitOption("Unit", "Conflicts", "exit.target"),
unit.NewUnitOption("Unit", "Conflicts", "halt.target"),
unit.NewUnitOption("Unit", "Conflicts", "poweroff.target"),
unit.NewUnitOption("Service", "RemainAfterExit", "yes"),
unit.NewUnitOption("Service", "ExecStop", fmt.Sprintf(
"/reaper.sh \"%s\" \"%s\" \"%s\"",
appName,
common.RelAppRootfsPath(appName),
binPath,
)),
}...)
uw.WriteUnit(
ServiceUnitPath(uw.p.Root, types.ACName(fmt.Sprintf("reaper-%s", appName))),
fmt.Sprintf("failed to write app %q reaper service", appName),
opts...,
)
}
|
go
|
func (uw *UnitWriter) AppReaperUnit(appName types.ACName, binPath string, opts ...*unit.UnitOption) {
if uw.err != nil {
return
}
opts = append(opts, []*unit.UnitOption{
unit.NewUnitOption("Unit", "Description", fmt.Sprintf("%s Reaper", appName)),
unit.NewUnitOption("Unit", "DefaultDependencies", "false"),
unit.NewUnitOption("Unit", "StopWhenUnneeded", "yes"),
unit.NewUnitOption("Unit", "Before", "halt.target"),
unit.NewUnitOption("Unit", "Conflicts", "exit.target"),
unit.NewUnitOption("Unit", "Conflicts", "halt.target"),
unit.NewUnitOption("Unit", "Conflicts", "poweroff.target"),
unit.NewUnitOption("Service", "RemainAfterExit", "yes"),
unit.NewUnitOption("Service", "ExecStop", fmt.Sprintf(
"/reaper.sh \"%s\" \"%s\" \"%s\"",
appName,
common.RelAppRootfsPath(appName),
binPath,
)),
}...)
uw.WriteUnit(
ServiceUnitPath(uw.p.Root, types.ACName(fmt.Sprintf("reaper-%s", appName))),
fmt.Sprintf("failed to write app %q reaper service", appName),
opts...,
)
}
|
[
"func",
"(",
"uw",
"*",
"UnitWriter",
")",
"AppReaperUnit",
"(",
"appName",
"types",
".",
"ACName",
",",
"binPath",
"string",
",",
"opts",
"...",
"*",
"unit",
".",
"UnitOption",
")",
"{",
"if",
"uw",
".",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"opts",
"=",
"append",
"(",
"opts",
",",
"[",
"]",
"*",
"unit",
".",
"UnitOption",
"{",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"appName",
")",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\"",
",",
"appName",
",",
"common",
".",
"RelAppRootfsPath",
"(",
"appName",
")",
",",
"binPath",
",",
")",
")",
",",
"}",
"...",
")",
"\n\n",
"uw",
".",
"WriteUnit",
"(",
"ServiceUnitPath",
"(",
"uw",
".",
"p",
".",
"Root",
",",
"types",
".",
"ACName",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"appName",
")",
")",
")",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"appName",
")",
",",
"opts",
"...",
",",
")",
"\n",
"}"
] |
// AppReaperUnit writes an app reaper service unit for the given app in the given path using the given unit options.
|
[
"AppReaperUnit",
"writes",
"an",
"app",
"reaper",
"service",
"unit",
"for",
"the",
"given",
"app",
"in",
"the",
"given",
"path",
"using",
"the",
"given",
"unit",
"options",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L737-L764
|
20,964
|
rkt/rkt
|
stage1/init/common/units.go
|
AppSocketUnit
|
func (uw *UnitWriter) AppSocketUnit(appName types.ACName, binPath string, streamName string, opts ...*unit.UnitOption) {
opts = append(opts, []*unit.UnitOption{
unit.NewUnitOption("Unit", "Description", fmt.Sprintf("%s socket for %s", streamName, appName)),
unit.NewUnitOption("Unit", "DefaultDependencies", "no"),
unit.NewUnitOption("Unit", "StopWhenUnneeded", "yes"),
unit.NewUnitOption("Unit", "RefuseManualStart", "yes"),
unit.NewUnitOption("Unit", "RefuseManualStop", "yes"),
unit.NewUnitOption("Unit", "BindsTo", fmt.Sprintf("%s.service", appName)),
unit.NewUnitOption("Socket", "RemoveOnStop", "yes"),
unit.NewUnitOption("Socket", "Service", fmt.Sprintf("%s.service", appName)),
unit.NewUnitOption("Socket", "FileDescriptorName", streamName),
unit.NewUnitOption("Socket", "ListenFIFO", filepath.Join("/rkt/iottymux", appName.String(), "stage2-"+streamName)),
}...)
uw.WriteUnit(
TypedUnitPath(uw.p.Root, appName.String()+"-"+streamName, "socket"),
fmt.Sprintf("failed to write %s socket for %q service", streamName, appName),
opts...,
)
}
|
go
|
func (uw *UnitWriter) AppSocketUnit(appName types.ACName, binPath string, streamName string, opts ...*unit.UnitOption) {
opts = append(opts, []*unit.UnitOption{
unit.NewUnitOption("Unit", "Description", fmt.Sprintf("%s socket for %s", streamName, appName)),
unit.NewUnitOption("Unit", "DefaultDependencies", "no"),
unit.NewUnitOption("Unit", "StopWhenUnneeded", "yes"),
unit.NewUnitOption("Unit", "RefuseManualStart", "yes"),
unit.NewUnitOption("Unit", "RefuseManualStop", "yes"),
unit.NewUnitOption("Unit", "BindsTo", fmt.Sprintf("%s.service", appName)),
unit.NewUnitOption("Socket", "RemoveOnStop", "yes"),
unit.NewUnitOption("Socket", "Service", fmt.Sprintf("%s.service", appName)),
unit.NewUnitOption("Socket", "FileDescriptorName", streamName),
unit.NewUnitOption("Socket", "ListenFIFO", filepath.Join("/rkt/iottymux", appName.String(), "stage2-"+streamName)),
}...)
uw.WriteUnit(
TypedUnitPath(uw.p.Root, appName.String()+"-"+streamName, "socket"),
fmt.Sprintf("failed to write %s socket for %q service", streamName, appName),
opts...,
)
}
|
[
"func",
"(",
"uw",
"*",
"UnitWriter",
")",
"AppSocketUnit",
"(",
"appName",
"types",
".",
"ACName",
",",
"binPath",
"string",
",",
"streamName",
"string",
",",
"opts",
"...",
"*",
"unit",
".",
"UnitOption",
")",
"{",
"opts",
"=",
"append",
"(",
"opts",
",",
"[",
"]",
"*",
"unit",
".",
"UnitOption",
"{",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"streamName",
",",
"appName",
")",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"appName",
")",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"appName",
")",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"streamName",
")",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filepath",
".",
"Join",
"(",
"\"",
"\"",
",",
"appName",
".",
"String",
"(",
")",
",",
"\"",
"\"",
"+",
"streamName",
")",
")",
",",
"}",
"...",
")",
"\n\n",
"uw",
".",
"WriteUnit",
"(",
"TypedUnitPath",
"(",
"uw",
".",
"p",
".",
"Root",
",",
"appName",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"+",
"streamName",
",",
"\"",
"\"",
")",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"streamName",
",",
"appName",
")",
",",
"opts",
"...",
",",
")",
"\n",
"}"
] |
// AppSocketUnits writes a stream socket-unit for the given app in the given path.
|
[
"AppSocketUnits",
"writes",
"a",
"stream",
"socket",
"-",
"unit",
"for",
"the",
"given",
"app",
"in",
"the",
"given",
"path",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L767-L786
|
20,965
|
rkt/rkt
|
stage1/init/common/units.go
|
appendOptionsList
|
func appendOptionsList(opts []*unit.UnitOption, section, property, prefix string, vals ...string) []*unit.UnitOption {
for _, v := range vals {
opts = append(opts, unit.NewUnitOption(section, property, fmt.Sprintf("%s%s", prefix, v)))
}
return opts
}
|
go
|
func appendOptionsList(opts []*unit.UnitOption, section, property, prefix string, vals ...string) []*unit.UnitOption {
for _, v := range vals {
opts = append(opts, unit.NewUnitOption(section, property, fmt.Sprintf("%s%s", prefix, v)))
}
return opts
}
|
[
"func",
"appendOptionsList",
"(",
"opts",
"[",
"]",
"*",
"unit",
".",
"UnitOption",
",",
"section",
",",
"property",
",",
"prefix",
"string",
",",
"vals",
"...",
"string",
")",
"[",
"]",
"*",
"unit",
".",
"UnitOption",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"vals",
"{",
"opts",
"=",
"append",
"(",
"opts",
",",
"unit",
".",
"NewUnitOption",
"(",
"section",
",",
"property",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"prefix",
",",
"v",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"opts",
"\n",
"}"
] |
// appendOptionsList updates an existing unit options list appending
// an array of new properties, one entry at a time.
// This is the preferred method to avoid hitting line length limits
// in unit files. Target property must support multi-line entries.
|
[
"appendOptionsList",
"updates",
"an",
"existing",
"unit",
"options",
"list",
"appending",
"an",
"array",
"of",
"new",
"properties",
"one",
"entry",
"at",
"a",
"time",
".",
"This",
"is",
"the",
"preferred",
"method",
"to",
"avoid",
"hitting",
"line",
"length",
"limits",
"in",
"unit",
"files",
".",
"Target",
"property",
"must",
"support",
"multi",
"-",
"line",
"entries",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/units.go#L792-L797
|
20,966
|
rkt/rkt
|
lib/app.go
|
AppsForPod
|
func AppsForPod(uuid, dataDir string, appName string) ([]*v1.App, error) {
p, err := pkgPod.PodFromUUIDString(dataDir, uuid)
if err != nil {
return nil, err
}
defer p.Close()
return appsForPod(p, appName, appStateInMutablePod)
}
|
go
|
func AppsForPod(uuid, dataDir string, appName string) ([]*v1.App, error) {
p, err := pkgPod.PodFromUUIDString(dataDir, uuid)
if err != nil {
return nil, err
}
defer p.Close()
return appsForPod(p, appName, appStateInMutablePod)
}
|
[
"func",
"AppsForPod",
"(",
"uuid",
",",
"dataDir",
"string",
",",
"appName",
"string",
")",
"(",
"[",
"]",
"*",
"v1",
".",
"App",
",",
"error",
")",
"{",
"p",
",",
"err",
":=",
"pkgPod",
".",
"PodFromUUIDString",
"(",
"dataDir",
",",
"uuid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"p",
".",
"Close",
"(",
")",
"\n\n",
"return",
"appsForPod",
"(",
"p",
",",
"appName",
",",
"appStateInMutablePod",
")",
"\n",
"}"
] |
// AppsForPod returns the apps of the pod with the given uuid in the given data directory.
// If appName is non-empty, then only the app with the given name will be returned.
|
[
"AppsForPod",
"returns",
"the",
"apps",
"of",
"the",
"pod",
"with",
"the",
"given",
"uuid",
"in",
"the",
"given",
"data",
"directory",
".",
"If",
"appName",
"is",
"non",
"-",
"empty",
"then",
"only",
"the",
"app",
"with",
"the",
"given",
"name",
"will",
"be",
"returned",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/lib/app.go#L38-L46
|
20,967
|
rkt/rkt
|
lib/app.go
|
newApp
|
func newApp(ra *schema.RuntimeApp, podManifest *schema.PodManifest, pod *pkgPod.Pod, appState appStateFunc) (*v1.App, error) {
app := &v1.App{
Name: ra.Name.String(),
ImageID: ra.Image.ID.String(),
UserAnnotations: ra.App.UserAnnotations,
UserLabels: ra.App.UserLabels,
}
podVols := podManifest.Volumes
podVolsByName := make(map[types.ACName]types.Volume, len(podVols))
for i := range podManifest.Volumes {
podVolsByName[podVols[i].Name] = podVols[i]
}
for _, mnt := range ra.Mounts {
readOnly := false
var hostPath string
// AppVolume is optional
if av := mnt.AppVolume; av != nil {
hostPath = av.Source
if ro := av.ReadOnly; ro != nil {
readOnly = *ro
}
} else {
hostPath = podVolsByName[mnt.Volume].Source
if ro := podVolsByName[mnt.Volume].ReadOnly; ro != nil {
readOnly = *ro
}
}
app.Mounts = append(app.Mounts, &v1.Mount{
Name: mnt.Volume.String(),
ContainerPath: mnt.Path,
HostPath: hostPath,
ReadOnly: readOnly,
})
}
// Generate state.
if err := appState(app, pod); err != nil {
return nil, fmt.Errorf("error getting app's state: %v", err)
}
return app, nil
}
|
go
|
func newApp(ra *schema.RuntimeApp, podManifest *schema.PodManifest, pod *pkgPod.Pod, appState appStateFunc) (*v1.App, error) {
app := &v1.App{
Name: ra.Name.String(),
ImageID: ra.Image.ID.String(),
UserAnnotations: ra.App.UserAnnotations,
UserLabels: ra.App.UserLabels,
}
podVols := podManifest.Volumes
podVolsByName := make(map[types.ACName]types.Volume, len(podVols))
for i := range podManifest.Volumes {
podVolsByName[podVols[i].Name] = podVols[i]
}
for _, mnt := range ra.Mounts {
readOnly := false
var hostPath string
// AppVolume is optional
if av := mnt.AppVolume; av != nil {
hostPath = av.Source
if ro := av.ReadOnly; ro != nil {
readOnly = *ro
}
} else {
hostPath = podVolsByName[mnt.Volume].Source
if ro := podVolsByName[mnt.Volume].ReadOnly; ro != nil {
readOnly = *ro
}
}
app.Mounts = append(app.Mounts, &v1.Mount{
Name: mnt.Volume.String(),
ContainerPath: mnt.Path,
HostPath: hostPath,
ReadOnly: readOnly,
})
}
// Generate state.
if err := appState(app, pod); err != nil {
return nil, fmt.Errorf("error getting app's state: %v", err)
}
return app, nil
}
|
[
"func",
"newApp",
"(",
"ra",
"*",
"schema",
".",
"RuntimeApp",
",",
"podManifest",
"*",
"schema",
".",
"PodManifest",
",",
"pod",
"*",
"pkgPod",
".",
"Pod",
",",
"appState",
"appStateFunc",
")",
"(",
"*",
"v1",
".",
"App",
",",
"error",
")",
"{",
"app",
":=",
"&",
"v1",
".",
"App",
"{",
"Name",
":",
"ra",
".",
"Name",
".",
"String",
"(",
")",
",",
"ImageID",
":",
"ra",
".",
"Image",
".",
"ID",
".",
"String",
"(",
")",
",",
"UserAnnotations",
":",
"ra",
".",
"App",
".",
"UserAnnotations",
",",
"UserLabels",
":",
"ra",
".",
"App",
".",
"UserLabels",
",",
"}",
"\n\n",
"podVols",
":=",
"podManifest",
".",
"Volumes",
"\n",
"podVolsByName",
":=",
"make",
"(",
"map",
"[",
"types",
".",
"ACName",
"]",
"types",
".",
"Volume",
",",
"len",
"(",
"podVols",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"podManifest",
".",
"Volumes",
"{",
"podVolsByName",
"[",
"podVols",
"[",
"i",
"]",
".",
"Name",
"]",
"=",
"podVols",
"[",
"i",
"]",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"mnt",
":=",
"range",
"ra",
".",
"Mounts",
"{",
"readOnly",
":=",
"false",
"\n",
"var",
"hostPath",
"string",
"\n",
"// AppVolume is optional",
"if",
"av",
":=",
"mnt",
".",
"AppVolume",
";",
"av",
"!=",
"nil",
"{",
"hostPath",
"=",
"av",
".",
"Source",
"\n",
"if",
"ro",
":=",
"av",
".",
"ReadOnly",
";",
"ro",
"!=",
"nil",
"{",
"readOnly",
"=",
"*",
"ro",
"\n",
"}",
"\n",
"}",
"else",
"{",
"hostPath",
"=",
"podVolsByName",
"[",
"mnt",
".",
"Volume",
"]",
".",
"Source",
"\n",
"if",
"ro",
":=",
"podVolsByName",
"[",
"mnt",
".",
"Volume",
"]",
".",
"ReadOnly",
";",
"ro",
"!=",
"nil",
"{",
"readOnly",
"=",
"*",
"ro",
"\n",
"}",
"\n",
"}",
"\n",
"app",
".",
"Mounts",
"=",
"append",
"(",
"app",
".",
"Mounts",
",",
"&",
"v1",
".",
"Mount",
"{",
"Name",
":",
"mnt",
".",
"Volume",
".",
"String",
"(",
")",
",",
"ContainerPath",
":",
"mnt",
".",
"Path",
",",
"HostPath",
":",
"hostPath",
",",
"ReadOnly",
":",
"readOnly",
",",
"}",
")",
"\n",
"}",
"\n\n",
"// Generate state.",
"if",
"err",
":=",
"appState",
"(",
"app",
",",
"pod",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"app",
",",
"nil",
"\n",
"}"
] |
// newApp constructs the App object with the runtime app and pod manifest.
|
[
"newApp",
"constructs",
"the",
"App",
"object",
"with",
"the",
"runtime",
"app",
"and",
"pod",
"manifest",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/lib/app.go#L73-L116
|
20,968
|
rkt/rkt
|
lib/app.go
|
appStateInImmutablePod
|
func appStateInImmutablePod(app *v1.App, pod *pkgPod.Pod) error {
app.State = appStateFromPod(pod)
t, err := pod.CreationTime()
if err != nil {
return err
}
createdAt := t.UnixNano()
app.CreatedAt = &createdAt
code, err := pod.AppExitCode(app.Name)
if err == nil {
// there is an exit code, it is definitely Exited
app.State = v1.AppStateExited
exitCode := int32(code)
app.ExitCode = &exitCode
}
start, err := pod.StartTime()
if err != nil {
return err
}
if !start.IsZero() {
startedAt := start.UnixNano()
app.StartedAt = &startedAt
}
// the best we can guess for immutable pods
finish, err := pod.GCMarkedTime()
if err != nil {
return err
}
if !finish.IsZero() {
finishedAt := finish.UnixNano()
app.FinishedAt = &finishedAt
}
return nil
}
|
go
|
func appStateInImmutablePod(app *v1.App, pod *pkgPod.Pod) error {
app.State = appStateFromPod(pod)
t, err := pod.CreationTime()
if err != nil {
return err
}
createdAt := t.UnixNano()
app.CreatedAt = &createdAt
code, err := pod.AppExitCode(app.Name)
if err == nil {
// there is an exit code, it is definitely Exited
app.State = v1.AppStateExited
exitCode := int32(code)
app.ExitCode = &exitCode
}
start, err := pod.StartTime()
if err != nil {
return err
}
if !start.IsZero() {
startedAt := start.UnixNano()
app.StartedAt = &startedAt
}
// the best we can guess for immutable pods
finish, err := pod.GCMarkedTime()
if err != nil {
return err
}
if !finish.IsZero() {
finishedAt := finish.UnixNano()
app.FinishedAt = &finishedAt
}
return nil
}
|
[
"func",
"appStateInImmutablePod",
"(",
"app",
"*",
"v1",
".",
"App",
",",
"pod",
"*",
"pkgPod",
".",
"Pod",
")",
"error",
"{",
"app",
".",
"State",
"=",
"appStateFromPod",
"(",
"pod",
")",
"\n\n",
"t",
",",
"err",
":=",
"pod",
".",
"CreationTime",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"createdAt",
":=",
"t",
".",
"UnixNano",
"(",
")",
"\n",
"app",
".",
"CreatedAt",
"=",
"&",
"createdAt",
"\n\n",
"code",
",",
"err",
":=",
"pod",
".",
"AppExitCode",
"(",
"app",
".",
"Name",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// there is an exit code, it is definitely Exited",
"app",
".",
"State",
"=",
"v1",
".",
"AppStateExited",
"\n",
"exitCode",
":=",
"int32",
"(",
"code",
")",
"\n",
"app",
".",
"ExitCode",
"=",
"&",
"exitCode",
"\n",
"}",
"\n\n",
"start",
",",
"err",
":=",
"pod",
".",
"StartTime",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"start",
".",
"IsZero",
"(",
")",
"{",
"startedAt",
":=",
"start",
".",
"UnixNano",
"(",
")",
"\n",
"app",
".",
"StartedAt",
"=",
"&",
"startedAt",
"\n",
"}",
"\n",
"// the best we can guess for immutable pods",
"finish",
",",
"err",
":=",
"pod",
".",
"GCMarkedTime",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"finish",
".",
"IsZero",
"(",
")",
"{",
"finishedAt",
":=",
"finish",
".",
"UnixNano",
"(",
")",
"\n",
"app",
".",
"FinishedAt",
"=",
"&",
"finishedAt",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// appStateInImmutablePod infers most App state from the Pod itself, since all apps are created and destroyed with the Pod
|
[
"appStateInImmutablePod",
"infers",
"most",
"App",
"state",
"from",
"the",
"Pod",
"itself",
"since",
"all",
"apps",
"are",
"created",
"and",
"destroyed",
"with",
"the",
"Pod"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/lib/app.go#L200-L237
|
20,969
|
rkt/rkt
|
stage1/common/types/pod.go
|
SaveRuntime
|
func (p *Pod) SaveRuntime() error {
path := filepath.Join(p.Root, RuntimeConfigPath)
buf, err := json.Marshal(p.RuntimePod)
if err != nil {
return err
}
return ioutil.WriteFile(path, buf, 0644)
}
|
go
|
func (p *Pod) SaveRuntime() error {
path := filepath.Join(p.Root, RuntimeConfigPath)
buf, err := json.Marshal(p.RuntimePod)
if err != nil {
return err
}
return ioutil.WriteFile(path, buf, 0644)
}
|
[
"func",
"(",
"p",
"*",
"Pod",
")",
"SaveRuntime",
"(",
")",
"error",
"{",
"path",
":=",
"filepath",
".",
"Join",
"(",
"p",
".",
"Root",
",",
"RuntimeConfigPath",
")",
"\n",
"buf",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"p",
".",
"RuntimePod",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"ioutil",
".",
"WriteFile",
"(",
"path",
",",
"buf",
",",
"0644",
")",
"\n",
"}"
] |
// SaveRuntime persists just the runtime state. This should be called when the
// pod is started.
|
[
"SaveRuntime",
"persists",
"just",
"the",
"runtime",
"state",
".",
"This",
"should",
"be",
"called",
"when",
"the",
"pod",
"is",
"started",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/common/types/pod.go#L91-L99
|
20,970
|
rkt/rkt
|
stage1/common/types/pod.go
|
LoadPodManifest
|
func LoadPodManifest(root string) (*schema.PodManifest, error) {
buf, err := ioutil.ReadFile(common.PodManifestPath(root))
if err != nil {
return nil, errwrap.Wrap(errors.New("failed reading pod manifest"), err)
}
pm := &schema.PodManifest{}
if err := json.Unmarshal(buf, pm); err != nil {
return nil, errwrap.Wrap(errors.New("failed unmarshalling pod manifest"), err)
}
return pm, nil
}
|
go
|
func LoadPodManifest(root string) (*schema.PodManifest, error) {
buf, err := ioutil.ReadFile(common.PodManifestPath(root))
if err != nil {
return nil, errwrap.Wrap(errors.New("failed reading pod manifest"), err)
}
pm := &schema.PodManifest{}
if err := json.Unmarshal(buf, pm); err != nil {
return nil, errwrap.Wrap(errors.New("failed unmarshalling pod manifest"), err)
}
return pm, nil
}
|
[
"func",
"LoadPodManifest",
"(",
"root",
"string",
")",
"(",
"*",
"schema",
".",
"PodManifest",
",",
"error",
")",
"{",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"common",
".",
"PodManifestPath",
"(",
"root",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"pm",
":=",
"&",
"schema",
".",
"PodManifest",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"buf",
",",
"pm",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"pm",
",",
"nil",
"\n",
"}"
] |
// LoadPodManifest loads a Pod Manifest.
|
[
"LoadPodManifest",
"loads",
"a",
"Pod",
"Manifest",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/common/types/pod.go#L102-L113
|
20,971
|
rkt/rkt
|
rkt/image/fetcher.go
|
FetchImages
|
func (f *Fetcher) FetchImages(al *apps.Apps) error {
return al.Walk(func(app *apps.App) error {
d, err := DistFromImageString(app.Image)
if err != nil {
return err
}
h, err := f.FetchImage(d, app.Image, app.Asc)
if err != nil {
return err
}
app.ImageID = *h
return nil
})
}
|
go
|
func (f *Fetcher) FetchImages(al *apps.Apps) error {
return al.Walk(func(app *apps.App) error {
d, err := DistFromImageString(app.Image)
if err != nil {
return err
}
h, err := f.FetchImage(d, app.Image, app.Asc)
if err != nil {
return err
}
app.ImageID = *h
return nil
})
}
|
[
"func",
"(",
"f",
"*",
"Fetcher",
")",
"FetchImages",
"(",
"al",
"*",
"apps",
".",
"Apps",
")",
"error",
"{",
"return",
"al",
".",
"Walk",
"(",
"func",
"(",
"app",
"*",
"apps",
".",
"App",
")",
"error",
"{",
"d",
",",
"err",
":=",
"DistFromImageString",
"(",
"app",
".",
"Image",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"h",
",",
"err",
":=",
"f",
".",
"FetchImage",
"(",
"d",
",",
"app",
".",
"Image",
",",
"app",
".",
"Asc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"app",
".",
"ImageID",
"=",
"*",
"h",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"}"
] |
// FetchImages uses FetchImage to attain a list of image hashes
|
[
"FetchImages",
"uses",
"FetchImage",
"to",
"attain",
"a",
"list",
"of",
"image",
"hashes"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/fetcher.go#L46-L59
|
20,972
|
rkt/rkt
|
rkt/image/fetcher.go
|
FetchImage
|
func (f *Fetcher) FetchImage(d dist.Distribution, image, ascPath string) (*types.Hash, error) {
ensureLogger(f.Debug)
db := &distBundle{
dist: d,
image: image,
}
a := f.getAsc(ascPath)
hash, err := f.fetchSingleImage(db, a)
if err != nil {
return nil, err
}
if f.WithDeps {
err = f.fetchImageDeps(hash)
if err != nil {
return nil, err
}
}
// we need to be able to do a chroot and access to the tree store
// directories, we need to
// 1) check if the system supports OverlayFS
// 2) check if we're root
if common.SupportsOverlay() == nil && os.Geteuid() == 0 {
if _, _, err := f.Ts.Render(hash, false); err != nil {
return nil, errwrap.Wrap(errors.New("error rendering tree store"), err)
}
}
h, err := types.NewHash(hash)
if err != nil {
// should never happen
log.PanicE("invalid hash", err)
}
return h, nil
}
|
go
|
func (f *Fetcher) FetchImage(d dist.Distribution, image, ascPath string) (*types.Hash, error) {
ensureLogger(f.Debug)
db := &distBundle{
dist: d,
image: image,
}
a := f.getAsc(ascPath)
hash, err := f.fetchSingleImage(db, a)
if err != nil {
return nil, err
}
if f.WithDeps {
err = f.fetchImageDeps(hash)
if err != nil {
return nil, err
}
}
// we need to be able to do a chroot and access to the tree store
// directories, we need to
// 1) check if the system supports OverlayFS
// 2) check if we're root
if common.SupportsOverlay() == nil && os.Geteuid() == 0 {
if _, _, err := f.Ts.Render(hash, false); err != nil {
return nil, errwrap.Wrap(errors.New("error rendering tree store"), err)
}
}
h, err := types.NewHash(hash)
if err != nil {
// should never happen
log.PanicE("invalid hash", err)
}
return h, nil
}
|
[
"func",
"(",
"f",
"*",
"Fetcher",
")",
"FetchImage",
"(",
"d",
"dist",
".",
"Distribution",
",",
"image",
",",
"ascPath",
"string",
")",
"(",
"*",
"types",
".",
"Hash",
",",
"error",
")",
"{",
"ensureLogger",
"(",
"f",
".",
"Debug",
")",
"\n",
"db",
":=",
"&",
"distBundle",
"{",
"dist",
":",
"d",
",",
"image",
":",
"image",
",",
"}",
"\n",
"a",
":=",
"f",
".",
"getAsc",
"(",
"ascPath",
")",
"\n",
"hash",
",",
"err",
":=",
"f",
".",
"fetchSingleImage",
"(",
"db",
",",
"a",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"f",
".",
"WithDeps",
"{",
"err",
"=",
"f",
".",
"fetchImageDeps",
"(",
"hash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// we need to be able to do a chroot and access to the tree store",
"// directories, we need to",
"// 1) check if the system supports OverlayFS",
"// 2) check if we're root",
"if",
"common",
".",
"SupportsOverlay",
"(",
")",
"==",
"nil",
"&&",
"os",
".",
"Geteuid",
"(",
")",
"==",
"0",
"{",
"if",
"_",
",",
"_",
",",
"err",
":=",
"f",
".",
"Ts",
".",
"Render",
"(",
"hash",
",",
"false",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"h",
",",
"err",
":=",
"types",
".",
"NewHash",
"(",
"hash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// should never happen",
"log",
".",
"PanicE",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"h",
",",
"nil",
"\n",
"}"
] |
// FetchImage will take an image as either a path, a URL or a name
// string and import it into the store if found. If ascPath is not "",
// it must exist as a local file and will be used as the signature
// file for verification, unless verification is disabled. If
// f.WithDeps is true also image dependencies are fetched.
|
[
"FetchImage",
"will",
"take",
"an",
"image",
"as",
"either",
"a",
"path",
"a",
"URL",
"or",
"a",
"name",
"string",
"and",
"import",
"it",
"into",
"the",
"store",
"if",
"found",
".",
"If",
"ascPath",
"is",
"not",
"it",
"must",
"exist",
"as",
"a",
"local",
"file",
"and",
"will",
"be",
"used",
"as",
"the",
"signature",
"file",
"for",
"verification",
"unless",
"verification",
"is",
"disabled",
".",
"If",
"f",
".",
"WithDeps",
"is",
"true",
"also",
"image",
"dependencies",
"are",
"fetched",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/fetcher.go#L66-L99
|
20,973
|
rkt/rkt
|
rkt/image/fetcher.go
|
fetchImageDeps
|
func (f *Fetcher) fetchImageDeps(hash string) error {
imgsl := list.New()
seen := map[string]dist.Distribution{}
f.addImageDeps(hash, imgsl, seen)
for el := imgsl.Front(); el != nil; el = el.Next() {
a := &asc{}
d := el.Value.(*dist.Appc)
str := d.String()
db := &distBundle{
dist: d,
image: str,
}
hash, err := f.fetchSingleImage(db, a)
if err != nil {
return err
}
f.addImageDeps(hash, imgsl, seen)
}
return nil
}
|
go
|
func (f *Fetcher) fetchImageDeps(hash string) error {
imgsl := list.New()
seen := map[string]dist.Distribution{}
f.addImageDeps(hash, imgsl, seen)
for el := imgsl.Front(); el != nil; el = el.Next() {
a := &asc{}
d := el.Value.(*dist.Appc)
str := d.String()
db := &distBundle{
dist: d,
image: str,
}
hash, err := f.fetchSingleImage(db, a)
if err != nil {
return err
}
f.addImageDeps(hash, imgsl, seen)
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Fetcher",
")",
"fetchImageDeps",
"(",
"hash",
"string",
")",
"error",
"{",
"imgsl",
":=",
"list",
".",
"New",
"(",
")",
"\n",
"seen",
":=",
"map",
"[",
"string",
"]",
"dist",
".",
"Distribution",
"{",
"}",
"\n",
"f",
".",
"addImageDeps",
"(",
"hash",
",",
"imgsl",
",",
"seen",
")",
"\n",
"for",
"el",
":=",
"imgsl",
".",
"Front",
"(",
")",
";",
"el",
"!=",
"nil",
";",
"el",
"=",
"el",
".",
"Next",
"(",
")",
"{",
"a",
":=",
"&",
"asc",
"{",
"}",
"\n",
"d",
":=",
"el",
".",
"Value",
".",
"(",
"*",
"dist",
".",
"Appc",
")",
"\n",
"str",
":=",
"d",
".",
"String",
"(",
")",
"\n",
"db",
":=",
"&",
"distBundle",
"{",
"dist",
":",
"d",
",",
"image",
":",
"str",
",",
"}",
"\n",
"hash",
",",
"err",
":=",
"f",
".",
"fetchSingleImage",
"(",
"db",
",",
"a",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"f",
".",
"addImageDeps",
"(",
"hash",
",",
"imgsl",
",",
"seen",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// fetchImageDeps will recursively fetch all the image dependencies
|
[
"fetchImageDeps",
"will",
"recursively",
"fetch",
"all",
"the",
"image",
"dependencies"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/fetcher.go#L112-L131
|
20,974
|
rkt/rkt
|
pkg/log/log.go
|
New
|
func New(out io.Writer, prefix string, debug bool) *Logger {
l := &Logger{
debug: debug,
Logger: log.New(out, prefix, 0),
}
l.SetFlags(0)
return l
}
|
go
|
func New(out io.Writer, prefix string, debug bool) *Logger {
l := &Logger{
debug: debug,
Logger: log.New(out, prefix, 0),
}
l.SetFlags(0)
return l
}
|
[
"func",
"New",
"(",
"out",
"io",
".",
"Writer",
",",
"prefix",
"string",
",",
"debug",
"bool",
")",
"*",
"Logger",
"{",
"l",
":=",
"&",
"Logger",
"{",
"debug",
":",
"debug",
",",
"Logger",
":",
"log",
".",
"New",
"(",
"out",
",",
"prefix",
",",
"0",
")",
",",
"}",
"\n",
"l",
".",
"SetFlags",
"(",
"0",
")",
"\n",
"return",
"l",
"\n",
"}"
] |
// New creates a new Logger with no Log flags set.
|
[
"New",
"creates",
"a",
"new",
"Logger",
"with",
"no",
"Log",
"flags",
"set",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/log/log.go#L35-L42
|
20,975
|
rkt/rkt
|
pkg/log/log.go
|
Error
|
func (l *Logger) Error(e error) {
l.Print(l.formatErr(e, ""))
}
|
go
|
func (l *Logger) Error(e error) {
l.Print(l.formatErr(e, ""))
}
|
[
"func",
"(",
"l",
"*",
"Logger",
")",
"Error",
"(",
"e",
"error",
")",
"{",
"l",
".",
"Print",
"(",
"l",
".",
"formatErr",
"(",
"e",
",",
"\"",
"\"",
")",
")",
"\n",
"}"
] |
// Error is a convenience function for printing errors without a message.
|
[
"Error",
"is",
"a",
"convenience",
"function",
"for",
"printing",
"errors",
"without",
"a",
"message",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/log/log.go#L110-L112
|
20,976
|
rkt/rkt
|
pkg/log/log.go
|
Errorf
|
func (l *Logger) Errorf(format string, a ...interface{}) {
l.Print(l.formatErr(fmt.Errorf(format, a...), ""))
}
|
go
|
func (l *Logger) Errorf(format string, a ...interface{}) {
l.Print(l.formatErr(fmt.Errorf(format, a...), ""))
}
|
[
"func",
"(",
"l",
"*",
"Logger",
")",
"Errorf",
"(",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"Print",
"(",
"l",
".",
"formatErr",
"(",
"fmt",
".",
"Errorf",
"(",
"format",
",",
"a",
"...",
")",
",",
"\"",
"\"",
")",
")",
"\n",
"}"
] |
// Errorf is a convenience function for formatting and printing errors.
|
[
"Errorf",
"is",
"a",
"convenience",
"function",
"for",
"formatting",
"and",
"printing",
"errors",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/log/log.go#L115-L117
|
20,977
|
rkt/rkt
|
pkg/log/log.go
|
PanicE
|
func (l *Logger) PanicE(msg string, e error) {
l.Panic(l.formatErr(e, msg))
}
|
go
|
func (l *Logger) PanicE(msg string, e error) {
l.Panic(l.formatErr(e, msg))
}
|
[
"func",
"(",
"l",
"*",
"Logger",
")",
"PanicE",
"(",
"msg",
"string",
",",
"e",
"error",
")",
"{",
"l",
".",
"Panic",
"(",
"l",
".",
"formatErr",
"(",
"e",
",",
"msg",
")",
")",
"\n",
"}"
] |
// PanicE prints a string and error then calls panic.
|
[
"PanicE",
"prints",
"a",
"string",
"and",
"error",
"then",
"calls",
"panic",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/log/log.go#L132-L134
|
20,978
|
rkt/rkt
|
tools/common/util.go
|
Warn
|
func Warn(format string, values ...interface{}) {
fmt.Fprintf(os.Stderr, fmt.Sprintf("%s%c", format, '\n'), values...)
}
|
go
|
func Warn(format string, values ...interface{}) {
fmt.Fprintf(os.Stderr, fmt.Sprintf("%s%c", format, '\n'), values...)
}
|
[
"func",
"Warn",
"(",
"format",
"string",
",",
"values",
"...",
"interface",
"{",
"}",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"format",
",",
"'\\n'",
")",
",",
"values",
"...",
")",
"\n",
"}"
] |
// Warn is just a shorter version of a formatted printing to
// stderr. It appends a newline for you.
|
[
"Warn",
"is",
"just",
"a",
"shorter",
"version",
"of",
"a",
"formatted",
"printing",
"to",
"stderr",
".",
"It",
"appends",
"a",
"newline",
"for",
"you",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/common/util.go#L45-L47
|
20,979
|
rkt/rkt
|
tools/common/util.go
|
MustAbs
|
func MustAbs(dir string) string {
absDir, err := filepath.Abs(dir)
if err != nil {
panic(fmt.Sprintf("Failed to get absolute path of a directory %q: %v\n", dir, err))
}
return filepath.Clean(absDir)
}
|
go
|
func MustAbs(dir string) string {
absDir, err := filepath.Abs(dir)
if err != nil {
panic(fmt.Sprintf("Failed to get absolute path of a directory %q: %v\n", dir, err))
}
return filepath.Clean(absDir)
}
|
[
"func",
"MustAbs",
"(",
"dir",
"string",
")",
"string",
"{",
"absDir",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"dir",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"return",
"filepath",
".",
"Clean",
"(",
"absDir",
")",
"\n",
"}"
] |
// MustAbs returns an absolute path. It works like filepath.Abs, but
// panics if it fails.
|
[
"MustAbs",
"returns",
"an",
"absolute",
"path",
".",
"It",
"works",
"like",
"filepath",
".",
"Abs",
"but",
"panics",
"if",
"it",
"fails",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/tools/common/util.go#L75-L81
|
20,980
|
rkt/rkt
|
rkt/status.go
|
parseDuration
|
func parseDuration(s string) (time.Duration, error) {
if s == "" {
return time.Duration(-1), nil
}
b, err := strconv.ParseBool(s)
switch {
case err != nil:
return time.ParseDuration(s)
case b:
return time.Duration(-1), nil
}
return time.Duration(0), nil
}
|
go
|
func parseDuration(s string) (time.Duration, error) {
if s == "" {
return time.Duration(-1), nil
}
b, err := strconv.ParseBool(s)
switch {
case err != nil:
return time.ParseDuration(s)
case b:
return time.Duration(-1), nil
}
return time.Duration(0), nil
}
|
[
"func",
"parseDuration",
"(",
"s",
"string",
")",
"(",
"time",
".",
"Duration",
",",
"error",
")",
"{",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"time",
".",
"Duration",
"(",
"-",
"1",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"b",
",",
"err",
":=",
"strconv",
".",
"ParseBool",
"(",
"s",
")",
"\n\n",
"switch",
"{",
"case",
"err",
"!=",
"nil",
":",
"return",
"time",
".",
"ParseDuration",
"(",
"s",
")",
"\n",
"case",
"b",
":",
"return",
"time",
".",
"Duration",
"(",
"-",
"1",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"time",
".",
"Duration",
"(",
"0",
")",
",",
"nil",
"\n",
"}"
] |
// parseDuration converts the given string s to a duration value.
// If it is empty string or a true boolean value according to strconv.ParseBool, a negative duration is returned.
// If the boolean value is false, a 0 duration is returned.
// If the string s is a duration value, then it is returned.
// It returns an error if the duration conversion failed.
|
[
"parseDuration",
"converts",
"the",
"given",
"string",
"s",
"to",
"a",
"duration",
"value",
".",
"If",
"it",
"is",
"empty",
"string",
"or",
"a",
"true",
"boolean",
"value",
"according",
"to",
"strconv",
".",
"ParseBool",
"a",
"negative",
"duration",
"is",
"returned",
".",
"If",
"the",
"boolean",
"value",
"is",
"false",
"a",
"0",
"duration",
"is",
"returned",
".",
"If",
"the",
"string",
"s",
"is",
"a",
"duration",
"value",
"then",
"it",
"is",
"returned",
".",
"It",
"returns",
"an",
"error",
"if",
"the",
"duration",
"conversion",
"failed",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/status.go#L126-L141
|
20,981
|
rkt/rkt
|
rkt/status.go
|
newContext
|
func newContext(t time.Duration) context.Context {
ctx := context.Background()
if t > 0 {
ctx, _ = context.WithTimeout(ctx, t)
}
return ctx
}
|
go
|
func newContext(t time.Duration) context.Context {
ctx := context.Background()
if t > 0 {
ctx, _ = context.WithTimeout(ctx, t)
}
return ctx
}
|
[
"func",
"newContext",
"(",
"t",
"time",
".",
"Duration",
")",
"context",
".",
"Context",
"{",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n",
"if",
"t",
">",
"0",
"{",
"ctx",
",",
"_",
"=",
"context",
".",
"WithTimeout",
"(",
"ctx",
",",
"t",
")",
"\n",
"}",
"\n",
"return",
"ctx",
"\n",
"}"
] |
// newContext returns a new context with timeout t if t > 0.
|
[
"newContext",
"returns",
"a",
"new",
"context",
"with",
"timeout",
"t",
"if",
"t",
">",
"0",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/status.go#L144-L150
|
20,982
|
rkt/rkt
|
rkt/status.go
|
getExitStatuses
|
func getExitStatuses(p *pkgPod.Pod) (map[string]int, error) {
_, manifest, err := p.PodManifest()
if err != nil {
return nil, err
}
stats := make(map[string]int)
for _, app := range manifest.Apps {
exitCode, err := p.AppExitCode(app.Name.String())
if err != nil {
continue
}
stats[app.Name.String()] = exitCode
}
return stats, nil
}
|
go
|
func getExitStatuses(p *pkgPod.Pod) (map[string]int, error) {
_, manifest, err := p.PodManifest()
if err != nil {
return nil, err
}
stats := make(map[string]int)
for _, app := range manifest.Apps {
exitCode, err := p.AppExitCode(app.Name.String())
if err != nil {
continue
}
stats[app.Name.String()] = exitCode
}
return stats, nil
}
|
[
"func",
"getExitStatuses",
"(",
"p",
"*",
"pkgPod",
".",
"Pod",
")",
"(",
"map",
"[",
"string",
"]",
"int",
",",
"error",
")",
"{",
"_",
",",
"manifest",
",",
"err",
":=",
"p",
".",
"PodManifest",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"stats",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
"\n",
"for",
"_",
",",
"app",
":=",
"range",
"manifest",
".",
"Apps",
"{",
"exitCode",
",",
"err",
":=",
"p",
".",
"AppExitCode",
"(",
"app",
".",
"Name",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"stats",
"[",
"app",
".",
"Name",
".",
"String",
"(",
")",
"]",
"=",
"exitCode",
"\n",
"}",
"\n",
"return",
"stats",
",",
"nil",
"\n",
"}"
] |
// getExitStatuses returns a map of the statuses of the pod.
|
[
"getExitStatuses",
"returns",
"a",
"map",
"of",
"the",
"statuses",
"of",
"the",
"pod",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/status.go#L153-L168
|
20,983
|
rkt/rkt
|
rkt/status.go
|
printStatus
|
func printStatus(p *pkgPod.Pod) error {
if flagFormat != outputFormatTabbed {
pod, err := lib.NewPodFromInternalPod(p)
if err != nil {
return fmt.Errorf("error converting pod: %v", err)
}
switch flagFormat {
case outputFormatJSON:
result, err := json.Marshal(pod)
if err != nil {
return fmt.Errorf("error marshaling the pod: %v", err)
}
stdout.Print(string(result))
case outputFormatPrettyJSON:
result, err := json.MarshalIndent(pod, "", "\t")
if err != nil {
return fmt.Errorf("error marshaling the pod: %v", err)
}
stdout.Print(string(result))
}
return nil
}
state := p.State()
stdout.Printf("state=%s", state)
created, err := p.CreationTime()
if err != nil {
return fmt.Errorf("unable to get creation time for pod %q: %v", p.UUID, err)
}
createdStr := created.Format(defaultTimeLayout)
stdout.Printf("created=%s", createdStr)
started, err := p.StartTime()
if err != nil {
return fmt.Errorf("unable to get start time for pod %q: %v", p.UUID, err)
}
var startedStr string
if !started.IsZero() {
startedStr = started.Format(defaultTimeLayout)
stdout.Printf("started=%s", startedStr)
}
if state == pkgPod.Running || state == pkgPod.Exited {
stdout.Printf("networks=%s", fmtNets(p.Nets))
}
if !(state == pkgPod.Running || state == pkgPod.Deleting || state == pkgPod.ExitedDeleting || state == pkgPod.Exited || state == pkgPod.ExitedGarbage) {
return nil
}
if pid, err := p.Pid(); err == nil {
// the pid file might not be written yet when the state changes to 'Running'
// it may also never be written if systemd never executes (e.g.: a bad command)
stdout.Printf("pid=%d", pid)
}
stdout.Printf("exited=%t", (state == pkgPod.Exited || state == pkgPod.ExitedGarbage))
if state != pkgPod.Running {
stats, err := getExitStatuses(p)
if err != nil {
return fmt.Errorf("unable to get exit statuses for pod %q: %v", p.UUID, err)
}
for app, stat := range stats {
stdout.Printf("app-%s=%d", app, stat)
}
}
return nil
}
|
go
|
func printStatus(p *pkgPod.Pod) error {
if flagFormat != outputFormatTabbed {
pod, err := lib.NewPodFromInternalPod(p)
if err != nil {
return fmt.Errorf("error converting pod: %v", err)
}
switch flagFormat {
case outputFormatJSON:
result, err := json.Marshal(pod)
if err != nil {
return fmt.Errorf("error marshaling the pod: %v", err)
}
stdout.Print(string(result))
case outputFormatPrettyJSON:
result, err := json.MarshalIndent(pod, "", "\t")
if err != nil {
return fmt.Errorf("error marshaling the pod: %v", err)
}
stdout.Print(string(result))
}
return nil
}
state := p.State()
stdout.Printf("state=%s", state)
created, err := p.CreationTime()
if err != nil {
return fmt.Errorf("unable to get creation time for pod %q: %v", p.UUID, err)
}
createdStr := created.Format(defaultTimeLayout)
stdout.Printf("created=%s", createdStr)
started, err := p.StartTime()
if err != nil {
return fmt.Errorf("unable to get start time for pod %q: %v", p.UUID, err)
}
var startedStr string
if !started.IsZero() {
startedStr = started.Format(defaultTimeLayout)
stdout.Printf("started=%s", startedStr)
}
if state == pkgPod.Running || state == pkgPod.Exited {
stdout.Printf("networks=%s", fmtNets(p.Nets))
}
if !(state == pkgPod.Running || state == pkgPod.Deleting || state == pkgPod.ExitedDeleting || state == pkgPod.Exited || state == pkgPod.ExitedGarbage) {
return nil
}
if pid, err := p.Pid(); err == nil {
// the pid file might not be written yet when the state changes to 'Running'
// it may also never be written if systemd never executes (e.g.: a bad command)
stdout.Printf("pid=%d", pid)
}
stdout.Printf("exited=%t", (state == pkgPod.Exited || state == pkgPod.ExitedGarbage))
if state != pkgPod.Running {
stats, err := getExitStatuses(p)
if err != nil {
return fmt.Errorf("unable to get exit statuses for pod %q: %v", p.UUID, err)
}
for app, stat := range stats {
stdout.Printf("app-%s=%d", app, stat)
}
}
return nil
}
|
[
"func",
"printStatus",
"(",
"p",
"*",
"pkgPod",
".",
"Pod",
")",
"error",
"{",
"if",
"flagFormat",
"!=",
"outputFormatTabbed",
"{",
"pod",
",",
"err",
":=",
"lib",
".",
"NewPodFromInternalPod",
"(",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"switch",
"flagFormat",
"{",
"case",
"outputFormatJSON",
":",
"result",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"pod",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"stdout",
".",
"Print",
"(",
"string",
"(",
"result",
")",
")",
"\n",
"case",
"outputFormatPrettyJSON",
":",
"result",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"pod",
",",
"\"",
"\"",
",",
"\"",
"\\t",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"stdout",
".",
"Print",
"(",
"string",
"(",
"result",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"state",
":=",
"p",
".",
"State",
"(",
")",
"\n",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
",",
"state",
")",
"\n\n",
"created",
",",
"err",
":=",
"p",
".",
"CreationTime",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
".",
"UUID",
",",
"err",
")",
"\n",
"}",
"\n",
"createdStr",
":=",
"created",
".",
"Format",
"(",
"defaultTimeLayout",
")",
"\n\n",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
",",
"createdStr",
")",
"\n\n",
"started",
",",
"err",
":=",
"p",
".",
"StartTime",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
".",
"UUID",
",",
"err",
")",
"\n",
"}",
"\n",
"var",
"startedStr",
"string",
"\n",
"if",
"!",
"started",
".",
"IsZero",
"(",
")",
"{",
"startedStr",
"=",
"started",
".",
"Format",
"(",
"defaultTimeLayout",
")",
"\n",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
",",
"startedStr",
")",
"\n",
"}",
"\n\n",
"if",
"state",
"==",
"pkgPod",
".",
"Running",
"||",
"state",
"==",
"pkgPod",
".",
"Exited",
"{",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
",",
"fmtNets",
"(",
"p",
".",
"Nets",
")",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"(",
"state",
"==",
"pkgPod",
".",
"Running",
"||",
"state",
"==",
"pkgPod",
".",
"Deleting",
"||",
"state",
"==",
"pkgPod",
".",
"ExitedDeleting",
"||",
"state",
"==",
"pkgPod",
".",
"Exited",
"||",
"state",
"==",
"pkgPod",
".",
"ExitedGarbage",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"pid",
",",
"err",
":=",
"p",
".",
"Pid",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"// the pid file might not be written yet when the state changes to 'Running'",
"// it may also never be written if systemd never executes (e.g.: a bad command)",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
",",
"pid",
")",
"\n",
"}",
"\n",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
",",
"(",
"state",
"==",
"pkgPod",
".",
"Exited",
"||",
"state",
"==",
"pkgPod",
".",
"ExitedGarbage",
")",
")",
"\n\n",
"if",
"state",
"!=",
"pkgPod",
".",
"Running",
"{",
"stats",
",",
"err",
":=",
"getExitStatuses",
"(",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
".",
"UUID",
",",
"err",
")",
"\n",
"}",
"\n",
"for",
"app",
",",
"stat",
":=",
"range",
"stats",
"{",
"stdout",
".",
"Printf",
"(",
"\"",
"\"",
",",
"app",
",",
"stat",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// printStatus prints the pod's pid and per-app status codes
|
[
"printStatus",
"prints",
"the",
"pod",
"s",
"pid",
"and",
"per",
"-",
"app",
"status",
"codes"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/status.go#L171-L240
|
20,984
|
rkt/rkt
|
rkt/image/common.go
|
ascURLFromImgURL
|
func ascURLFromImgURL(u *url.URL) *url.URL {
copy := *u
copy.Path = ascPathFromImgPath(copy.Path)
return ©
}
|
go
|
func ascURLFromImgURL(u *url.URL) *url.URL {
copy := *u
copy.Path = ascPathFromImgPath(copy.Path)
return ©
}
|
[
"func",
"ascURLFromImgURL",
"(",
"u",
"*",
"url",
".",
"URL",
")",
"*",
"url",
".",
"URL",
"{",
"copy",
":=",
"*",
"u",
"\n",
"copy",
".",
"Path",
"=",
"ascPathFromImgPath",
"(",
"copy",
".",
"Path",
")",
"\n",
"return",
"&",
"copy",
"\n",
"}"
] |
// ascURLFromImgURL creates a URL to a signature file from passed URL
// to an image.
|
[
"ascURLFromImgURL",
"creates",
"a",
"URL",
"to",
"a",
"signature",
"file",
"from",
"passed",
"URL",
"to",
"an",
"image",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/common.go#L113-L117
|
20,985
|
rkt/rkt
|
rkt/image/common.go
|
printIdentities
|
func printIdentities(entity *openpgp.Entity) {
lines := []string{"signature verified:"}
for _, v := range entity.Identities {
lines = append(lines, fmt.Sprintf(" %s", v.Name))
}
log.Print(strings.Join(lines, "\n"))
}
|
go
|
func printIdentities(entity *openpgp.Entity) {
lines := []string{"signature verified:"}
for _, v := range entity.Identities {
lines = append(lines, fmt.Sprintf(" %s", v.Name))
}
log.Print(strings.Join(lines, "\n"))
}
|
[
"func",
"printIdentities",
"(",
"entity",
"*",
"openpgp",
".",
"Entity",
")",
"{",
"lines",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"entity",
".",
"Identities",
"{",
"lines",
"=",
"append",
"(",
"lines",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"v",
".",
"Name",
")",
")",
"\n",
"}",
"\n",
"log",
".",
"Print",
"(",
"strings",
".",
"Join",
"(",
"lines",
",",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"}"
] |
// printIdentities prints a message that signature was verified.
|
[
"printIdentities",
"prints",
"a",
"message",
"that",
"signature",
"was",
"verified",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/common.go#L126-L132
|
20,986
|
rkt/rkt
|
rkt/image/common.go
|
DistFromImageString
|
func DistFromImageString(is string) (dist.Distribution, error) {
u, err := url.Parse(is)
if err != nil {
return nil, errwrap.Wrap(fmt.Errorf("failed to parse image url %q", is), err)
}
// Convert user friendly image string names to internal distribution URIs
// file:///full/path/to/aci/file.aci -> archive:aci:file%3A%2F%2F%2Ffull%2Fpath%2Fto%2Faci%2Ffile.aci
switch u.Scheme {
case "":
// no scheme given, hence it is an appc image name or path
appImageType := guessAppcOrPath(is, []string{schema.ACIExtension})
switch appImageType {
case imageStringName:
app, err := discovery.NewAppFromString(is)
if err != nil {
return nil, fmt.Errorf("invalid appc image string %q: %v", is, err)
}
return dist.NewAppcFromApp(app), nil
case imageStringPath:
absPath, err := filepath.Abs(is)
if err != nil {
return nil, errwrap.Wrap(fmt.Errorf("failed to get an absolute path for %q", is), err)
}
is = "file://" + absPath
// given a file:// image string, call this function again to return an ACI distribution
return DistFromImageString(is)
default:
return nil, fmt.Errorf("invalid image string type %q", appImageType)
}
case "file", "http", "https":
// An ACI archive with any transport type (file, http, s3 etc...) and final aci extension
if filepath.Ext(u.Path) == schema.ACIExtension {
dist, err := dist.NewACIArchiveFromTransportURL(u)
if err != nil {
return nil, fmt.Errorf("archive distribution creation error: %v", err)
}
return dist, nil
}
case "docker":
// Accept both docker: and docker:// uri
dockerStr := is
if strings.HasPrefix(dockerStr, "docker://") {
dockerStr = strings.TrimPrefix(dockerStr, "docker://")
} else if strings.HasPrefix(dockerStr, "docker:") {
dockerStr = strings.TrimPrefix(dockerStr, "docker:")
}
dist, err := dist.NewDockerFromString(dockerStr)
if err != nil {
return nil, fmt.Errorf("docker distribution creation error: %v", err)
}
return dist, nil
case dist.Scheme: // cimd
return dist.Parse(is)
default:
// any other scheme is a an appc image name, i.e. "my-app:v1.0"
app, err := discovery.NewAppFromString(is)
if err != nil {
return nil, fmt.Errorf("invalid appc image string %q: %v", is, err)
}
return dist.NewAppcFromApp(app), nil
}
return nil, fmt.Errorf("invalid image string %q", is)
}
|
go
|
func DistFromImageString(is string) (dist.Distribution, error) {
u, err := url.Parse(is)
if err != nil {
return nil, errwrap.Wrap(fmt.Errorf("failed to parse image url %q", is), err)
}
// Convert user friendly image string names to internal distribution URIs
// file:///full/path/to/aci/file.aci -> archive:aci:file%3A%2F%2F%2Ffull%2Fpath%2Fto%2Faci%2Ffile.aci
switch u.Scheme {
case "":
// no scheme given, hence it is an appc image name or path
appImageType := guessAppcOrPath(is, []string{schema.ACIExtension})
switch appImageType {
case imageStringName:
app, err := discovery.NewAppFromString(is)
if err != nil {
return nil, fmt.Errorf("invalid appc image string %q: %v", is, err)
}
return dist.NewAppcFromApp(app), nil
case imageStringPath:
absPath, err := filepath.Abs(is)
if err != nil {
return nil, errwrap.Wrap(fmt.Errorf("failed to get an absolute path for %q", is), err)
}
is = "file://" + absPath
// given a file:// image string, call this function again to return an ACI distribution
return DistFromImageString(is)
default:
return nil, fmt.Errorf("invalid image string type %q", appImageType)
}
case "file", "http", "https":
// An ACI archive with any transport type (file, http, s3 etc...) and final aci extension
if filepath.Ext(u.Path) == schema.ACIExtension {
dist, err := dist.NewACIArchiveFromTransportURL(u)
if err != nil {
return nil, fmt.Errorf("archive distribution creation error: %v", err)
}
return dist, nil
}
case "docker":
// Accept both docker: and docker:// uri
dockerStr := is
if strings.HasPrefix(dockerStr, "docker://") {
dockerStr = strings.TrimPrefix(dockerStr, "docker://")
} else if strings.HasPrefix(dockerStr, "docker:") {
dockerStr = strings.TrimPrefix(dockerStr, "docker:")
}
dist, err := dist.NewDockerFromString(dockerStr)
if err != nil {
return nil, fmt.Errorf("docker distribution creation error: %v", err)
}
return dist, nil
case dist.Scheme: // cimd
return dist.Parse(is)
default:
// any other scheme is a an appc image name, i.e. "my-app:v1.0"
app, err := discovery.NewAppFromString(is)
if err != nil {
return nil, fmt.Errorf("invalid appc image string %q: %v", is, err)
}
return dist.NewAppcFromApp(app), nil
}
return nil, fmt.Errorf("invalid image string %q", is)
}
|
[
"func",
"DistFromImageString",
"(",
"is",
"string",
")",
"(",
"dist",
".",
"Distribution",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"is",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"is",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Convert user friendly image string names to internal distribution URIs",
"// file:///full/path/to/aci/file.aci -> archive:aci:file%3A%2F%2F%2Ffull%2Fpath%2Fto%2Faci%2Ffile.aci",
"switch",
"u",
".",
"Scheme",
"{",
"case",
"\"",
"\"",
":",
"// no scheme given, hence it is an appc image name or path",
"appImageType",
":=",
"guessAppcOrPath",
"(",
"is",
",",
"[",
"]",
"string",
"{",
"schema",
".",
"ACIExtension",
"}",
")",
"\n\n",
"switch",
"appImageType",
"{",
"case",
"imageStringName",
":",
"app",
",",
"err",
":=",
"discovery",
".",
"NewAppFromString",
"(",
"is",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"is",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"dist",
".",
"NewAppcFromApp",
"(",
"app",
")",
",",
"nil",
"\n",
"case",
"imageStringPath",
":",
"absPath",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"is",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"is",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"is",
"=",
"\"",
"\"",
"+",
"absPath",
"\n\n",
"// given a file:// image string, call this function again to return an ACI distribution",
"return",
"DistFromImageString",
"(",
"is",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"appImageType",
")",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"// An ACI archive with any transport type (file, http, s3 etc...) and final aci extension",
"if",
"filepath",
".",
"Ext",
"(",
"u",
".",
"Path",
")",
"==",
"schema",
".",
"ACIExtension",
"{",
"dist",
",",
"err",
":=",
"dist",
".",
"NewACIArchiveFromTransportURL",
"(",
"u",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"dist",
",",
"nil",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"// Accept both docker: and docker:// uri",
"dockerStr",
":=",
"is",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"dockerStr",
",",
"\"",
"\"",
")",
"{",
"dockerStr",
"=",
"strings",
".",
"TrimPrefix",
"(",
"dockerStr",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"strings",
".",
"HasPrefix",
"(",
"dockerStr",
",",
"\"",
"\"",
")",
"{",
"dockerStr",
"=",
"strings",
".",
"TrimPrefix",
"(",
"dockerStr",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"dist",
",",
"err",
":=",
"dist",
".",
"NewDockerFromString",
"(",
"dockerStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"dist",
",",
"nil",
"\n",
"case",
"dist",
".",
"Scheme",
":",
"// cimd",
"return",
"dist",
".",
"Parse",
"(",
"is",
")",
"\n",
"default",
":",
"// any other scheme is a an appc image name, i.e. \"my-app:v1.0\"",
"app",
",",
"err",
":=",
"discovery",
".",
"NewAppFromString",
"(",
"is",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"is",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"dist",
".",
"NewAppcFromApp",
"(",
"app",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"is",
")",
"\n",
"}"
] |
// DistFromImageString return the distribution for the given input image string
|
[
"DistFromImageString",
"return",
"the",
"distribution",
"for",
"the",
"given",
"input",
"image",
"string"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/image/common.go#L135-L203
|
20,987
|
rkt/rkt
|
pkg/distribution/cimd.go
|
parseCIMD
|
func parseCIMD(u *url.URL) (*cimd, error) {
if u.Scheme != Scheme {
return nil, fmt.Errorf("unsupported scheme: %q", u.Scheme)
}
parts := strings.SplitN(u.Opaque, ":", 3)
if len(parts) < 3 {
return nil, fmt.Errorf("malformed distribution uri: %q", u.String())
}
version, err := strconv.ParseUint(strings.TrimPrefix(parts[1], "v="), 10, 32)
if err != nil {
return nil, fmt.Errorf("malformed distribution version: %s", parts[1])
}
return &cimd{
Type: Type(parts[0]),
Version: uint32(version),
Data: parts[2],
}, nil
}
|
go
|
func parseCIMD(u *url.URL) (*cimd, error) {
if u.Scheme != Scheme {
return nil, fmt.Errorf("unsupported scheme: %q", u.Scheme)
}
parts := strings.SplitN(u.Opaque, ":", 3)
if len(parts) < 3 {
return nil, fmt.Errorf("malformed distribution uri: %q", u.String())
}
version, err := strconv.ParseUint(strings.TrimPrefix(parts[1], "v="), 10, 32)
if err != nil {
return nil, fmt.Errorf("malformed distribution version: %s", parts[1])
}
return &cimd{
Type: Type(parts[0]),
Version: uint32(version),
Data: parts[2],
}, nil
}
|
[
"func",
"parseCIMD",
"(",
"u",
"*",
"url",
".",
"URL",
")",
"(",
"*",
"cimd",
",",
"error",
")",
"{",
"if",
"u",
".",
"Scheme",
"!=",
"Scheme",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"u",
".",
"Scheme",
")",
"\n",
"}",
"\n",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"u",
".",
"Opaque",
",",
"\"",
"\"",
",",
"3",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"<",
"3",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"u",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"version",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"strings",
".",
"TrimPrefix",
"(",
"parts",
"[",
"1",
"]",
",",
"\"",
"\"",
")",
",",
"10",
",",
"32",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"parts",
"[",
"1",
"]",
")",
"\n",
"}",
"\n",
"return",
"&",
"cimd",
"{",
"Type",
":",
"Type",
"(",
"parts",
"[",
"0",
"]",
")",
",",
"Version",
":",
"uint32",
"(",
"version",
")",
",",
"Data",
":",
"parts",
"[",
"2",
"]",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// parseCIMD parses the given url and returns a cimd.
|
[
"parseCIMD",
"parses",
"the",
"given",
"url",
"and",
"returns",
"a",
"cimd",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/distribution/cimd.go#L34-L51
|
20,988
|
rkt/rkt
|
pkg/distribution/cimd.go
|
NewCIMDString
|
func NewCIMDString(typ Type, version uint32, data string) string {
return fmt.Sprintf("%s:%s:v=%d:%s", Scheme, typ, version, data)
}
|
go
|
func NewCIMDString(typ Type, version uint32, data string) string {
return fmt.Sprintf("%s:%s:v=%d:%s", Scheme, typ, version, data)
}
|
[
"func",
"NewCIMDString",
"(",
"typ",
"Type",
",",
"version",
"uint32",
",",
"data",
"string",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"Scheme",
",",
"typ",
",",
"version",
",",
"data",
")",
"\n",
"}"
] |
// NewCIMDString creates a new cimd URL string.
|
[
"NewCIMDString",
"creates",
"a",
"new",
"cimd",
"URL",
"string",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/pkg/distribution/cimd.go#L54-L56
|
20,989
|
rkt/rkt
|
rkt/export.go
|
getApp
|
func getApp(p *pkgPod.Pod) (*schema.RuntimeApp, error) {
_, manifest, err := p.PodManifest()
if err != nil {
return nil, errwrap.Wrap(errors.New("problem getting the pod's manifest"), err)
}
apps := manifest.Apps
if flagExportAppName != "" {
exportAppName, err := types.NewACName(flagExportAppName)
if err != nil {
return nil, err
}
for _, ra := range apps {
if *exportAppName == ra.Name {
return &ra, nil
}
}
return nil, fmt.Errorf("app %s is not present in pod", flagExportAppName)
}
switch len(apps) {
case 0:
return nil, fmt.Errorf("pod contains zero apps")
case 1:
return &apps[0], nil
default:
}
stderr.Print("pod contains multiple apps:")
for _, ra := range apps {
stderr.Printf("\t%v", ra.Name)
}
return nil, fmt.Errorf("specify app using \"rkt export --app= ...\"")
}
|
go
|
func getApp(p *pkgPod.Pod) (*schema.RuntimeApp, error) {
_, manifest, err := p.PodManifest()
if err != nil {
return nil, errwrap.Wrap(errors.New("problem getting the pod's manifest"), err)
}
apps := manifest.Apps
if flagExportAppName != "" {
exportAppName, err := types.NewACName(flagExportAppName)
if err != nil {
return nil, err
}
for _, ra := range apps {
if *exportAppName == ra.Name {
return &ra, nil
}
}
return nil, fmt.Errorf("app %s is not present in pod", flagExportAppName)
}
switch len(apps) {
case 0:
return nil, fmt.Errorf("pod contains zero apps")
case 1:
return &apps[0], nil
default:
}
stderr.Print("pod contains multiple apps:")
for _, ra := range apps {
stderr.Printf("\t%v", ra.Name)
}
return nil, fmt.Errorf("specify app using \"rkt export --app= ...\"")
}
|
[
"func",
"getApp",
"(",
"p",
"*",
"pkgPod",
".",
"Pod",
")",
"(",
"*",
"schema",
".",
"RuntimeApp",
",",
"error",
")",
"{",
"_",
",",
"manifest",
",",
"err",
":=",
"p",
".",
"PodManifest",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"apps",
":=",
"manifest",
".",
"Apps",
"\n\n",
"if",
"flagExportAppName",
"!=",
"\"",
"\"",
"{",
"exportAppName",
",",
"err",
":=",
"types",
".",
"NewACName",
"(",
"flagExportAppName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"ra",
":=",
"range",
"apps",
"{",
"if",
"*",
"exportAppName",
"==",
"ra",
".",
"Name",
"{",
"return",
"&",
"ra",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"flagExportAppName",
")",
"\n",
"}",
"\n\n",
"switch",
"len",
"(",
"apps",
")",
"{",
"case",
"0",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"1",
":",
"return",
"&",
"apps",
"[",
"0",
"]",
",",
"nil",
"\n",
"default",
":",
"}",
"\n\n",
"stderr",
".",
"Print",
"(",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"ra",
":=",
"range",
"apps",
"{",
"stderr",
".",
"Printf",
"(",
"\"",
"\\t",
"\"",
",",
"ra",
".",
"Name",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
")",
"\n",
"}"
] |
// getApp returns the app to export
// If one was supplied in the flags then it's returned if present
// If the PM contains a single app, that app is returned
// If the PM has multiple apps, the names are printed and an error is returned
|
[
"getApp",
"returns",
"the",
"app",
"to",
"export",
"If",
"one",
"was",
"supplied",
"in",
"the",
"flags",
"then",
"it",
"s",
"returned",
"if",
"present",
"If",
"the",
"PM",
"contains",
"a",
"single",
"app",
"that",
"app",
"is",
"returned",
"If",
"the",
"PM",
"has",
"multiple",
"apps",
"the",
"names",
"are",
"printed",
"and",
"an",
"error",
"is",
"returned"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/export.go#L164-L199
|
20,990
|
rkt/rkt
|
rkt/export.go
|
mountOverlay
|
func mountOverlay(pod *pkgPod.Pod, app *schema.RuntimeApp, dest string) error {
if _, err := os.Stat(dest); err != nil {
return err
}
s, err := imagestore.NewStore(getDataDir())
if err != nil {
return errwrap.Wrap(errors.New("cannot open store"), err)
}
ts, err := treestore.NewStore(treeStoreDir(), s)
if err != nil {
return errwrap.Wrap(errors.New("cannot open treestore"), err)
}
treeStoreID, err := pod.GetAppTreeStoreID(app.Name)
if err != nil {
return err
}
lower := ts.GetRootFS(treeStoreID)
imgDir := filepath.Join(filepath.Join(pod.Path(), "overlay"), treeStoreID)
if _, err := os.Stat(imgDir); err != nil {
return err
}
upper := filepath.Join(imgDir, "upper", app.Name.String())
if _, err := os.Stat(upper); err != nil {
return err
}
work := filepath.Join(imgDir, "work", app.Name.String())
if _, err := os.Stat(work); err != nil {
return err
}
if err := overlay.Mount(&overlay.MountCfg{lower, upper, work, dest, ""}); err != nil {
return errwrap.Wrap(errors.New("problem mounting overlayfs directory"), err)
}
return nil
}
|
go
|
func mountOverlay(pod *pkgPod.Pod, app *schema.RuntimeApp, dest string) error {
if _, err := os.Stat(dest); err != nil {
return err
}
s, err := imagestore.NewStore(getDataDir())
if err != nil {
return errwrap.Wrap(errors.New("cannot open store"), err)
}
ts, err := treestore.NewStore(treeStoreDir(), s)
if err != nil {
return errwrap.Wrap(errors.New("cannot open treestore"), err)
}
treeStoreID, err := pod.GetAppTreeStoreID(app.Name)
if err != nil {
return err
}
lower := ts.GetRootFS(treeStoreID)
imgDir := filepath.Join(filepath.Join(pod.Path(), "overlay"), treeStoreID)
if _, err := os.Stat(imgDir); err != nil {
return err
}
upper := filepath.Join(imgDir, "upper", app.Name.String())
if _, err := os.Stat(upper); err != nil {
return err
}
work := filepath.Join(imgDir, "work", app.Name.String())
if _, err := os.Stat(work); err != nil {
return err
}
if err := overlay.Mount(&overlay.MountCfg{lower, upper, work, dest, ""}); err != nil {
return errwrap.Wrap(errors.New("problem mounting overlayfs directory"), err)
}
return nil
}
|
[
"func",
"mountOverlay",
"(",
"pod",
"*",
"pkgPod",
".",
"Pod",
",",
"app",
"*",
"schema",
".",
"RuntimeApp",
",",
"dest",
"string",
")",
"error",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"dest",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"s",
",",
"err",
":=",
"imagestore",
".",
"NewStore",
"(",
"getDataDir",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"ts",
",",
"err",
":=",
"treestore",
".",
"NewStore",
"(",
"treeStoreDir",
"(",
")",
",",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"treeStoreID",
",",
"err",
":=",
"pod",
".",
"GetAppTreeStoreID",
"(",
"app",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"lower",
":=",
"ts",
".",
"GetRootFS",
"(",
"treeStoreID",
")",
"\n",
"imgDir",
":=",
"filepath",
".",
"Join",
"(",
"filepath",
".",
"Join",
"(",
"pod",
".",
"Path",
"(",
")",
",",
"\"",
"\"",
")",
",",
"treeStoreID",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"imgDir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"upper",
":=",
"filepath",
".",
"Join",
"(",
"imgDir",
",",
"\"",
"\"",
",",
"app",
".",
"Name",
".",
"String",
"(",
")",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"upper",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"work",
":=",
"filepath",
".",
"Join",
"(",
"imgDir",
",",
"\"",
"\"",
",",
"app",
".",
"Name",
".",
"String",
"(",
")",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"work",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"overlay",
".",
"Mount",
"(",
"&",
"overlay",
".",
"MountCfg",
"{",
"lower",
",",
"upper",
",",
"work",
",",
"dest",
",",
"\"",
"\"",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// mountOverlay mounts the app from the overlay-rendered pod to the destination directory.
|
[
"mountOverlay",
"mounts",
"the",
"app",
"from",
"the",
"overlay",
"-",
"rendered",
"pod",
"to",
"the",
"destination",
"directory",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/export.go#L202-L240
|
20,991
|
rkt/rkt
|
rkt/export.go
|
buildAci
|
func buildAci(root, manifestPath, target string, uidRange *user.UidRange) (e error) {
mode := os.O_CREATE | os.O_WRONLY
if flagOverwriteACI {
mode |= os.O_TRUNC
} else {
mode |= os.O_EXCL
}
aciFile, err := os.OpenFile(target, mode, 0644)
if err != nil {
if os.IsExist(err) {
return errors.New("target file exists (try --overwrite)")
} else {
return errwrap.Wrap(fmt.Errorf("unable to open target %s", target), err)
}
}
gw := gzip.NewWriter(aciFile)
tr := tar.NewWriter(gw)
defer func() {
tr.Close()
gw.Close()
aciFile.Close()
// e is implicitly assigned by the return statement. As defer runs
// after return, but before actually returning, this works.
if e != nil {
os.Remove(target)
}
}()
b, err := ioutil.ReadFile(manifestPath)
if err != nil {
return errwrap.Wrap(errors.New("unable to read Image Manifest"), err)
}
var im schema.ImageManifest
if err := im.UnmarshalJSON(b); err != nil {
return errwrap.Wrap(errors.New("unable to load Image Manifest"), err)
}
iw := aci.NewImageWriter(im, tr)
// Unshift uid and gid when pod was started with --private-user (user namespace)
var walkerCb aci.TarHeaderWalkFunc = func(hdr *tar.Header) bool {
if uidRange != nil {
uid, gid, err := uidRange.UnshiftRange(uint32(hdr.Uid), uint32(hdr.Gid))
if err != nil {
stderr.PrintE("error unshifting gid and uid", err)
return false
}
hdr.Uid, hdr.Gid = int(uid), int(gid)
}
return true
}
if err := filepath.Walk(root, aci.BuildWalker(root, iw, walkerCb)); err != nil {
return errwrap.Wrap(errors.New("error walking rootfs"), err)
}
if err = iw.Close(); err != nil {
return errwrap.Wrap(fmt.Errorf("unable to close image %s", target), err)
}
return
}
|
go
|
func buildAci(root, manifestPath, target string, uidRange *user.UidRange) (e error) {
mode := os.O_CREATE | os.O_WRONLY
if flagOverwriteACI {
mode |= os.O_TRUNC
} else {
mode |= os.O_EXCL
}
aciFile, err := os.OpenFile(target, mode, 0644)
if err != nil {
if os.IsExist(err) {
return errors.New("target file exists (try --overwrite)")
} else {
return errwrap.Wrap(fmt.Errorf("unable to open target %s", target), err)
}
}
gw := gzip.NewWriter(aciFile)
tr := tar.NewWriter(gw)
defer func() {
tr.Close()
gw.Close()
aciFile.Close()
// e is implicitly assigned by the return statement. As defer runs
// after return, but before actually returning, this works.
if e != nil {
os.Remove(target)
}
}()
b, err := ioutil.ReadFile(manifestPath)
if err != nil {
return errwrap.Wrap(errors.New("unable to read Image Manifest"), err)
}
var im schema.ImageManifest
if err := im.UnmarshalJSON(b); err != nil {
return errwrap.Wrap(errors.New("unable to load Image Manifest"), err)
}
iw := aci.NewImageWriter(im, tr)
// Unshift uid and gid when pod was started with --private-user (user namespace)
var walkerCb aci.TarHeaderWalkFunc = func(hdr *tar.Header) bool {
if uidRange != nil {
uid, gid, err := uidRange.UnshiftRange(uint32(hdr.Uid), uint32(hdr.Gid))
if err != nil {
stderr.PrintE("error unshifting gid and uid", err)
return false
}
hdr.Uid, hdr.Gid = int(uid), int(gid)
}
return true
}
if err := filepath.Walk(root, aci.BuildWalker(root, iw, walkerCb)); err != nil {
return errwrap.Wrap(errors.New("error walking rootfs"), err)
}
if err = iw.Close(); err != nil {
return errwrap.Wrap(fmt.Errorf("unable to close image %s", target), err)
}
return
}
|
[
"func",
"buildAci",
"(",
"root",
",",
"manifestPath",
",",
"target",
"string",
",",
"uidRange",
"*",
"user",
".",
"UidRange",
")",
"(",
"e",
"error",
")",
"{",
"mode",
":=",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_WRONLY",
"\n",
"if",
"flagOverwriteACI",
"{",
"mode",
"|=",
"os",
".",
"O_TRUNC",
"\n",
"}",
"else",
"{",
"mode",
"|=",
"os",
".",
"O_EXCL",
"\n",
"}",
"\n",
"aciFile",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"target",
",",
"mode",
",",
"0644",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"os",
".",
"IsExist",
"(",
"err",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"target",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"gw",
":=",
"gzip",
".",
"NewWriter",
"(",
"aciFile",
")",
"\n",
"tr",
":=",
"tar",
".",
"NewWriter",
"(",
"gw",
")",
"\n\n",
"defer",
"func",
"(",
")",
"{",
"tr",
".",
"Close",
"(",
")",
"\n",
"gw",
".",
"Close",
"(",
")",
"\n",
"aciFile",
".",
"Close",
"(",
")",
"\n",
"// e is implicitly assigned by the return statement. As defer runs",
"// after return, but before actually returning, this works.",
"if",
"e",
"!=",
"nil",
"{",
"os",
".",
"Remove",
"(",
"target",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"manifestPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"var",
"im",
"schema",
".",
"ImageManifest",
"\n",
"if",
"err",
":=",
"im",
".",
"UnmarshalJSON",
"(",
"b",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"iw",
":=",
"aci",
".",
"NewImageWriter",
"(",
"im",
",",
"tr",
")",
"\n\n",
"// Unshift uid and gid when pod was started with --private-user (user namespace)",
"var",
"walkerCb",
"aci",
".",
"TarHeaderWalkFunc",
"=",
"func",
"(",
"hdr",
"*",
"tar",
".",
"Header",
")",
"bool",
"{",
"if",
"uidRange",
"!=",
"nil",
"{",
"uid",
",",
"gid",
",",
"err",
":=",
"uidRange",
".",
"UnshiftRange",
"(",
"uint32",
"(",
"hdr",
".",
"Uid",
")",
",",
"uint32",
"(",
"hdr",
".",
"Gid",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"stderr",
".",
"PrintE",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"hdr",
".",
"Uid",
",",
"hdr",
".",
"Gid",
"=",
"int",
"(",
"uid",
")",
",",
"int",
"(",
"gid",
")",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"root",
",",
"aci",
".",
"BuildWalker",
"(",
"root",
",",
"iw",
",",
"walkerCb",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"iw",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errwrap",
".",
"Wrap",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"target",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] |
// buildAci builds a target aci from the root directory using any uid shift
// information from uidRange.
|
[
"buildAci",
"builds",
"a",
"target",
"aci",
"from",
"the",
"root",
"directory",
"using",
"any",
"uid",
"shift",
"information",
"from",
"uidRange",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/export.go#L244-L306
|
20,992
|
rkt/rkt
|
rkt/rkt.go
|
ensureSuperuser
|
func ensureSuperuser(cf func(cmd *cobra.Command, args []string)) func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {
if os.Geteuid() != 0 {
stderr.Print("cannot run as unprivileged user")
cmdExitCode = 254
return
}
cf(cmd, args)
}
}
|
go
|
func ensureSuperuser(cf func(cmd *cobra.Command, args []string)) func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {
if os.Geteuid() != 0 {
stderr.Print("cannot run as unprivileged user")
cmdExitCode = 254
return
}
cf(cmd, args)
}
}
|
[
"func",
"ensureSuperuser",
"(",
"cf",
"func",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
")",
"func",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"{",
"return",
"func",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"{",
"if",
"os",
".",
"Geteuid",
"(",
")",
"!=",
"0",
"{",
"stderr",
".",
"Print",
"(",
"\"",
"\"",
")",
"\n",
"cmdExitCode",
"=",
"254",
"\n",
"return",
"\n",
"}",
"\n\n",
"cf",
"(",
"cmd",
",",
"args",
")",
"\n",
"}",
"\n",
"}"
] |
// ensureSuperuser will error out if the effective UID of the current process
// is not zero. Otherwise, it will invoke the supplied cobra command.
|
[
"ensureSuperuser",
"will",
"error",
"out",
"if",
"the",
"effective",
"UID",
"of",
"the",
"current",
"process",
"is",
"not",
"zero",
".",
"Otherwise",
"it",
"will",
"invoke",
"the",
"supplied",
"cobra",
"command",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/rkt.go#L192-L202
|
20,993
|
rkt/rkt
|
stage1/init/common/seccomp.go
|
generateSeccompFilter
|
func generateSeccompFilter(p *stage1commontypes.Pod, pa *preparedApp) (*seccompFilter, error) {
sf := seccompFilter{}
seenIsolators := 0
for _, i := range pa.app.App.Isolators {
var flag string
var err error
if seccomp, ok := i.Value().(types.LinuxSeccompSet); ok {
seenIsolators++
// By appc spec, only one seccomp isolator per app is allowed
if seenIsolators > 1 {
return nil, ErrTooManySeccompIsolators
}
switch i.Name {
case types.LinuxSeccompRemoveSetName:
sf.mode = ModeBlacklist
sf.syscalls, flag, err = parseLinuxSeccompSet(p, seccomp)
if err != nil {
return nil, err
}
if flag == "empty" {
// we interpret "remove @empty" to mean "default whitelist"
sf.mode = ModeWhitelist
sf.syscalls = RktDefaultSeccompWhitelist
}
case types.LinuxSeccompRetainSetName:
sf.mode = ModeWhitelist
sf.syscalls, flag, err = parseLinuxSeccompSet(p, seccomp)
if err != nil {
return nil, err
}
if flag == "all" {
// Opt-out seccomp filtering
return nil, nil
}
}
sf.errno = string(seccomp.Errno())
}
}
// If unset, use rkt default whitelist
if seenIsolators == 0 {
sf.mode = ModeWhitelist
sf.syscalls = RktDefaultSeccompWhitelist
}
// Non-priv apps *must* have NoNewPrivileges set if they have seccomp
sf.forceNoNewPrivileges = (pa.uid != 0)
return &sf, nil
}
|
go
|
func generateSeccompFilter(p *stage1commontypes.Pod, pa *preparedApp) (*seccompFilter, error) {
sf := seccompFilter{}
seenIsolators := 0
for _, i := range pa.app.App.Isolators {
var flag string
var err error
if seccomp, ok := i.Value().(types.LinuxSeccompSet); ok {
seenIsolators++
// By appc spec, only one seccomp isolator per app is allowed
if seenIsolators > 1 {
return nil, ErrTooManySeccompIsolators
}
switch i.Name {
case types.LinuxSeccompRemoveSetName:
sf.mode = ModeBlacklist
sf.syscalls, flag, err = parseLinuxSeccompSet(p, seccomp)
if err != nil {
return nil, err
}
if flag == "empty" {
// we interpret "remove @empty" to mean "default whitelist"
sf.mode = ModeWhitelist
sf.syscalls = RktDefaultSeccompWhitelist
}
case types.LinuxSeccompRetainSetName:
sf.mode = ModeWhitelist
sf.syscalls, flag, err = parseLinuxSeccompSet(p, seccomp)
if err != nil {
return nil, err
}
if flag == "all" {
// Opt-out seccomp filtering
return nil, nil
}
}
sf.errno = string(seccomp.Errno())
}
}
// If unset, use rkt default whitelist
if seenIsolators == 0 {
sf.mode = ModeWhitelist
sf.syscalls = RktDefaultSeccompWhitelist
}
// Non-priv apps *must* have NoNewPrivileges set if they have seccomp
sf.forceNoNewPrivileges = (pa.uid != 0)
return &sf, nil
}
|
[
"func",
"generateSeccompFilter",
"(",
"p",
"*",
"stage1commontypes",
".",
"Pod",
",",
"pa",
"*",
"preparedApp",
")",
"(",
"*",
"seccompFilter",
",",
"error",
")",
"{",
"sf",
":=",
"seccompFilter",
"{",
"}",
"\n",
"seenIsolators",
":=",
"0",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"pa",
".",
"app",
".",
"App",
".",
"Isolators",
"{",
"var",
"flag",
"string",
"\n",
"var",
"err",
"error",
"\n",
"if",
"seccomp",
",",
"ok",
":=",
"i",
".",
"Value",
"(",
")",
".",
"(",
"types",
".",
"LinuxSeccompSet",
")",
";",
"ok",
"{",
"seenIsolators",
"++",
"\n",
"// By appc spec, only one seccomp isolator per app is allowed",
"if",
"seenIsolators",
">",
"1",
"{",
"return",
"nil",
",",
"ErrTooManySeccompIsolators",
"\n",
"}",
"\n",
"switch",
"i",
".",
"Name",
"{",
"case",
"types",
".",
"LinuxSeccompRemoveSetName",
":",
"sf",
".",
"mode",
"=",
"ModeBlacklist",
"\n",
"sf",
".",
"syscalls",
",",
"flag",
",",
"err",
"=",
"parseLinuxSeccompSet",
"(",
"p",
",",
"seccomp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"flag",
"==",
"\"",
"\"",
"{",
"// we interpret \"remove @empty\" to mean \"default whitelist\"",
"sf",
".",
"mode",
"=",
"ModeWhitelist",
"\n",
"sf",
".",
"syscalls",
"=",
"RktDefaultSeccompWhitelist",
"\n",
"}",
"\n",
"case",
"types",
".",
"LinuxSeccompRetainSetName",
":",
"sf",
".",
"mode",
"=",
"ModeWhitelist",
"\n",
"sf",
".",
"syscalls",
",",
"flag",
",",
"err",
"=",
"parseLinuxSeccompSet",
"(",
"p",
",",
"seccomp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"flag",
"==",
"\"",
"\"",
"{",
"// Opt-out seccomp filtering",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"sf",
".",
"errno",
"=",
"string",
"(",
"seccomp",
".",
"Errno",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// If unset, use rkt default whitelist",
"if",
"seenIsolators",
"==",
"0",
"{",
"sf",
".",
"mode",
"=",
"ModeWhitelist",
"\n",
"sf",
".",
"syscalls",
"=",
"RktDefaultSeccompWhitelist",
"\n",
"}",
"\n\n",
"// Non-priv apps *must* have NoNewPrivileges set if they have seccomp",
"sf",
".",
"forceNoNewPrivileges",
"=",
"(",
"pa",
".",
"uid",
"!=",
"0",
")",
"\n\n",
"return",
"&",
"sf",
",",
"nil",
"\n",
"}"
] |
// generateSeccompFilter computes the concrete seccomp filter from the isolators
|
[
"generateSeccompFilter",
"computes",
"the",
"concrete",
"seccomp",
"filter",
"from",
"the",
"isolators"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/seccomp.go#L58-L107
|
20,994
|
rkt/rkt
|
stage1/init/common/seccomp.go
|
seccompUnitOptions
|
func seccompUnitOptions(opts []*unit.UnitOption, sf *seccompFilter) ([]*unit.UnitOption, error) {
if sf == nil {
return opts, nil
}
if sf.errno != "" {
opts = append(opts, unit.NewUnitOption("Service", "SystemCallErrorNumber", sf.errno))
}
var filterPrefix string
switch sf.mode {
case ModeWhitelist:
filterPrefix = sdWhitelistPrefix
case ModeBlacklist:
filterPrefix = sdBlacklistPrefix
default:
return nil, fmt.Errorf("unknown filter mode %v", sf.mode)
}
// SystemCallFilter options are written down one entry per line, because
// filtering sets may be quite large and overlong lines break unit serialization.
opts = appendOptionsList(opts, "Service", "SystemCallFilter", filterPrefix, sf.syscalls...)
return opts, nil
}
|
go
|
func seccompUnitOptions(opts []*unit.UnitOption, sf *seccompFilter) ([]*unit.UnitOption, error) {
if sf == nil {
return opts, nil
}
if sf.errno != "" {
opts = append(opts, unit.NewUnitOption("Service", "SystemCallErrorNumber", sf.errno))
}
var filterPrefix string
switch sf.mode {
case ModeWhitelist:
filterPrefix = sdWhitelistPrefix
case ModeBlacklist:
filterPrefix = sdBlacklistPrefix
default:
return nil, fmt.Errorf("unknown filter mode %v", sf.mode)
}
// SystemCallFilter options are written down one entry per line, because
// filtering sets may be quite large and overlong lines break unit serialization.
opts = appendOptionsList(opts, "Service", "SystemCallFilter", filterPrefix, sf.syscalls...)
return opts, nil
}
|
[
"func",
"seccompUnitOptions",
"(",
"opts",
"[",
"]",
"*",
"unit",
".",
"UnitOption",
",",
"sf",
"*",
"seccompFilter",
")",
"(",
"[",
"]",
"*",
"unit",
".",
"UnitOption",
",",
"error",
")",
"{",
"if",
"sf",
"==",
"nil",
"{",
"return",
"opts",
",",
"nil",
"\n",
"}",
"\n",
"if",
"sf",
".",
"errno",
"!=",
"\"",
"\"",
"{",
"opts",
"=",
"append",
"(",
"opts",
",",
"unit",
".",
"NewUnitOption",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"sf",
".",
"errno",
")",
")",
"\n",
"}",
"\n\n",
"var",
"filterPrefix",
"string",
"\n",
"switch",
"sf",
".",
"mode",
"{",
"case",
"ModeWhitelist",
":",
"filterPrefix",
"=",
"sdWhitelistPrefix",
"\n",
"case",
"ModeBlacklist",
":",
"filterPrefix",
"=",
"sdBlacklistPrefix",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sf",
".",
"mode",
")",
"\n",
"}",
"\n\n",
"// SystemCallFilter options are written down one entry per line, because",
"// filtering sets may be quite large and overlong lines break unit serialization.",
"opts",
"=",
"appendOptionsList",
"(",
"opts",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"filterPrefix",
",",
"sf",
".",
"syscalls",
"...",
")",
"\n",
"return",
"opts",
",",
"nil",
"\n",
"}"
] |
// seccompUnitOptions converts a concrete seccomp filter to systemd unit options
|
[
"seccompUnitOptions",
"converts",
"a",
"concrete",
"seccomp",
"filter",
"to",
"systemd",
"unit",
"options"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/seccomp.go#L110-L132
|
20,995
|
rkt/rkt
|
stage1/init/common/seccomp.go
|
parseLinuxSeccompSet
|
func parseLinuxSeccompSet(p *stage1commontypes.Pod, s types.LinuxSeccompSet) (syscallFilter []string, flag string, err error) {
for _, item := range s.Set() {
if item[0] == '@' {
// Wildcards
wildcard := strings.SplitN(string(item), "/", 2)
if len(wildcard) != 2 {
continue
}
scope := wildcard[0]
name := wildcard[1]
switch scope {
case "@appc.io":
// appc-reserved wildcards
switch name {
case "all":
return nil, "all", nil
case "empty":
return nil, "empty", nil
}
case "@docker":
// Docker-originated wildcards
switch name {
case "default-blacklist":
syscallFilter = append(syscallFilter, DockerDefaultSeccompBlacklist...)
case "default-whitelist":
syscallFilter = append(syscallFilter, DockerDefaultSeccompWhitelist...)
}
case "@rkt":
// Custom rkt wildcards
switch name {
case "default-blacklist":
syscallFilter = append(syscallFilter, RktDefaultSeccompBlacklist...)
case "default-whitelist":
syscallFilter = append(syscallFilter, RktDefaultSeccompWhitelist...)
}
case "@systemd":
// Custom systemd wildcards (systemd >= 231)
_, systemdVersion, err := GetFlavor(p)
if err != nil || systemdVersion < 231 {
return nil, "", errors.New("Unsupported or unknown systemd version, seccomp groups need systemd >= v231")
}
switch name {
case "clock":
syscallFilter = append(syscallFilter, "@clock")
case "default-whitelist":
syscallFilter = append(syscallFilter, "@default")
case "mount":
syscallFilter = append(syscallFilter, "@mount")
case "network-io":
syscallFilter = append(syscallFilter, "@network-io")
case "obsolete":
syscallFilter = append(syscallFilter, "@obsolete")
case "privileged":
syscallFilter = append(syscallFilter, "@privileged")
case "process":
syscallFilter = append(syscallFilter, "@process")
case "raw-io":
syscallFilter = append(syscallFilter, "@raw-io")
}
}
} else {
// Plain syscall name
syscallFilter = append(syscallFilter, string(item))
}
}
return syscallFilter, "", nil
}
|
go
|
func parseLinuxSeccompSet(p *stage1commontypes.Pod, s types.LinuxSeccompSet) (syscallFilter []string, flag string, err error) {
for _, item := range s.Set() {
if item[0] == '@' {
// Wildcards
wildcard := strings.SplitN(string(item), "/", 2)
if len(wildcard) != 2 {
continue
}
scope := wildcard[0]
name := wildcard[1]
switch scope {
case "@appc.io":
// appc-reserved wildcards
switch name {
case "all":
return nil, "all", nil
case "empty":
return nil, "empty", nil
}
case "@docker":
// Docker-originated wildcards
switch name {
case "default-blacklist":
syscallFilter = append(syscallFilter, DockerDefaultSeccompBlacklist...)
case "default-whitelist":
syscallFilter = append(syscallFilter, DockerDefaultSeccompWhitelist...)
}
case "@rkt":
// Custom rkt wildcards
switch name {
case "default-blacklist":
syscallFilter = append(syscallFilter, RktDefaultSeccompBlacklist...)
case "default-whitelist":
syscallFilter = append(syscallFilter, RktDefaultSeccompWhitelist...)
}
case "@systemd":
// Custom systemd wildcards (systemd >= 231)
_, systemdVersion, err := GetFlavor(p)
if err != nil || systemdVersion < 231 {
return nil, "", errors.New("Unsupported or unknown systemd version, seccomp groups need systemd >= v231")
}
switch name {
case "clock":
syscallFilter = append(syscallFilter, "@clock")
case "default-whitelist":
syscallFilter = append(syscallFilter, "@default")
case "mount":
syscallFilter = append(syscallFilter, "@mount")
case "network-io":
syscallFilter = append(syscallFilter, "@network-io")
case "obsolete":
syscallFilter = append(syscallFilter, "@obsolete")
case "privileged":
syscallFilter = append(syscallFilter, "@privileged")
case "process":
syscallFilter = append(syscallFilter, "@process")
case "raw-io":
syscallFilter = append(syscallFilter, "@raw-io")
}
}
} else {
// Plain syscall name
syscallFilter = append(syscallFilter, string(item))
}
}
return syscallFilter, "", nil
}
|
[
"func",
"parseLinuxSeccompSet",
"(",
"p",
"*",
"stage1commontypes",
".",
"Pod",
",",
"s",
"types",
".",
"LinuxSeccompSet",
")",
"(",
"syscallFilter",
"[",
"]",
"string",
",",
"flag",
"string",
",",
"err",
"error",
")",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"s",
".",
"Set",
"(",
")",
"{",
"if",
"item",
"[",
"0",
"]",
"==",
"'@'",
"{",
"// Wildcards",
"wildcard",
":=",
"strings",
".",
"SplitN",
"(",
"string",
"(",
"item",
")",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"wildcard",
")",
"!=",
"2",
"{",
"continue",
"\n",
"}",
"\n",
"scope",
":=",
"wildcard",
"[",
"0",
"]",
"\n",
"name",
":=",
"wildcard",
"[",
"1",
"]",
"\n",
"switch",
"scope",
"{",
"case",
"\"",
"\"",
":",
"// appc-reserved wildcards",
"switch",
"name",
"{",
"case",
"\"",
"\"",
":",
"return",
"nil",
",",
"\"",
"\"",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"return",
"nil",
",",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"// Docker-originated wildcards",
"switch",
"name",
"{",
"case",
"\"",
"\"",
":",
"syscallFilter",
"=",
"append",
"(",
"syscallFilter",
",",
"DockerDefaultSeccompBlacklist",
"...",
")",
"\n",
"case",
"\"",
"\"",
":",
"syscallFilter",
"=",
"append",
"(",
"syscallFilter",
",",
"DockerDefaultSeccompWhitelist",
"...",
")",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"// Custom rkt wildcards",
"switch",
"name",
"{",
"case",
"\"",
"\"",
":",
"syscallFilter",
"=",
"append",
"(",
"syscallFilter",
",",
"RktDefaultSeccompBlacklist",
"...",
")",
"\n",
"case",
"\"",
"\"",
":",
"syscallFilter",
"=",
"append",
"(",
"syscallFilter",
",",
"RktDefaultSeccompWhitelist",
"...",
")",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"// Custom systemd wildcards (systemd >= 231)",
"_",
",",
"systemdVersion",
",",
"err",
":=",
"GetFlavor",
"(",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"systemdVersion",
"<",
"231",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"switch",
"name",
"{",
"case",
"\"",
"\"",
":",
"syscallFilter",
"=",
"append",
"(",
"syscallFilter",
",",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"syscallFilter",
"=",
"append",
"(",
"syscallFilter",
",",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"syscallFilter",
"=",
"append",
"(",
"syscallFilter",
",",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"syscallFilter",
"=",
"append",
"(",
"syscallFilter",
",",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"syscallFilter",
"=",
"append",
"(",
"syscallFilter",
",",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"syscallFilter",
"=",
"append",
"(",
"syscallFilter",
",",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"syscallFilter",
"=",
"append",
"(",
"syscallFilter",
",",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"syscallFilter",
"=",
"append",
"(",
"syscallFilter",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// Plain syscall name",
"syscallFilter",
"=",
"append",
"(",
"syscallFilter",
",",
"string",
"(",
"item",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"syscallFilter",
",",
"\"",
"\"",
",",
"nil",
"\n",
"}"
] |
// parseLinuxSeccompSet gets an appc LinuxSeccompSet and returns an array
// of values suitable for systemd SystemCallFilter.
|
[
"parseLinuxSeccompSet",
"gets",
"an",
"appc",
"LinuxSeccompSet",
"and",
"returns",
"an",
"array",
"of",
"values",
"suitable",
"for",
"systemd",
"SystemCallFilter",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/init/common/seccomp.go#L136-L202
|
20,996
|
rkt/rkt
|
stage1/app_rm/app_rm.go
|
main
|
func main() {
flag.Parse()
stage1initcommon.InitDebug(debug)
log, diag, _ = rktlog.NewLogSet("app-rm", debug)
if !debug {
diag.SetOutput(ioutil.Discard)
}
appName, err := types.NewACName(flagApp)
if err != nil {
log.FatalE("invalid app name", err)
}
enterCmd := stage1common.PrepareEnterCmd(false)
switch flagStage {
case 0:
// clean resources in stage0
err = cleanupStage0(appName, enterCmd)
case 1:
// clean resources in stage1
err = cleanupStage1(appName, enterCmd)
default:
// unknown step
err = fmt.Errorf("unsupported cleaning step %d", flagStage)
}
if err != nil {
log.FatalE("cleanup error", err)
}
os.Exit(0)
}
|
go
|
func main() {
flag.Parse()
stage1initcommon.InitDebug(debug)
log, diag, _ = rktlog.NewLogSet("app-rm", debug)
if !debug {
diag.SetOutput(ioutil.Discard)
}
appName, err := types.NewACName(flagApp)
if err != nil {
log.FatalE("invalid app name", err)
}
enterCmd := stage1common.PrepareEnterCmd(false)
switch flagStage {
case 0:
// clean resources in stage0
err = cleanupStage0(appName, enterCmd)
case 1:
// clean resources in stage1
err = cleanupStage1(appName, enterCmd)
default:
// unknown step
err = fmt.Errorf("unsupported cleaning step %d", flagStage)
}
if err != nil {
log.FatalE("cleanup error", err)
}
os.Exit(0)
}
|
[
"func",
"main",
"(",
")",
"{",
"flag",
".",
"Parse",
"(",
")",
"\n\n",
"stage1initcommon",
".",
"InitDebug",
"(",
"debug",
")",
"\n\n",
"log",
",",
"diag",
",",
"_",
"=",
"rktlog",
".",
"NewLogSet",
"(",
"\"",
"\"",
",",
"debug",
")",
"\n",
"if",
"!",
"debug",
"{",
"diag",
".",
"SetOutput",
"(",
"ioutil",
".",
"Discard",
")",
"\n",
"}",
"\n\n",
"appName",
",",
"err",
":=",
"types",
".",
"NewACName",
"(",
"flagApp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"FatalE",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"enterCmd",
":=",
"stage1common",
".",
"PrepareEnterCmd",
"(",
"false",
")",
"\n",
"switch",
"flagStage",
"{",
"case",
"0",
":",
"// clean resources in stage0",
"err",
"=",
"cleanupStage0",
"(",
"appName",
",",
"enterCmd",
")",
"\n",
"case",
"1",
":",
"// clean resources in stage1",
"err",
"=",
"cleanupStage1",
"(",
"appName",
",",
"enterCmd",
")",
"\n",
"default",
":",
"// unknown step",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"flagStage",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"FatalE",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"os",
".",
"Exit",
"(",
"0",
")",
"\n",
"}"
] |
// This is a multi-step entrypoint. It starts in stage0 context then invokes
// itself again in stage1 context to perform further cleanup at pod level.
|
[
"This",
"is",
"a",
"multi",
"-",
"step",
"entrypoint",
".",
"It",
"starts",
"in",
"stage0",
"context",
"then",
"invokes",
"itself",
"again",
"in",
"stage1",
"context",
"to",
"perform",
"further",
"cleanup",
"at",
"pod",
"level",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/app_rm/app_rm.go#L56-L88
|
20,997
|
rkt/rkt
|
stage1/app_rm/app_rm.go
|
cleanupStage1
|
func cleanupStage1(appName *types.ACName, enterCmd []string) error {
// TODO(lucab): re-evaluate once/if we support systemd as non-pid1 (eg. host pid-ns inheriting)
mnts, err := mountinfo.ParseMounts(1)
if err != nil {
return err
}
appRootFs := filepath.Join("/opt/stage2", appName.String(), "rootfs")
mnts = mnts.Filter(mountinfo.HasPrefix(appRootFs))
// soft-errors here, stage0 may still be able to continue with the removal anyway
for _, m := range mnts {
// unlink first to avoid back-propagation
_ = syscall.Mount("", m.MountPoint, "", syscall.MS_PRIVATE|syscall.MS_REC, "")
// simple unmount, it may fail if the target is busy (eg. overlapping children)
if e := syscall.Unmount(m.MountPoint, 0); e != nil {
// if busy, just detach here and let the kernel clean it once free
_ = syscall.Unmount(m.MountPoint, syscall.MNT_DETACH)
}
}
return nil
}
|
go
|
func cleanupStage1(appName *types.ACName, enterCmd []string) error {
// TODO(lucab): re-evaluate once/if we support systemd as non-pid1 (eg. host pid-ns inheriting)
mnts, err := mountinfo.ParseMounts(1)
if err != nil {
return err
}
appRootFs := filepath.Join("/opt/stage2", appName.String(), "rootfs")
mnts = mnts.Filter(mountinfo.HasPrefix(appRootFs))
// soft-errors here, stage0 may still be able to continue with the removal anyway
for _, m := range mnts {
// unlink first to avoid back-propagation
_ = syscall.Mount("", m.MountPoint, "", syscall.MS_PRIVATE|syscall.MS_REC, "")
// simple unmount, it may fail if the target is busy (eg. overlapping children)
if e := syscall.Unmount(m.MountPoint, 0); e != nil {
// if busy, just detach here and let the kernel clean it once free
_ = syscall.Unmount(m.MountPoint, syscall.MNT_DETACH)
}
}
return nil
}
|
[
"func",
"cleanupStage1",
"(",
"appName",
"*",
"types",
".",
"ACName",
",",
"enterCmd",
"[",
"]",
"string",
")",
"error",
"{",
"// TODO(lucab): re-evaluate once/if we support systemd as non-pid1 (eg. host pid-ns inheriting)",
"mnts",
",",
"err",
":=",
"mountinfo",
".",
"ParseMounts",
"(",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"appRootFs",
":=",
"filepath",
".",
"Join",
"(",
"\"",
"\"",
",",
"appName",
".",
"String",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"mnts",
"=",
"mnts",
".",
"Filter",
"(",
"mountinfo",
".",
"HasPrefix",
"(",
"appRootFs",
")",
")",
"\n\n",
"// soft-errors here, stage0 may still be able to continue with the removal anyway",
"for",
"_",
",",
"m",
":=",
"range",
"mnts",
"{",
"// unlink first to avoid back-propagation",
"_",
"=",
"syscall",
".",
"Mount",
"(",
"\"",
"\"",
",",
"m",
".",
"MountPoint",
",",
"\"",
"\"",
",",
"syscall",
".",
"MS_PRIVATE",
"|",
"syscall",
".",
"MS_REC",
",",
"\"",
"\"",
")",
"\n",
"// simple unmount, it may fail if the target is busy (eg. overlapping children)",
"if",
"e",
":=",
"syscall",
".",
"Unmount",
"(",
"m",
".",
"MountPoint",
",",
"0",
")",
";",
"e",
"!=",
"nil",
"{",
"// if busy, just detach here and let the kernel clean it once free",
"_",
"=",
"syscall",
".",
"Unmount",
"(",
"m",
".",
"MountPoint",
",",
"syscall",
".",
"MNT_DETACH",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// cleanupStage1 is meant to be executed in stage1 context. It inspects pod systemd-pid1 mountinfo to
// find all remaining mountpoints for appName and proceed to clean them up.
|
[
"cleanupStage1",
"is",
"meant",
"to",
"be",
"executed",
"in",
"stage1",
"context",
".",
"It",
"inspects",
"pod",
"systemd",
"-",
"pid1",
"mountinfo",
"to",
"find",
"all",
"remaining",
"mountpoints",
"for",
"appName",
"and",
"proceed",
"to",
"clean",
"them",
"up",
"."
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/stage1/app_rm/app_rm.go#L155-L176
|
20,998
|
rkt/rkt
|
rkt/gc.go
|
renameExited
|
func renameExited() error {
if err := pkgPod.WalkPods(getDataDir(), pkgPod.IncludeRunDir, func(p *pkgPod.Pod) {
if p.State() == pkgPod.Exited {
stderr.Printf("moving pod %q to garbage", p.UUID)
if err := p.ToExitedGarbage(); err != nil && err != os.ErrNotExist {
stderr.PrintE("rename error", err)
}
}
}); err != nil {
return err
}
return nil
}
|
go
|
func renameExited() error {
if err := pkgPod.WalkPods(getDataDir(), pkgPod.IncludeRunDir, func(p *pkgPod.Pod) {
if p.State() == pkgPod.Exited {
stderr.Printf("moving pod %q to garbage", p.UUID)
if err := p.ToExitedGarbage(); err != nil && err != os.ErrNotExist {
stderr.PrintE("rename error", err)
}
}
}); err != nil {
return err
}
return nil
}
|
[
"func",
"renameExited",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"pkgPod",
".",
"WalkPods",
"(",
"getDataDir",
"(",
")",
",",
"pkgPod",
".",
"IncludeRunDir",
",",
"func",
"(",
"p",
"*",
"pkgPod",
".",
"Pod",
")",
"{",
"if",
"p",
".",
"State",
"(",
")",
"==",
"pkgPod",
".",
"Exited",
"{",
"stderr",
".",
"Printf",
"(",
"\"",
"\"",
",",
"p",
".",
"UUID",
")",
"\n",
"if",
"err",
":=",
"p",
".",
"ToExitedGarbage",
"(",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"os",
".",
"ErrNotExist",
"{",
"stderr",
".",
"PrintE",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// renameExited renames exited pods to the exitedGarbage directory
|
[
"renameExited",
"renames",
"exited",
"pods",
"to",
"the",
"exitedGarbage",
"directory"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/gc.go#L102-L115
|
20,999
|
rkt/rkt
|
rkt/gc.go
|
renameAborted
|
func renameAborted() error {
if err := pkgPod.WalkPods(getDataDir(), pkgPod.IncludePrepareDir, func(p *pkgPod.Pod) {
if p.State() == pkgPod.AbortedPrepare {
stderr.Printf("moving failed prepare %q to garbage", p.UUID)
if err := p.ToGarbage(); err != nil && err != os.ErrNotExist {
stderr.PrintE("rename error", err)
}
}
}); err != nil {
return err
}
return nil
}
|
go
|
func renameAborted() error {
if err := pkgPod.WalkPods(getDataDir(), pkgPod.IncludePrepareDir, func(p *pkgPod.Pod) {
if p.State() == pkgPod.AbortedPrepare {
stderr.Printf("moving failed prepare %q to garbage", p.UUID)
if err := p.ToGarbage(); err != nil && err != os.ErrNotExist {
stderr.PrintE("rename error", err)
}
}
}); err != nil {
return err
}
return nil
}
|
[
"func",
"renameAborted",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"pkgPod",
".",
"WalkPods",
"(",
"getDataDir",
"(",
")",
",",
"pkgPod",
".",
"IncludePrepareDir",
",",
"func",
"(",
"p",
"*",
"pkgPod",
".",
"Pod",
")",
"{",
"if",
"p",
".",
"State",
"(",
")",
"==",
"pkgPod",
".",
"AbortedPrepare",
"{",
"stderr",
".",
"Printf",
"(",
"\"",
"\"",
",",
"p",
".",
"UUID",
")",
"\n",
"if",
"err",
":=",
"p",
".",
"ToGarbage",
"(",
")",
";",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"os",
".",
"ErrNotExist",
"{",
"stderr",
".",
"PrintE",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// renameAborted renames failed prepares to the garbage directory
|
[
"renameAborted",
"renames",
"failed",
"prepares",
"to",
"the",
"garbage",
"directory"
] |
0c8765619cae3391a9ffa12c8dbd12ba7a475eb8
|
https://github.com/rkt/rkt/blob/0c8765619cae3391a9ffa12c8dbd12ba7a475eb8/rkt/gc.go#L147-L159
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.