repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
cri-o/cri-o
lib/sandbox/sandbox.go
AddContainer
func (s *Sandbox) AddContainer(c *oci.Container) { s.containers.Add(c.Name(), c) }
go
func (s *Sandbox) AddContainer(c *oci.Container) { s.containers.Add(c.Name(), c) }
[ "func", "(", "s", "*", "Sandbox", ")", "AddContainer", "(", "c", "*", "oci", ".", "Container", ")", "{", "s", ".", "containers", ".", "Add", "(", "c", ".", "Name", "(", ")", ",", "c", ")", "\n", "}" ]
// AddContainer adds a container to the sandbox
[ "AddContainer", "adds", "a", "container", "to", "the", "sandbox" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/sandbox/sandbox.go#L328-L330
train
cri-o/cri-o
lib/sandbox/sandbox.go
GetContainer
func (s *Sandbox) GetContainer(name string) *oci.Container { return s.containers.Get(name) }
go
func (s *Sandbox) GetContainer(name string) *oci.Container { return s.containers.Get(name) }
[ "func", "(", "s", "*", "Sandbox", ")", "GetContainer", "(", "name", "string", ")", "*", "oci", ".", "Container", "{", "return", "s", ".", "containers", ".", "Get", "(", "name", ")", "\n", "}" ]
// GetContainer retrieves a container from the sandbox
[ "GetContainer", "retrieves", "a", "container", "from", "the", "sandbox" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/sandbox/sandbox.go#L333-L335
train
cri-o/cri-o
lib/sandbox/sandbox.go
RemoveContainer
func (s *Sandbox) RemoveContainer(c *oci.Container) { s.containers.Delete(c.Name()) }
go
func (s *Sandbox) RemoveContainer(c *oci.Container) { s.containers.Delete(c.Name()) }
[ "func", "(", "s", "*", "Sandbox", ")", "RemoveContainer", "(", "c", "*", "oci", ".", "Container", ")", "{", "s", ".", "containers", ".", "Delete", "(", "c", ".", "Name", "(", ")", ")", "\n", "}" ]
// RemoveContainer deletes a container from the sandbox
[ "RemoveContainer", "deletes", "a", "container", "from", "the", "sandbox" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/sandbox/sandbox.go#L338-L340
train
cri-o/cri-o
lib/sandbox/sandbox.go
SetInfraContainer
func (s *Sandbox) SetInfraContainer(infraCtr *oci.Container) error { if s.infraContainer != nil { return fmt.Errorf("sandbox already has an infra container") } else if infraCtr == nil { return fmt.Errorf("must provide non-nil infra container") } s.infraContainer = infraCtr return nil }
go
func (s *Sandbox) SetInfraContainer(infraCtr *oci.Container) error { if s.infraContainer != nil { return fmt.Errorf("sandbox already has an infra container") } else if infraCtr == nil { return fmt.Errorf("must provide non-nil infra container") } s.infraContainer = infraCtr return nil }
[ "func", "(", "s", "*", "Sandbox", ")", "SetInfraContainer", "(", "infraCtr", "*", "oci", ".", "Container", ")", "error", "{", "if", "s", ".", "infraContainer", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "else", "if", "infraCtr", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "s", ".", "infraContainer", "=", "infraCtr", "\n\n", "return", "nil", "\n", "}" ]
// SetInfraContainer sets the infrastructure container of a sandbox // Attempts to set the infrastructure container after one is already present will throw an error
[ "SetInfraContainer", "sets", "the", "infrastructure", "container", "of", "a", "sandbox", "Attempts", "to", "set", "the", "infrastructure", "container", "after", "one", "is", "already", "present", "will", "throw", "an", "error" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/sandbox/sandbox.go#L344-L354
train
cri-o/cri-o
lib/sandbox/sandbox.go
NetNs
func (s *Sandbox) NetNs() *NetNs { if s.netns == nil { return nil } return s.netns.Get() }
go
func (s *Sandbox) NetNs() *NetNs { if s.netns == nil { return nil } return s.netns.Get() }
[ "func", "(", "s", "*", "Sandbox", ")", "NetNs", "(", ")", "*", "NetNs", "{", "if", "s", ".", "netns", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "s", ".", "netns", ".", "Get", "(", ")", "\n", "}" ]
// NetNs retrieves the network namespace of the sandbox // If the sandbox uses the host namespace, nil is returned
[ "NetNs", "retrieves", "the", "network", "namespace", "of", "the", "sandbox", "If", "the", "sandbox", "uses", "the", "host", "namespace", "nil", "is", "returned" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/sandbox/sandbox.go#L363-L368
train
cri-o/cri-o
lib/sandbox/sandbox.go
NetNsPath
func (s *Sandbox) NetNsPath() string { if s.netns == nil || s.netns.Get() == nil || s.netns.Get().symlink == nil { if s.infraContainer != nil { return fmt.Sprintf("/proc/%v/ns/net", s.infraContainer.State().Pid) } return "" } return s.netns.Get().symlink.Name() }
go
func (s *Sandbox) NetNsPath() string { if s.netns == nil || s.netns.Get() == nil || s.netns.Get().symlink == nil { if s.infraContainer != nil { return fmt.Sprintf("/proc/%v/ns/net", s.infraContainer.State().Pid) } return "" } return s.netns.Get().symlink.Name() }
[ "func", "(", "s", "*", "Sandbox", ")", "NetNsPath", "(", ")", "string", "{", "if", "s", ".", "netns", "==", "nil", "||", "s", ".", "netns", ".", "Get", "(", ")", "==", "nil", "||", "s", ".", "netns", ".", "Get", "(", ")", ".", "symlink", "==", "nil", "{", "if", "s", ".", "infraContainer", "!=", "nil", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "infraContainer", ".", "State", "(", ")", ".", "Pid", ")", "\n", "}", "\n", "return", "\"", "\"", "\n", "}", "\n\n", "return", "s", ".", "netns", ".", "Get", "(", ")", ".", "symlink", ".", "Name", "(", ")", "\n", "}" ]
// NetNsPath returns the path to the network namespace of the sandbox. // If the sandbox uses the host namespace, nil is returned
[ "NetNsPath", "returns", "the", "path", "to", "the", "network", "namespace", "of", "the", "sandbox", ".", "If", "the", "sandbox", "uses", "the", "host", "namespace", "nil", "is", "returned" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/sandbox/sandbox.go#L372-L382
train
cri-o/cri-o
lib/sandbox/sandbox.go
UserNsPath
func (s *Sandbox) UserNsPath() string { if s.infraContainer != nil { return fmt.Sprintf("/proc/%v/ns/user", s.infraContainer.State().Pid) } return "" }
go
func (s *Sandbox) UserNsPath() string { if s.infraContainer != nil { return fmt.Sprintf("/proc/%v/ns/user", s.infraContainer.State().Pid) } return "" }
[ "func", "(", "s", "*", "Sandbox", ")", "UserNsPath", "(", ")", "string", "{", "if", "s", ".", "infraContainer", "!=", "nil", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "infraContainer", ".", "State", "(", ")", ".", "Pid", ")", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// UserNsPath returns the path to the user namespace of the sandbox. // If the sandbox uses the host namespace, nil is returned
[ "UserNsPath", "returns", "the", "path", "to", "the", "user", "namespace", "of", "the", "sandbox", ".", "If", "the", "sandbox", "uses", "the", "host", "namespace", "nil", "is", "returned" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/sandbox/sandbox.go#L386-L391
train
cri-o/cri-o
lib/sandbox/sandbox.go
NetNsCreate
func (s *Sandbox) NetNsCreate(netNs NetNsIface) error { // Create a new netNs if nil provided if netNs == nil { netNs = &NetNs{} } // Check if interface is already initialized if netNs.Initialized() { return fmt.Errorf("net NS already initialized") } netNs, err := netNs.Initialize() if err != nil { return err } if err := netNs.SymlinkCreate(s.name); err != nil { logrus.Warnf("Could not create nentns symlink %v", err) if err1 := netNs.Close(); err1 != nil { return err1 } return err } s.netns = netNs return nil }
go
func (s *Sandbox) NetNsCreate(netNs NetNsIface) error { // Create a new netNs if nil provided if netNs == nil { netNs = &NetNs{} } // Check if interface is already initialized if netNs.Initialized() { return fmt.Errorf("net NS already initialized") } netNs, err := netNs.Initialize() if err != nil { return err } if err := netNs.SymlinkCreate(s.name); err != nil { logrus.Warnf("Could not create nentns symlink %v", err) if err1 := netNs.Close(); err1 != nil { return err1 } return err } s.netns = netNs return nil }
[ "func", "(", "s", "*", "Sandbox", ")", "NetNsCreate", "(", "netNs", "NetNsIface", ")", "error", "{", "// Create a new netNs if nil provided", "if", "netNs", "==", "nil", "{", "netNs", "=", "&", "NetNs", "{", "}", "\n", "}", "\n\n", "// Check if interface is already initialized", "if", "netNs", ".", "Initialized", "(", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "netNs", ",", "err", ":=", "netNs", ".", "Initialize", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "netNs", ".", "SymlinkCreate", "(", "s", ".", "name", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "err", ")", "\n\n", "if", "err1", ":=", "netNs", ".", "Close", "(", ")", ";", "err1", "!=", "nil", "{", "return", "err1", "\n", "}", "\n\n", "return", "err", "\n", "}", "\n\n", "s", ".", "netns", "=", "netNs", "\n", "return", "nil", "\n", "}" ]
// NetNsCreate creates a new network namespace for the sandbox
[ "NetNsCreate", "creates", "a", "new", "network", "namespace", "for", "the", "sandbox" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/sandbox/sandbox.go#L394-L422
train
cri-o/cri-o
lib/sandbox/sandbox.go
NetNsJoin
func (s *Sandbox) NetNsJoin(nspath, name string) error { if s.netns != nil { return fmt.Errorf("sandbox already has a network namespace, cannot join another") } netNS, err := s.NetNsGet(nspath, name) if err != nil { return err } s.netns = netNS return nil }
go
func (s *Sandbox) NetNsJoin(nspath, name string) error { if s.netns != nil { return fmt.Errorf("sandbox already has a network namespace, cannot join another") } netNS, err := s.NetNsGet(nspath, name) if err != nil { return err } s.netns = netNS return nil }
[ "func", "(", "s", "*", "Sandbox", ")", "NetNsJoin", "(", "nspath", ",", "name", "string", ")", "error", "{", "if", "s", ".", "netns", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "netNS", ",", "err", ":=", "s", ".", "NetNsGet", "(", "nspath", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "s", ".", "netns", "=", "netNS", "\n\n", "return", "nil", "\n", "}" ]
// NetNsJoin attempts to join the sandbox to an existing network namespace // This will fail if the sandbox is already part of a network namespace
[ "NetNsJoin", "attempts", "to", "join", "the", "sandbox", "to", "an", "existing", "network", "namespace", "This", "will", "fail", "if", "the", "sandbox", "is", "already", "part", "of", "a", "network", "namespace" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/sandbox/sandbox.go#L439-L452
train
cri-o/cri-o
lib/sandbox/sandbox.go
NetNsRemove
func (s *Sandbox) NetNsRemove() error { if s.netns == nil { logrus.Warn("no networking namespace") return nil } return s.netns.Remove() }
go
func (s *Sandbox) NetNsRemove() error { if s.netns == nil { logrus.Warn("no networking namespace") return nil } return s.netns.Remove() }
[ "func", "(", "s", "*", "Sandbox", ")", "NetNsRemove", "(", ")", "error", "{", "if", "s", ".", "netns", "==", "nil", "{", "logrus", ".", "Warn", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "return", "s", ".", "netns", ".", "Remove", "(", ")", "\n", "}" ]
// NetNsRemove removes the network namespace associated with the sandbox
[ "NetNsRemove", "removes", "the", "network", "namespace", "associated", "with", "the", "sandbox" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/sandbox/sandbox.go#L455-L462
train
cri-o/cri-o
client/client.go
New
func New(crioSocketPath string) (CrioClient, error) { tr := new(http.Transport) configureUnixTransport(tr, "unix", crioSocketPath) c := &http.Client{ Transport: tr, } return &crioClientImpl{ client: c, crioSocketPath: crioSocketPath, }, nil }
go
func New(crioSocketPath string) (CrioClient, error) { tr := new(http.Transport) configureUnixTransport(tr, "unix", crioSocketPath) c := &http.Client{ Transport: tr, } return &crioClientImpl{ client: c, crioSocketPath: crioSocketPath, }, nil }
[ "func", "New", "(", "crioSocketPath", "string", ")", "(", "CrioClient", ",", "error", ")", "{", "tr", ":=", "new", "(", "http", ".", "Transport", ")", "\n", "configureUnixTransport", "(", "tr", ",", "\"", "\"", ",", "crioSocketPath", ")", "\n", "c", ":=", "&", "http", ".", "Client", "{", "Transport", ":", "tr", ",", "}", "\n", "return", "&", "crioClientImpl", "{", "client", ":", "c", ",", "crioSocketPath", ":", "crioSocketPath", ",", "}", ",", "nil", "\n", "}" ]
// New returns a crio client
[ "New", "returns", "a", "crio", "client" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/client/client.go#L43-L53
train
cri-o/cri-o
client/client.go
DaemonInfo
func (c *crioClientImpl) DaemonInfo() (types.CrioInfo, error) { info := types.CrioInfo{} req, err := c.getRequest("/info") if err != nil { return info, err } resp, err := c.client.Do(req) if err != nil { return info, err } defer resp.Body.Close() err = json.NewDecoder(resp.Body).Decode(&info) return info, err }
go
func (c *crioClientImpl) DaemonInfo() (types.CrioInfo, error) { info := types.CrioInfo{} req, err := c.getRequest("/info") if err != nil { return info, err } resp, err := c.client.Do(req) if err != nil { return info, err } defer resp.Body.Close() err = json.NewDecoder(resp.Body).Decode(&info) return info, err }
[ "func", "(", "c", "*", "crioClientImpl", ")", "DaemonInfo", "(", ")", "(", "types", ".", "CrioInfo", ",", "error", ")", "{", "info", ":=", "types", ".", "CrioInfo", "{", "}", "\n", "req", ",", "err", ":=", "c", ".", "getRequest", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "info", ",", "err", "\n", "}", "\n", "resp", ",", "err", ":=", "c", ".", "client", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "info", ",", "err", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "err", "=", "json", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "&", "info", ")", "\n", "return", "info", ",", "err", "\n", "}" ]
// DaemonInfo return cri-o daemon info from the cri-o // info endpoint.
[ "DaemonInfo", "return", "cri", "-", "o", "daemon", "info", "from", "the", "cri", "-", "o", "info", "endpoint", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/client/client.go#L70-L83
train
cri-o/cri-o
client/client.go
ContainerInfo
func (c *crioClientImpl) ContainerInfo(id string) (*types.ContainerInfo, error) { req, err := c.getRequest("/containers/" + id) if err != nil { return nil, err } resp, err := c.client.Do(req) if err != nil { return nil, err } defer resp.Body.Close() cInfo := types.ContainerInfo{} if err := json.NewDecoder(resp.Body).Decode(&cInfo); err != nil { return nil, err } return &cInfo, nil }
go
func (c *crioClientImpl) ContainerInfo(id string) (*types.ContainerInfo, error) { req, err := c.getRequest("/containers/" + id) if err != nil { return nil, err } resp, err := c.client.Do(req) if err != nil { return nil, err } defer resp.Body.Close() cInfo := types.ContainerInfo{} if err := json.NewDecoder(resp.Body).Decode(&cInfo); err != nil { return nil, err } return &cInfo, nil }
[ "func", "(", "c", "*", "crioClientImpl", ")", "ContainerInfo", "(", "id", "string", ")", "(", "*", "types", ".", "ContainerInfo", ",", "error", ")", "{", "req", ",", "err", ":=", "c", ".", "getRequest", "(", "\"", "\"", "+", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "resp", ",", "err", ":=", "c", ".", "client", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "cInfo", ":=", "types", ".", "ContainerInfo", "{", "}", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "&", "cInfo", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "cInfo", ",", "nil", "\n", "}" ]
// ContainerInfo returns container info by querying // the cri-o container endpoint.
[ "ContainerInfo", "returns", "container", "info", "by", "querying", "the", "cri", "-", "o", "container", "endpoint", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/client/client.go#L87-L102
train
cri-o/cri-o
utils/fifo/fifo.go
Write
func (f *fifo) Write(b []byte) (int, error) { if f.flag&(syscall.O_WRONLY|syscall.O_RDWR) == 0 { return 0, errors.New("writing to read-only fifo") } select { case <-f.opened: return f.file.Write(b) default: } select { case <-f.opened: return f.file.Write(b) case <-f.closed: return 0, errors.New("writing to a closed fifo") } }
go
func (f *fifo) Write(b []byte) (int, error) { if f.flag&(syscall.O_WRONLY|syscall.O_RDWR) == 0 { return 0, errors.New("writing to read-only fifo") } select { case <-f.opened: return f.file.Write(b) default: } select { case <-f.opened: return f.file.Write(b) case <-f.closed: return 0, errors.New("writing to a closed fifo") } }
[ "func", "(", "f", "*", "fifo", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "f", ".", "flag", "&", "(", "syscall", ".", "O_WRONLY", "|", "syscall", ".", "O_RDWR", ")", "==", "0", "{", "return", "0", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "select", "{", "case", "<-", "f", ".", "opened", ":", "return", "f", ".", "file", ".", "Write", "(", "b", ")", "\n", "default", ":", "}", "\n", "select", "{", "case", "<-", "f", ".", "opened", ":", "return", "f", ".", "file", ".", "Write", "(", "b", ")", "\n", "case", "<-", "f", ".", "closed", ":", "return", "0", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// Write from byte array to a fifo.
[ "Write", "from", "byte", "array", "to", "a", "fifo", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/fifo/fifo.go#L166-L181
train
cri-o/cri-o
server/useragent/useragent.go
Get
func Get(ctx context.Context) string { httpVersion := make([]VersionInfo, 0, 4) httpVersion = append(httpVersion, VersionInfo{Name: "cri-o", Version: version.Version}) httpVersion = append(httpVersion, VersionInfo{Name: "go", Version: runtime.Version()}) httpVersion = append(httpVersion, VersionInfo{Name: "os", Version: runtime.GOOS}) httpVersion = append(httpVersion, VersionInfo{Name: "arch", Version: runtime.GOARCH}) return AppendVersions("", httpVersion...) }
go
func Get(ctx context.Context) string { httpVersion := make([]VersionInfo, 0, 4) httpVersion = append(httpVersion, VersionInfo{Name: "cri-o", Version: version.Version}) httpVersion = append(httpVersion, VersionInfo{Name: "go", Version: runtime.Version()}) httpVersion = append(httpVersion, VersionInfo{Name: "os", Version: runtime.GOOS}) httpVersion = append(httpVersion, VersionInfo{Name: "arch", Version: runtime.GOARCH}) return AppendVersions("", httpVersion...) }
[ "func", "Get", "(", "ctx", "context", ".", "Context", ")", "string", "{", "httpVersion", ":=", "make", "(", "[", "]", "VersionInfo", ",", "0", ",", "4", ")", "\n", "httpVersion", "=", "append", "(", "httpVersion", ",", "VersionInfo", "{", "Name", ":", "\"", "\"", ",", "Version", ":", "version", ".", "Version", "}", ")", "\n", "httpVersion", "=", "append", "(", "httpVersion", ",", "VersionInfo", "{", "Name", ":", "\"", "\"", ",", "Version", ":", "runtime", ".", "Version", "(", ")", "}", ")", "\n", "httpVersion", "=", "append", "(", "httpVersion", ",", "VersionInfo", "{", "Name", ":", "\"", "\"", ",", "Version", ":", "runtime", ".", "GOOS", "}", ")", "\n", "httpVersion", "=", "append", "(", "httpVersion", ",", "VersionInfo", "{", "Name", ":", "\"", "\"", ",", "Version", ":", "runtime", ".", "GOARCH", "}", ")", "\n\n", "return", "AppendVersions", "(", "\"", "\"", ",", "httpVersion", "...", ")", "\n", "}" ]
// Get is the User-Agent the CRI-O daemon uses to identify itself.
[ "Get", "is", "the", "User", "-", "Agent", "the", "CRI", "-", "O", "daemon", "uses", "to", "identify", "itself", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/useragent/useragent.go#L11-L19
train
cri-o/cri-o
server/secrets.go
SaveTo
func (s SecretData) SaveTo(dir string) error { path := filepath.Join(dir, s.Name) if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil && !os.IsExist(err) { return err } return ioutil.WriteFile(path, s.Data, 0700) }
go
func (s SecretData) SaveTo(dir string) error { path := filepath.Join(dir, s.Name) if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil && !os.IsExist(err) { return err } return ioutil.WriteFile(path, s.Data, 0700) }
[ "func", "(", "s", "SecretData", ")", "SaveTo", "(", "dir", "string", ")", "error", "{", "path", ":=", "filepath", ".", "Join", "(", "dir", ",", "s", ".", "Name", ")", "\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "filepath", ".", "Dir", "(", "path", ")", ",", "0700", ")", ";", "err", "!=", "nil", "&&", "!", "os", ".", "IsExist", "(", "err", ")", "{", "return", "err", "\n", "}", "\n", "return", "ioutil", ".", "WriteFile", "(", "path", ",", "s", ".", "Data", ",", "0700", ")", "\n", "}" ]
// SaveTo saves secret data to given directory
[ "SaveTo", "saves", "secret", "data", "to", "given", "directory" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/secrets.go#L23-L29
train
cri-o/cri-o
server/secrets.go
secretMounts
func secretMounts(defaultMountsPaths []string, mountLabel, containerWorkingDir string, runtimeMounts []rspec.Mount) ([]rspec.Mount, error) { mounts := make([]rspec.Mount, 0, len(defaultMountsPaths)) for _, path := range defaultMountsPaths { hostDir, ctrDir, err := getMountsMap(path) if err != nil { return nil, err } // skip if the hostDir path doesn't exist if _, err := os.Stat(hostDir); os.IsNotExist(err) { logrus.Warnf("%q doesn't exist, skipping", hostDir) continue } ctrDirOnHost := filepath.Join(containerWorkingDir, ctrDir) // skip if ctrDir has already been mounted by caller if isAlreadyMounted(runtimeMounts, ctrDir) { logrus.Warnf("%q has already been mounted; cannot override mount", ctrDir) continue } if err := os.RemoveAll(ctrDirOnHost); err != nil { return nil, fmt.Errorf("remove container directory failed: %v", err) } if err := os.MkdirAll(ctrDirOnHost, 0755); err != nil { return nil, fmt.Errorf("making container directory failed: %v", err) } hostDir, err = resolveSymbolicLink(hostDir, "/") if err != nil { return nil, err } data, err := getHostSecretData(hostDir) if err != nil { return nil, errors.Wrapf(err, "getting host secret data failed") } for _, s := range data { if err := s.SaveTo(ctrDirOnHost); err != nil { return nil, err } } if err := label.Relabel(ctrDirOnHost, mountLabel, false); err != nil { return nil, err } m := rspec.Mount{ Source: ctrDirOnHost, Destination: ctrDir, } mounts = append(mounts, m) } return mounts, nil }
go
func secretMounts(defaultMountsPaths []string, mountLabel, containerWorkingDir string, runtimeMounts []rspec.Mount) ([]rspec.Mount, error) { mounts := make([]rspec.Mount, 0, len(defaultMountsPaths)) for _, path := range defaultMountsPaths { hostDir, ctrDir, err := getMountsMap(path) if err != nil { return nil, err } // skip if the hostDir path doesn't exist if _, err := os.Stat(hostDir); os.IsNotExist(err) { logrus.Warnf("%q doesn't exist, skipping", hostDir) continue } ctrDirOnHost := filepath.Join(containerWorkingDir, ctrDir) // skip if ctrDir has already been mounted by caller if isAlreadyMounted(runtimeMounts, ctrDir) { logrus.Warnf("%q has already been mounted; cannot override mount", ctrDir) continue } if err := os.RemoveAll(ctrDirOnHost); err != nil { return nil, fmt.Errorf("remove container directory failed: %v", err) } if err := os.MkdirAll(ctrDirOnHost, 0755); err != nil { return nil, fmt.Errorf("making container directory failed: %v", err) } hostDir, err = resolveSymbolicLink(hostDir, "/") if err != nil { return nil, err } data, err := getHostSecretData(hostDir) if err != nil { return nil, errors.Wrapf(err, "getting host secret data failed") } for _, s := range data { if err := s.SaveTo(ctrDirOnHost); err != nil { return nil, err } } if err := label.Relabel(ctrDirOnHost, mountLabel, false); err != nil { return nil, err } m := rspec.Mount{ Source: ctrDirOnHost, Destination: ctrDir, } mounts = append(mounts, m) } return mounts, nil }
[ "func", "secretMounts", "(", "defaultMountsPaths", "[", "]", "string", ",", "mountLabel", ",", "containerWorkingDir", "string", ",", "runtimeMounts", "[", "]", "rspec", ".", "Mount", ")", "(", "[", "]", "rspec", ".", "Mount", ",", "error", ")", "{", "mounts", ":=", "make", "(", "[", "]", "rspec", ".", "Mount", ",", "0", ",", "len", "(", "defaultMountsPaths", ")", ")", "\n", "for", "_", ",", "path", ":=", "range", "defaultMountsPaths", "{", "hostDir", ",", "ctrDir", ",", "err", ":=", "getMountsMap", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "// skip if the hostDir path doesn't exist", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "hostDir", ")", ";", "os", ".", "IsNotExist", "(", "err", ")", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "hostDir", ")", "\n", "continue", "\n", "}", "\n\n", "ctrDirOnHost", ":=", "filepath", ".", "Join", "(", "containerWorkingDir", ",", "ctrDir", ")", "\n", "// skip if ctrDir has already been mounted by caller", "if", "isAlreadyMounted", "(", "runtimeMounts", ",", "ctrDir", ")", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "ctrDir", ")", "\n", "continue", "\n", "}", "\n\n", "if", "err", ":=", "os", ".", "RemoveAll", "(", "ctrDirOnHost", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "ctrDirOnHost", ",", "0755", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "hostDir", ",", "err", "=", "resolveSymbolicLink", "(", "hostDir", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "data", ",", "err", ":=", "getHostSecretData", "(", "hostDir", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "for", "_", ",", "s", ":=", "range", "data", "{", "if", "err", ":=", "s", ".", "SaveTo", "(", "ctrDirOnHost", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "label", ".", "Relabel", "(", "ctrDirOnHost", ",", "mountLabel", ",", "false", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "m", ":=", "rspec", ".", "Mount", "{", "Source", ":", "ctrDirOnHost", ",", "Destination", ":", "ctrDir", ",", "}", "\n\n", "mounts", "=", "append", "(", "mounts", ",", "m", ")", "\n", "}", "\n", "return", "mounts", ",", "nil", "\n", "}" ]
// secretMount copies the contents of host directory to container directory // and returns a list of mounts
[ "secretMount", "copies", "the", "contents", "of", "host", "directory", "to", "container", "directory", "and", "returns", "a", "list", "of", "mounts" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/secrets.go#L103-L157
train
cri-o/cri-o
utils/io/logger.go
NewCRILogger
func NewCRILogger(path string, w io.Writer, stream StreamType, maxLen int) (io.WriteCloser, <-chan struct{}) { logrus.Debugf("Start writing stream %q to log file %q", stream, path) prc, pwc := io.Pipe() stop := make(chan struct{}) go func() { redirectLogs(path, prc, w, stream, maxLen) close(stop) }() return pwc, stop }
go
func NewCRILogger(path string, w io.Writer, stream StreamType, maxLen int) (io.WriteCloser, <-chan struct{}) { logrus.Debugf("Start writing stream %q to log file %q", stream, path) prc, pwc := io.Pipe() stop := make(chan struct{}) go func() { redirectLogs(path, prc, w, stream, maxLen) close(stop) }() return pwc, stop }
[ "func", "NewCRILogger", "(", "path", "string", ",", "w", "io", ".", "Writer", ",", "stream", "StreamType", ",", "maxLen", "int", ")", "(", "io", ".", "WriteCloser", ",", "<-", "chan", "struct", "{", "}", ")", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "stream", ",", "path", ")", "\n", "prc", ",", "pwc", ":=", "io", ".", "Pipe", "(", ")", "\n", "stop", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "go", "func", "(", ")", "{", "redirectLogs", "(", "path", ",", "prc", ",", "w", ",", "stream", ",", "maxLen", ")", "\n", "close", "(", "stop", ")", "\n", "}", "(", ")", "\n", "return", "pwc", ",", "stop", "\n", "}" ]
// NewCRILogger returns a write closer which redirect container log into // log file, and decorate the log line into CRI defined format. It also // returns a channel which indicates whether the logger is stopped. // maxLen is the max length limit of a line. A line longer than the // limit will be cut into multiple lines.
[ "NewCRILogger", "returns", "a", "write", "closer", "which", "redirect", "container", "log", "into", "log", "file", "and", "decorate", "the", "log", "line", "into", "CRI", "defined", "format", ".", "It", "also", "returns", "a", "channel", "which", "indicates", "whether", "the", "logger", "is", "stopped", ".", "maxLen", "is", "the", "max", "length", "limit", "of", "a", "line", ".", "A", "line", "longer", "than", "the", "limit", "will", "be", "cut", "into", "multiple", "lines", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/io/logger.go#L53-L62
train
cri-o/cri-o
server/utils.go
inStringSlice
func inStringSlice(ss []string, str string) bool { for _, s := range ss { if strings.EqualFold(s, str) { return true } } return false }
go
func inStringSlice(ss []string, str string) bool { for _, s := range ss { if strings.EqualFold(s, str) { return true } } return false }
[ "func", "inStringSlice", "(", "ss", "[", "]", "string", ",", "str", "string", ")", "bool", "{", "for", "_", ",", "s", ":=", "range", "ss", "{", "if", "strings", ".", "EqualFold", "(", "s", ",", "str", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// inStringSlice checks whether a string is inside a string slice. // Comparison is case insensitive.
[ "inStringSlice", "checks", "whether", "a", "string", "is", "inside", "a", "string", "slice", ".", "Comparison", "is", "case", "insensitive", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/utils.go#L113-L120
train
cri-o/cri-o
server/utils.go
getOCICapabilitiesList
func getOCICapabilitiesList() []string { caps := make([]string, 0, len(capability.List())) for _, cap := range capability.List() { if cap > validate.LastCap() { continue } caps = append(caps, "CAP_"+strings.ToUpper(cap.String())) } return caps }
go
func getOCICapabilitiesList() []string { caps := make([]string, 0, len(capability.List())) for _, cap := range capability.List() { if cap > validate.LastCap() { continue } caps = append(caps, "CAP_"+strings.ToUpper(cap.String())) } return caps }
[ "func", "getOCICapabilitiesList", "(", ")", "[", "]", "string", "{", "caps", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "capability", ".", "List", "(", ")", ")", ")", "\n", "for", "_", ",", "cap", ":=", "range", "capability", ".", "List", "(", ")", "{", "if", "cap", ">", "validate", ".", "LastCap", "(", ")", "{", "continue", "\n", "}", "\n", "caps", "=", "append", "(", "caps", ",", "\"", "\"", "+", "strings", ".", "ToUpper", "(", "cap", ".", "String", "(", ")", ")", ")", "\n", "}", "\n", "return", "caps", "\n", "}" ]
// getOCICapabilitiesList returns a list of all available capabilities.
[ "getOCICapabilitiesList", "returns", "a", "list", "of", "all", "available", "capabilities", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/utils.go#L123-L132
train
cri-o/cri-o
server/utils.go
validateSysctl
func validateSysctl(sysctl string, hostNet, hostIPC bool) error { nsErrorFmt := "%q not allowed with host %s enabled" if ns, found := namespaces[sysctl]; found { if ns == IpcNamespace && hostIPC { return errors.Errorf(nsErrorFmt, sysctl, ns) } if ns == NetNamespace && hostNet { return errors.Errorf(nsErrorFmt, sysctl, ns) } return nil } for p, ns := range prefixNamespaces { if strings.HasPrefix(sysctl, p) { if ns == IpcNamespace && hostIPC { return errors.Errorf(nsErrorFmt, sysctl, ns) } if ns == NetNamespace && hostNet { return errors.Errorf(nsErrorFmt, sysctl, ns) } return nil } } return errors.Errorf("%q not whitelisted", sysctl) }
go
func validateSysctl(sysctl string, hostNet, hostIPC bool) error { nsErrorFmt := "%q not allowed with host %s enabled" if ns, found := namespaces[sysctl]; found { if ns == IpcNamespace && hostIPC { return errors.Errorf(nsErrorFmt, sysctl, ns) } if ns == NetNamespace && hostNet { return errors.Errorf(nsErrorFmt, sysctl, ns) } return nil } for p, ns := range prefixNamespaces { if strings.HasPrefix(sysctl, p) { if ns == IpcNamespace && hostIPC { return errors.Errorf(nsErrorFmt, sysctl, ns) } if ns == NetNamespace && hostNet { return errors.Errorf(nsErrorFmt, sysctl, ns) } return nil } } return errors.Errorf("%q not whitelisted", sysctl) }
[ "func", "validateSysctl", "(", "sysctl", "string", ",", "hostNet", ",", "hostIPC", "bool", ")", "error", "{", "nsErrorFmt", ":=", "\"", "\"", "\n", "if", "ns", ",", "found", ":=", "namespaces", "[", "sysctl", "]", ";", "found", "{", "if", "ns", "==", "IpcNamespace", "&&", "hostIPC", "{", "return", "errors", ".", "Errorf", "(", "nsErrorFmt", ",", "sysctl", ",", "ns", ")", "\n", "}", "\n", "if", "ns", "==", "NetNamespace", "&&", "hostNet", "{", "return", "errors", ".", "Errorf", "(", "nsErrorFmt", ",", "sysctl", ",", "ns", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "for", "p", ",", "ns", ":=", "range", "prefixNamespaces", "{", "if", "strings", ".", "HasPrefix", "(", "sysctl", ",", "p", ")", "{", "if", "ns", "==", "IpcNamespace", "&&", "hostIPC", "{", "return", "errors", ".", "Errorf", "(", "nsErrorFmt", ",", "sysctl", ",", "ns", ")", "\n", "}", "\n", "if", "ns", "==", "NetNamespace", "&&", "hostNet", "{", "return", "errors", ".", "Errorf", "(", "nsErrorFmt", ",", "sysctl", ",", "ns", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "sysctl", ")", "\n", "}" ]
// validateSysctl checks that a sysctl is whitelisted because it is known // to be namespaced by the Linux kernel. // The parameters hostNet and hostIPC are used to forbid sysctls for pod sharing the // respective namespaces with the host. This check is only used on sysctls defined by // the user in the crio.conf file.
[ "validateSysctl", "checks", "that", "a", "sysctl", "is", "whitelisted", "because", "it", "is", "known", "to", "be", "namespaced", "by", "the", "Linux", "kernel", ".", "The", "parameters", "hostNet", "and", "hostIPC", "are", "used", "to", "forbid", "sysctls", "for", "pod", "sharing", "the", "respective", "namespaces", "with", "the", "host", ".", "This", "check", "is", "only", "used", "on", "sysctls", "defined", "by", "the", "user", "in", "the", "crio", ".", "conf", "file", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/utils.go#L230-L253
train
cri-o/cri-o
server/utils.go
translateLabelsToDescription
func translateLabelsToDescription(labels map[string]string) string { return fmt.Sprintf("%s/%s/%s", labels[types.KubernetesPodNamespaceLabel], labels[types.KubernetesPodNameLabel], labels[types.KubernetesContainerNameLabel]) }
go
func translateLabelsToDescription(labels map[string]string) string { return fmt.Sprintf("%s/%s/%s", labels[types.KubernetesPodNamespaceLabel], labels[types.KubernetesPodNameLabel], labels[types.KubernetesContainerNameLabel]) }
[ "func", "translateLabelsToDescription", "(", "labels", "map", "[", "string", "]", "string", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "labels", "[", "types", ".", "KubernetesPodNamespaceLabel", "]", ",", "labels", "[", "types", ".", "KubernetesPodNameLabel", "]", ",", "labels", "[", "types", ".", "KubernetesContainerNameLabel", "]", ")", "\n", "}" ]
// Translate container labels to a description of the container
[ "Translate", "container", "labels", "to", "a", "description", "of", "the", "container" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/utils.go#L279-L281
train
cri-o/cri-o
lib/config.go
GetStore
func (c *Config) GetStore() (cstorage.Store, error) { return cstorage.GetStore(cstorage.StoreOptions{ RunRoot: c.RunRoot, GraphRoot: c.Root, GraphDriverName: c.Storage, GraphDriverOptions: c.StorageOptions, }) }
go
func (c *Config) GetStore() (cstorage.Store, error) { return cstorage.GetStore(cstorage.StoreOptions{ RunRoot: c.RunRoot, GraphRoot: c.Root, GraphDriverName: c.Storage, GraphDriverOptions: c.StorageOptions, }) }
[ "func", "(", "c", "*", "Config", ")", "GetStore", "(", ")", "(", "cstorage", ".", "Store", ",", "error", ")", "{", "return", "cstorage", ".", "GetStore", "(", "cstorage", ".", "StoreOptions", "{", "RunRoot", ":", "c", ".", "RunRoot", ",", "GraphRoot", ":", "c", ".", "Root", ",", "GraphDriverName", ":", "c", ".", "Storage", ",", "GraphDriverOptions", ":", "c", ".", "StorageOptions", ",", "}", ")", "\n", "}" ]
// GetStore returns the container storage for a given configuration
[ "GetStore", "returns", "the", "container", "storage", "for", "a", "given", "configuration" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/config.go#L49-L56
train
cri-o/cri-o
lib/config.go
UpdateFromFile
func (c *Config) UpdateFromFile(path string) error { data, err := ioutil.ReadFile(path) if err != nil { return err } t := new(tomlConfig) t.fromConfig(c) _, err = toml.Decode(string(data), t) if err != nil { return fmt.Errorf("unable to decode configuration %v: %v", path, err) } t.toConfig(c) return nil }
go
func (c *Config) UpdateFromFile(path string) error { data, err := ioutil.ReadFile(path) if err != nil { return err } t := new(tomlConfig) t.fromConfig(c) _, err = toml.Decode(string(data), t) if err != nil { return fmt.Errorf("unable to decode configuration %v: %v", path, err) } t.toConfig(c) return nil }
[ "func", "(", "c", "*", "Config", ")", "UpdateFromFile", "(", "path", "string", ")", "error", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "t", ":=", "new", "(", "tomlConfig", ")", "\n", "t", ".", "fromConfig", "(", "c", ")", "\n\n", "_", ",", "err", "=", "toml", ".", "Decode", "(", "string", "(", "data", ")", ",", "t", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "path", ",", "err", ")", "\n", "}", "\n\n", "t", ".", "toConfig", "(", "c", ")", "\n", "return", "nil", "\n", "}" ]
// UpdateFromFile populates the Config from the TOML-encoded file at the given path. // Returns errors encountered when reading or parsing the files, or nil // otherwise.
[ "UpdateFromFile", "populates", "the", "Config", "from", "the", "TOML", "-", "encoded", "file", "at", "the", "given", "path", ".", "Returns", "errors", "encountered", "when", "reading", "or", "parsing", "the", "files", "or", "nil", "otherwise", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/config.go#L320-L336
train
cri-o/cri-o
lib/config.go
ToFile
func (c *Config) ToFile(path string) error { var w bytes.Buffer e := toml.NewEncoder(&w) t := new(tomlConfig) t.fromConfig(c) if err := e.Encode(*t); err != nil { return err } return ioutil.WriteFile(path, w.Bytes(), 0644) }
go
func (c *Config) ToFile(path string) error { var w bytes.Buffer e := toml.NewEncoder(&w) t := new(tomlConfig) t.fromConfig(c) if err := e.Encode(*t); err != nil { return err } return ioutil.WriteFile(path, w.Bytes(), 0644) }
[ "func", "(", "c", "*", "Config", ")", "ToFile", "(", "path", "string", ")", "error", "{", "var", "w", "bytes", ".", "Buffer", "\n", "e", ":=", "toml", ".", "NewEncoder", "(", "&", "w", ")", "\n\n", "t", ":=", "new", "(", "tomlConfig", ")", "\n", "t", ".", "fromConfig", "(", "c", ")", "\n\n", "if", "err", ":=", "e", ".", "Encode", "(", "*", "t", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "ioutil", ".", "WriteFile", "(", "path", ",", "w", ".", "Bytes", "(", ")", ",", "0644", ")", "\n", "}" ]
// ToFile outputs the given Config as a TOML-encoded file at the given path. // Returns errors encountered when generating or writing the file, or nil // otherwise.
[ "ToFile", "outputs", "the", "given", "Config", "as", "a", "TOML", "-", "encoded", "file", "at", "the", "given", "path", ".", "Returns", "errors", "encountered", "when", "generating", "or", "writing", "the", "file", "or", "nil", "otherwise", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/config.go#L341-L353
train
cri-o/cri-o
lib/config.go
Validate
func (c *Config) Validate(onExecution bool) error { if err := c.RootConfig.Validate(onExecution); err != nil { return errors.Wrapf(err, "root config") } if err := c.RuntimeConfig.Validate(onExecution); err != nil { return errors.Wrapf(err, "runtime config") } if err := c.NetworkConfig.Validate(onExecution); err != nil { return errors.Wrapf(err, "network config") } return nil }
go
func (c *Config) Validate(onExecution bool) error { if err := c.RootConfig.Validate(onExecution); err != nil { return errors.Wrapf(err, "root config") } if err := c.RuntimeConfig.Validate(onExecution); err != nil { return errors.Wrapf(err, "runtime config") } if err := c.NetworkConfig.Validate(onExecution); err != nil { return errors.Wrapf(err, "network config") } return nil }
[ "func", "(", "c", "*", "Config", ")", "Validate", "(", "onExecution", "bool", ")", "error", "{", "if", "err", ":=", "c", ".", "RootConfig", ".", "Validate", "(", "onExecution", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "err", ":=", "c", ".", "RuntimeConfig", ".", "Validate", "(", "onExecution", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "err", ":=", "c", ".", "NetworkConfig", ".", "Validate", "(", "onExecution", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Validate is the main entry point for library configuration validation. // The parameter `onExecution` specifies if the validation should include // execution checks. It returns an `error` on validation failure, otherwise // `nil`.
[ "Validate", "is", "the", "main", "entry", "point", "for", "library", "configuration", "validation", ".", "The", "parameter", "onExecution", "specifies", "if", "the", "validation", "should", "include", "execution", "checks", ".", "It", "returns", "an", "error", "on", "validation", "failure", "otherwise", "nil", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/config.go#L422-L436
train
cri-o/cri-o
lib/config.go
Validate
func (c *RootConfig) Validate(onExecution bool) error { if onExecution { if err := os.MkdirAll(c.LogDir, 0700); err != nil { return errors.Wrapf(err, "invalid log_dir") } } return nil }
go
func (c *RootConfig) Validate(onExecution bool) error { if onExecution { if err := os.MkdirAll(c.LogDir, 0700); err != nil { return errors.Wrapf(err, "invalid log_dir") } } return nil }
[ "func", "(", "c", "*", "RootConfig", ")", "Validate", "(", "onExecution", "bool", ")", "error", "{", "if", "onExecution", "{", "if", "err", ":=", "os", ".", "MkdirAll", "(", "c", ".", "LogDir", ",", "0700", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Validate is the main entry point for root configuration validation. // The parameter `onExecution` specifies if the validation should include // execution checks. It returns an `error` on validation failure, otherwise // `nil`.
[ "Validate", "is", "the", "main", "entry", "point", "for", "root", "configuration", "validation", ".", "The", "parameter", "onExecution", "specifies", "if", "the", "validation", "should", "include", "execution", "checks", ".", "It", "returns", "an", "error", "on", "validation", "failure", "otherwise", "nil", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/config.go#L442-L450
train
cri-o/cri-o
lib/config.go
Validate
func (c *RuntimeConfig) Validate(onExecution bool) error { // This is somehow duplicated with server.getUlimitsFromConfig under server/utils.go // but I don't want to export that function for the sake of validation here // so, keep it in mind if things start to blow up. // Reason for having this here is that I don't want people to start crio // with invalid ulimits but realize that only after starting a couple of // containers and watching them fail. for _, u := range c.DefaultUlimits { ul, err := units.ParseUlimit(u) if err != nil { return fmt.Errorf("unrecognized ulimit %s: %v", u, err) } _, err = ul.GetRlimit() if err != nil { return err } } for _, d := range c.AdditionalDevices { split := strings.Split(d, ":") switch len(split) { case 3: if !createconfig.IsValidDeviceMode(split[2]) { return fmt.Errorf("invalid device mode: %s", split[2]) } fallthrough case 2: if (!createconfig.IsValidDeviceMode(split[1]) && !strings.HasPrefix(split[1], "/dev/")) || (len(split) == 3 && createconfig.IsValidDeviceMode(split[1])) { return fmt.Errorf("invalid device mode: %s", split[1]) } fallthrough case 1: if !strings.HasPrefix(split[0], "/dev/") { return fmt.Errorf("invalid device mode: %s", split[0]) } default: return fmt.Errorf("invalid device specification: %s", d) } } // check we do have at least a runtime if _, ok := c.Runtimes[c.DefaultRuntime]; !ok { return errors.New("no default runtime configured") } // check for validation on execution if onExecution { // Validate if runtime_path does exist for each runtime for runtime, handler := range c.Runtimes { if _, err := os.Stat(handler.RuntimePath); os.IsNotExist(err) { return fmt.Errorf("invalid runtime_path for runtime '%s': %q", runtime, err) } logrus.Debugf("found valid runtime '%s' for runtime_path '%s'\n", runtime, handler.RuntimePath) } // Validate the system registries configuration if _, err := sysregistriesv2.GetRegistries(nil); err != nil { return fmt.Errorf("invalid /etc/containers/registries.conf: %q", err) } for _, hooksDir := range c.HooksDir { if _, err := os.Stat(hooksDir); err != nil { return errors.Wrapf(err, "invalid hooks_dir entry") } } if _, err := os.Stat(c.Conmon); err != nil { return errors.Wrapf(err, "invalid conmon path") } } return nil }
go
func (c *RuntimeConfig) Validate(onExecution bool) error { // This is somehow duplicated with server.getUlimitsFromConfig under server/utils.go // but I don't want to export that function for the sake of validation here // so, keep it in mind if things start to blow up. // Reason for having this here is that I don't want people to start crio // with invalid ulimits but realize that only after starting a couple of // containers and watching them fail. for _, u := range c.DefaultUlimits { ul, err := units.ParseUlimit(u) if err != nil { return fmt.Errorf("unrecognized ulimit %s: %v", u, err) } _, err = ul.GetRlimit() if err != nil { return err } } for _, d := range c.AdditionalDevices { split := strings.Split(d, ":") switch len(split) { case 3: if !createconfig.IsValidDeviceMode(split[2]) { return fmt.Errorf("invalid device mode: %s", split[2]) } fallthrough case 2: if (!createconfig.IsValidDeviceMode(split[1]) && !strings.HasPrefix(split[1], "/dev/")) || (len(split) == 3 && createconfig.IsValidDeviceMode(split[1])) { return fmt.Errorf("invalid device mode: %s", split[1]) } fallthrough case 1: if !strings.HasPrefix(split[0], "/dev/") { return fmt.Errorf("invalid device mode: %s", split[0]) } default: return fmt.Errorf("invalid device specification: %s", d) } } // check we do have at least a runtime if _, ok := c.Runtimes[c.DefaultRuntime]; !ok { return errors.New("no default runtime configured") } // check for validation on execution if onExecution { // Validate if runtime_path does exist for each runtime for runtime, handler := range c.Runtimes { if _, err := os.Stat(handler.RuntimePath); os.IsNotExist(err) { return fmt.Errorf("invalid runtime_path for runtime '%s': %q", runtime, err) } logrus.Debugf("found valid runtime '%s' for runtime_path '%s'\n", runtime, handler.RuntimePath) } // Validate the system registries configuration if _, err := sysregistriesv2.GetRegistries(nil); err != nil { return fmt.Errorf("invalid /etc/containers/registries.conf: %q", err) } for _, hooksDir := range c.HooksDir { if _, err := os.Stat(hooksDir); err != nil { return errors.Wrapf(err, "invalid hooks_dir entry") } } if _, err := os.Stat(c.Conmon); err != nil { return errors.Wrapf(err, "invalid conmon path") } } return nil }
[ "func", "(", "c", "*", "RuntimeConfig", ")", "Validate", "(", "onExecution", "bool", ")", "error", "{", "// This is somehow duplicated with server.getUlimitsFromConfig under server/utils.go", "// but I don't want to export that function for the sake of validation here", "// so, keep it in mind if things start to blow up.", "// Reason for having this here is that I don't want people to start crio", "// with invalid ulimits but realize that only after starting a couple of", "// containers and watching them fail.", "for", "_", ",", "u", ":=", "range", "c", ".", "DefaultUlimits", "{", "ul", ",", "err", ":=", "units", ".", "ParseUlimit", "(", "u", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "u", ",", "err", ")", "\n", "}", "\n", "_", ",", "err", "=", "ul", ".", "GetRlimit", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "d", ":=", "range", "c", ".", "AdditionalDevices", "{", "split", ":=", "strings", ".", "Split", "(", "d", ",", "\"", "\"", ")", "\n", "switch", "len", "(", "split", ")", "{", "case", "3", ":", "if", "!", "createconfig", ".", "IsValidDeviceMode", "(", "split", "[", "2", "]", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "split", "[", "2", "]", ")", "\n", "}", "\n", "fallthrough", "\n", "case", "2", ":", "if", "(", "!", "createconfig", ".", "IsValidDeviceMode", "(", "split", "[", "1", "]", ")", "&&", "!", "strings", ".", "HasPrefix", "(", "split", "[", "1", "]", ",", "\"", "\"", ")", ")", "||", "(", "len", "(", "split", ")", "==", "3", "&&", "createconfig", ".", "IsValidDeviceMode", "(", "split", "[", "1", "]", ")", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "split", "[", "1", "]", ")", "\n", "}", "\n", "fallthrough", "\n", "case", "1", ":", "if", "!", "strings", ".", "HasPrefix", "(", "split", "[", "0", "]", ",", "\"", "\"", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "split", "[", "0", "]", ")", "\n", "}", "\n", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "d", ")", "\n", "}", "\n", "}", "\n\n", "// check we do have at least a runtime", "if", "_", ",", "ok", ":=", "c", ".", "Runtimes", "[", "c", ".", "DefaultRuntime", "]", ";", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// check for validation on execution", "if", "onExecution", "{", "// Validate if runtime_path does exist for each runtime", "for", "runtime", ",", "handler", ":=", "range", "c", ".", "Runtimes", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "handler", ".", "RuntimePath", ")", ";", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "runtime", ",", "err", ")", "\n", "}", "\n", "logrus", ".", "Debugf", "(", "\"", "\\n", "\"", ",", "runtime", ",", "handler", ".", "RuntimePath", ")", "\n", "}", "\n\n", "// Validate the system registries configuration", "if", "_", ",", "err", ":=", "sysregistriesv2", ".", "GetRegistries", "(", "nil", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "for", "_", ",", "hooksDir", ":=", "range", "c", ".", "HooksDir", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "hooksDir", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "c", ".", "Conmon", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Validate is the main entry point for runtime configuration validation // The parameter `onExecution` specifies if the validation should include // execution checks. It returns an `error` on validation failure, otherwise // `nil`.
[ "Validate", "is", "the", "main", "entry", "point", "for", "runtime", "configuration", "validation", "The", "parameter", "onExecution", "specifies", "if", "the", "validation", "should", "include", "execution", "checks", ".", "It", "returns", "an", "error", "on", "validation", "failure", "otherwise", "nil", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/config.go#L456-L531
train
cri-o/cri-o
lib/config.go
Validate
func (c *NetworkConfig) Validate(onExecution bool) error { if onExecution { if _, err := os.Stat(c.NetworkDir); err != nil { return errors.Wrapf(err, "invalid network_dir") } for _, pluginDir := range c.PluginDir { if err := os.MkdirAll(pluginDir, 0755); err != nil { return errors.Wrapf(err, "invalid plugin_dir entry") } } } return nil }
go
func (c *NetworkConfig) Validate(onExecution bool) error { if onExecution { if _, err := os.Stat(c.NetworkDir); err != nil { return errors.Wrapf(err, "invalid network_dir") } for _, pluginDir := range c.PluginDir { if err := os.MkdirAll(pluginDir, 0755); err != nil { return errors.Wrapf(err, "invalid plugin_dir entry") } } } return nil }
[ "func", "(", "c", "*", "NetworkConfig", ")", "Validate", "(", "onExecution", "bool", ")", "error", "{", "if", "onExecution", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "c", ".", "NetworkDir", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "for", "_", ",", "pluginDir", ":=", "range", "c", ".", "PluginDir", "{", "if", "err", ":=", "os", ".", "MkdirAll", "(", "pluginDir", ",", "0755", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Validate is the main entry point for network configuration validation. // The parameter `onExecution` specifies if the validation should include // execution checks. It returns an `error` on validation failure, otherwise // `nil`.
[ "Validate", "is", "the", "main", "entry", "point", "for", "network", "configuration", "validation", ".", "The", "parameter", "onExecution", "specifies", "if", "the", "validation", "should", "include", "execution", "checks", ".", "It", "returns", "an", "error", "on", "validation", "failure", "otherwise", "nil", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/config.go#L537-L551
train
cri-o/cri-o
server/sandbox_run.go
privilegedSandbox
func (s *Server) privilegedSandbox(req *pb.RunPodSandboxRequest) bool { securityContext := req.GetConfig().GetLinux().GetSecurityContext() if securityContext == nil { return false } if securityContext.Privileged { return true } namespaceOptions := securityContext.GetNamespaceOptions() if namespaceOptions == nil { return false } if namespaceOptions.GetNetwork() == pb.NamespaceMode_NODE || namespaceOptions.GetPid() == pb.NamespaceMode_NODE || namespaceOptions.GetIpc() == pb.NamespaceMode_NODE { return true } return false }
go
func (s *Server) privilegedSandbox(req *pb.RunPodSandboxRequest) bool { securityContext := req.GetConfig().GetLinux().GetSecurityContext() if securityContext == nil { return false } if securityContext.Privileged { return true } namespaceOptions := securityContext.GetNamespaceOptions() if namespaceOptions == nil { return false } if namespaceOptions.GetNetwork() == pb.NamespaceMode_NODE || namespaceOptions.GetPid() == pb.NamespaceMode_NODE || namespaceOptions.GetIpc() == pb.NamespaceMode_NODE { return true } return false }
[ "func", "(", "s", "*", "Server", ")", "privilegedSandbox", "(", "req", "*", "pb", ".", "RunPodSandboxRequest", ")", "bool", "{", "securityContext", ":=", "req", ".", "GetConfig", "(", ")", ".", "GetLinux", "(", ")", ".", "GetSecurityContext", "(", ")", "\n", "if", "securityContext", "==", "nil", "{", "return", "false", "\n", "}", "\n\n", "if", "securityContext", ".", "Privileged", "{", "return", "true", "\n", "}", "\n\n", "namespaceOptions", ":=", "securityContext", ".", "GetNamespaceOptions", "(", ")", "\n", "if", "namespaceOptions", "==", "nil", "{", "return", "false", "\n", "}", "\n\n", "if", "namespaceOptions", ".", "GetNetwork", "(", ")", "==", "pb", ".", "NamespaceMode_NODE", "||", "namespaceOptions", ".", "GetPid", "(", ")", "==", "pb", ".", "NamespaceMode_NODE", "||", "namespaceOptions", ".", "GetIpc", "(", ")", "==", "pb", ".", "NamespaceMode_NODE", "{", "return", "true", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// privilegedSandbox returns true if the sandbox configuration // requires additional host privileges for the sandbox.
[ "privilegedSandbox", "returns", "true", "if", "the", "sandbox", "configuration", "requires", "additional", "host", "privileges", "for", "the", "sandbox", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/sandbox_run.go#L28-L50
train
cri-o/cri-o
server/sandbox_run.go
runtimeHandler
func (s *Server) runtimeHandler(req *pb.RunPodSandboxRequest) (string, error) { handler := req.GetRuntimeHandler() if handler == "" { return handler, nil } runtime, ok := s.Runtime().(*oci.Runtime) if !ok { return "", fmt.Errorf("runtime interface conversion error") } if _, err := runtime.ValidateRuntimeHandler(handler); err != nil { return "", err } return handler, nil }
go
func (s *Server) runtimeHandler(req *pb.RunPodSandboxRequest) (string, error) { handler := req.GetRuntimeHandler() if handler == "" { return handler, nil } runtime, ok := s.Runtime().(*oci.Runtime) if !ok { return "", fmt.Errorf("runtime interface conversion error") } if _, err := runtime.ValidateRuntimeHandler(handler); err != nil { return "", err } return handler, nil }
[ "func", "(", "s", "*", "Server", ")", "runtimeHandler", "(", "req", "*", "pb", ".", "RunPodSandboxRequest", ")", "(", "string", ",", "error", ")", "{", "handler", ":=", "req", ".", "GetRuntimeHandler", "(", ")", "\n", "if", "handler", "==", "\"", "\"", "{", "return", "handler", ",", "nil", "\n", "}", "\n\n", "runtime", ",", "ok", ":=", "s", ".", "Runtime", "(", ")", ".", "(", "*", "oci", ".", "Runtime", ")", "\n", "if", "!", "ok", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "runtime", ".", "ValidateRuntimeHandler", "(", "handler", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "handler", ",", "nil", "\n", "}" ]
// runtimeHandler returns the runtime handler key provided by CRI if the key // does exist and the associated data are valid. If the key is empty, there // is nothing to do, and the empty key is returned. For every other case, this // function will return an empty string with the error associated.
[ "runtimeHandler", "returns", "the", "runtime", "handler", "key", "provided", "by", "CRI", "if", "the", "key", "does", "exist", "and", "the", "associated", "data", "are", "valid", ".", "If", "the", "key", "is", "empty", "there", "is", "nothing", "to", "do", "and", "the", "empty", "key", "is", "returned", ".", "For", "every", "other", "case", "this", "function", "will", "return", "an", "empty", "string", "with", "the", "error", "associated", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/sandbox_run.go#L56-L72
train
cri-o/cri-o
server/sandbox_run.go
RunPodSandbox
func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest) (resp *pb.RunPodSandboxResponse, err error) { // platform dependent call return s.runPodSandbox(ctx, req) }
go
func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest) (resp *pb.RunPodSandboxResponse, err error) { // platform dependent call return s.runPodSandbox(ctx, req) }
[ "func", "(", "s", "*", "Server", ")", "RunPodSandbox", "(", "ctx", "context", ".", "Context", ",", "req", "*", "pb", ".", "RunPodSandboxRequest", ")", "(", "resp", "*", "pb", ".", "RunPodSandboxResponse", ",", "err", "error", ")", "{", "// platform dependent call", "return", "s", ".", "runPodSandbox", "(", "ctx", ",", "req", ")", "\n", "}" ]
// RunPodSandbox creates and runs a pod-level sandbox.
[ "RunPodSandbox", "creates", "and", "runs", "a", "pod", "-", "level", "sandbox", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/sandbox_run.go#L79-L82
train
cri-o/cri-o
server/sandbox_stop.go
StopPodSandbox
func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxRequest) (resp *pb.StopPodSandboxResponse, err error) { // platform dependent call return s.stopPodSandbox(ctx, req) }
go
func (s *Server) StopPodSandbox(ctx context.Context, req *pb.StopPodSandboxRequest) (resp *pb.StopPodSandboxResponse, err error) { // platform dependent call return s.stopPodSandbox(ctx, req) }
[ "func", "(", "s", "*", "Server", ")", "StopPodSandbox", "(", "ctx", "context", ".", "Context", ",", "req", "*", "pb", ".", "StopPodSandboxRequest", ")", "(", "resp", "*", "pb", ".", "StopPodSandboxResponse", ",", "err", "error", ")", "{", "// platform dependent call", "return", "s", ".", "stopPodSandbox", "(", "ctx", ",", "req", ")", "\n", "}" ]
// StopPodSandbox stops the sandbox. If there are any running containers in the // sandbox, they should be force terminated.
[ "StopPodSandbox", "stops", "the", "sandbox", ".", "If", "there", "are", "any", "running", "containers", "in", "the", "sandbox", "they", "should", "be", "force", "terminated", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/sandbox_stop.go#L11-L14
train
cri-o/cri-o
server/sandbox_stop.go
stopAllPodSandboxes
func (s *Server) stopAllPodSandboxes(ctx context.Context) { logrus.Debugf("stopAllPodSandboxes") for _, sb := range s.ContainerServer.ListSandboxes() { pod := &pb.StopPodSandboxRequest{ PodSandboxId: sb.ID(), } if _, err := s.StopPodSandbox(ctx, pod); err != nil { logrus.Warnf("could not StopPodSandbox %s: %v", sb.ID(), err) } } }
go
func (s *Server) stopAllPodSandboxes(ctx context.Context) { logrus.Debugf("stopAllPodSandboxes") for _, sb := range s.ContainerServer.ListSandboxes() { pod := &pb.StopPodSandboxRequest{ PodSandboxId: sb.ID(), } if _, err := s.StopPodSandbox(ctx, pod); err != nil { logrus.Warnf("could not StopPodSandbox %s: %v", sb.ID(), err) } } }
[ "func", "(", "s", "*", "Server", ")", "stopAllPodSandboxes", "(", "ctx", "context", ".", "Context", ")", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ")", "\n", "for", "_", ",", "sb", ":=", "range", "s", ".", "ContainerServer", ".", "ListSandboxes", "(", ")", "{", "pod", ":=", "&", "pb", ".", "StopPodSandboxRequest", "{", "PodSandboxId", ":", "sb", ".", "ID", "(", ")", ",", "}", "\n", "if", "_", ",", "err", ":=", "s", ".", "StopPodSandbox", "(", "ctx", ",", "pod", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "sb", ".", "ID", "(", ")", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}" ]
// stopAllPodSandboxes removes all pod sandboxes
[ "stopAllPodSandboxes", "removes", "all", "pod", "sandboxes" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/sandbox_stop.go#L17-L27
train
cri-o/cri-o
lib/container_server.go
localeToLanguage
func localeToLanguage(locale string) string { locale = strings.Replace(strings.SplitN(locale, ".", 2)[0], "_", "-", 1) langString, ok := localeToLanguageMap[strings.ToLower(locale)] if !ok { langString = locale } return langString }
go
func localeToLanguage(locale string) string { locale = strings.Replace(strings.SplitN(locale, ".", 2)[0], "_", "-", 1) langString, ok := localeToLanguageMap[strings.ToLower(locale)] if !ok { langString = locale } return langString }
[ "func", "localeToLanguage", "(", "locale", "string", ")", "string", "{", "locale", "=", "strings", ".", "Replace", "(", "strings", ".", "SplitN", "(", "locale", ",", "\"", "\"", ",", "2", ")", "[", "0", "]", ",", "\"", "\"", ",", "\"", "\"", ",", "1", ")", "\n", "langString", ",", "ok", ":=", "localeToLanguageMap", "[", "strings", ".", "ToLower", "(", "locale", ")", "]", "\n", "if", "!", "ok", "{", "langString", "=", "locale", "\n", "}", "\n", "return", "langString", "\n", "}" ]
// localeToLanguage translates POSIX locale strings to BCP 47 language tags.
[ "localeToLanguage", "translates", "POSIX", "locale", "strings", "to", "BCP", "47", "language", "tags", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L111-L118
train
cri-o/cri-o
lib/container_server.go
ContainerStateFromDisk
func (c *ContainerServer) ContainerStateFromDisk(ctr *oci.Container) error { if err := ctr.FromDisk(); err != nil { return err } // ignore errors, this is a best effort to have up-to-date info about // a given container before its state gets stored c.runtime.UpdateContainerStatus(ctr) return nil }
go
func (c *ContainerServer) ContainerStateFromDisk(ctr *oci.Container) error { if err := ctr.FromDisk(); err != nil { return err } // ignore errors, this is a best effort to have up-to-date info about // a given container before its state gets stored c.runtime.UpdateContainerStatus(ctr) return nil }
[ "func", "(", "c", "*", "ContainerServer", ")", "ContainerStateFromDisk", "(", "ctr", "*", "oci", ".", "Container", ")", "error", "{", "if", "err", ":=", "ctr", ".", "FromDisk", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// ignore errors, this is a best effort to have up-to-date info about", "// a given container before its state gets stored", "c", ".", "runtime", ".", "UpdateContainerStatus", "(", "ctr", ")", "\n\n", "return", "nil", "\n", "}" ]
// ContainerStateFromDisk retrieves information on the state of a running container // from the disk
[ "ContainerStateFromDisk", "retrieves", "information", "on", "the", "state", "of", "a", "running", "container", "from", "the", "disk" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L599-L608
train
cri-o/cri-o
lib/container_server.go
ContainerStateToDisk
func (c *ContainerServer) ContainerStateToDisk(ctr *oci.Container) error { // ignore errors, this is a best effort to have up-to-date info about // a given container before its state gets stored c.Runtime().UpdateContainerStatus(ctr) jsonSource, err := ioutils.NewAtomicFileWriter(ctr.StatePath(), 0644) if err != nil { return err } defer jsonSource.Close() enc := json.NewEncoder(jsonSource) return enc.Encode(ctr.State()) }
go
func (c *ContainerServer) ContainerStateToDisk(ctr *oci.Container) error { // ignore errors, this is a best effort to have up-to-date info about // a given container before its state gets stored c.Runtime().UpdateContainerStatus(ctr) jsonSource, err := ioutils.NewAtomicFileWriter(ctr.StatePath(), 0644) if err != nil { return err } defer jsonSource.Close() enc := json.NewEncoder(jsonSource) return enc.Encode(ctr.State()) }
[ "func", "(", "c", "*", "ContainerServer", ")", "ContainerStateToDisk", "(", "ctr", "*", "oci", ".", "Container", ")", "error", "{", "// ignore errors, this is a best effort to have up-to-date info about", "// a given container before its state gets stored", "c", ".", "Runtime", "(", ")", ".", "UpdateContainerStatus", "(", "ctr", ")", "\n\n", "jsonSource", ",", "err", ":=", "ioutils", ".", "NewAtomicFileWriter", "(", "ctr", ".", "StatePath", "(", ")", ",", "0644", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "jsonSource", ".", "Close", "(", ")", "\n", "enc", ":=", "json", ".", "NewEncoder", "(", "jsonSource", ")", "\n", "return", "enc", ".", "Encode", "(", "ctr", ".", "State", "(", ")", ")", "\n", "}" ]
// ContainerStateToDisk writes the container's state information to a JSON file // on disk
[ "ContainerStateToDisk", "writes", "the", "container", "s", "state", "information", "to", "a", "JSON", "file", "on", "disk" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L612-L624
train
cri-o/cri-o
lib/container_server.go
ReserveContainerName
func (c *ContainerServer) ReserveContainerName(id, name string) (string, error) { if err := c.ctrNameIndex.Reserve(name, id); err != nil { err = fmt.Errorf("error reserving ctr name %s for id %s", name, id) logrus.Warn(err) return "", err } return name, nil }
go
func (c *ContainerServer) ReserveContainerName(id, name string) (string, error) { if err := c.ctrNameIndex.Reserve(name, id); err != nil { err = fmt.Errorf("error reserving ctr name %s for id %s", name, id) logrus.Warn(err) return "", err } return name, nil }
[ "func", "(", "c", "*", "ContainerServer", ")", "ReserveContainerName", "(", "id", ",", "name", "string", ")", "(", "string", ",", "error", ")", "{", "if", "err", ":=", "c", ".", "ctrNameIndex", ".", "Reserve", "(", "name", ",", "id", ")", ";", "err", "!=", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ",", "id", ")", "\n", "logrus", ".", "Warn", "(", "err", ")", "\n", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "name", ",", "nil", "\n", "}" ]
// ReserveContainerName holds a name for a container that is being created
[ "ReserveContainerName", "holds", "a", "name", "for", "a", "container", "that", "is", "being", "created" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L627-L634
train
cri-o/cri-o
lib/container_server.go
ReservePodName
func (c *ContainerServer) ReservePodName(id, name string) (string, error) { if err := c.podNameIndex.Reserve(name, id); err != nil { err = fmt.Errorf("error reserving pod name %s for id %s", name, id) logrus.Warn(err) return "", err } return name, nil }
go
func (c *ContainerServer) ReservePodName(id, name string) (string, error) { if err := c.podNameIndex.Reserve(name, id); err != nil { err = fmt.Errorf("error reserving pod name %s for id %s", name, id) logrus.Warn(err) return "", err } return name, nil }
[ "func", "(", "c", "*", "ContainerServer", ")", "ReservePodName", "(", "id", ",", "name", "string", ")", "(", "string", ",", "error", ")", "{", "if", "err", ":=", "c", ".", "podNameIndex", ".", "Reserve", "(", "name", ",", "id", ")", ";", "err", "!=", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ",", "id", ")", "\n", "logrus", ".", "Warn", "(", "err", ")", "\n", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "name", ",", "nil", "\n", "}" ]
// ReservePodName holds a name for a pod that is being created
[ "ReservePodName", "holds", "a", "name", "for", "a", "pod", "that", "is", "being", "created" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L643-L650
train
cri-o/cri-o
lib/container_server.go
AddContainer
func (c *ContainerServer) AddContainer(ctr *oci.Container) { sandbox := c.state.sandboxes.Get(ctr.Sandbox()) if sandbox == nil { return } sandbox.AddContainer(ctr) c.state.containers.Add(ctr.ID(), ctr) }
go
func (c *ContainerServer) AddContainer(ctr *oci.Container) { sandbox := c.state.sandboxes.Get(ctr.Sandbox()) if sandbox == nil { return } sandbox.AddContainer(ctr) c.state.containers.Add(ctr.ID(), ctr) }
[ "func", "(", "c", "*", "ContainerServer", ")", "AddContainer", "(", "ctr", "*", "oci", ".", "Container", ")", "{", "sandbox", ":=", "c", ".", "state", ".", "sandboxes", ".", "Get", "(", "ctr", ".", "Sandbox", "(", ")", ")", "\n", "if", "sandbox", "==", "nil", "{", "return", "\n", "}", "\n", "sandbox", ".", "AddContainer", "(", "ctr", ")", "\n", "c", ".", "state", ".", "containers", ".", "Add", "(", "ctr", ".", "ID", "(", ")", ",", "ctr", ")", "\n", "}" ]
// AddContainer adds a container to the container state store
[ "AddContainer", "adds", "a", "container", "to", "the", "container", "state", "store" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L676-L683
train
cri-o/cri-o
lib/container_server.go
AddInfraContainer
func (c *ContainerServer) AddInfraContainer(ctr *oci.Container) { c.state.infraContainers.Add(ctr.ID(), ctr) }
go
func (c *ContainerServer) AddInfraContainer(ctr *oci.Container) { c.state.infraContainers.Add(ctr.ID(), ctr) }
[ "func", "(", "c", "*", "ContainerServer", ")", "AddInfraContainer", "(", "ctr", "*", "oci", ".", "Container", ")", "{", "c", ".", "state", ".", "infraContainers", ".", "Add", "(", "ctr", ".", "ID", "(", ")", ",", "ctr", ")", "\n", "}" ]
// AddInfraContainer adds a container to the container state store
[ "AddInfraContainer", "adds", "a", "container", "to", "the", "container", "state", "store" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L686-L688
train
cri-o/cri-o
lib/container_server.go
GetContainer
func (c *ContainerServer) GetContainer(id string) *oci.Container { return c.state.containers.Get(id) }
go
func (c *ContainerServer) GetContainer(id string) *oci.Container { return c.state.containers.Get(id) }
[ "func", "(", "c", "*", "ContainerServer", ")", "GetContainer", "(", "id", "string", ")", "*", "oci", ".", "Container", "{", "return", "c", ".", "state", ".", "containers", ".", "Get", "(", "id", ")", "\n", "}" ]
// GetContainer returns a container by its ID
[ "GetContainer", "returns", "a", "container", "by", "its", "ID" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L691-L693
train
cri-o/cri-o
lib/container_server.go
GetInfraContainer
func (c *ContainerServer) GetInfraContainer(id string) *oci.Container { return c.state.infraContainers.Get(id) }
go
func (c *ContainerServer) GetInfraContainer(id string) *oci.Container { return c.state.infraContainers.Get(id) }
[ "func", "(", "c", "*", "ContainerServer", ")", "GetInfraContainer", "(", "id", "string", ")", "*", "oci", ".", "Container", "{", "return", "c", ".", "state", ".", "infraContainers", ".", "Get", "(", "id", ")", "\n", "}" ]
// GetInfraContainer returns a container by its ID
[ "GetInfraContainer", "returns", "a", "container", "by", "its", "ID" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L696-L698
train
cri-o/cri-o
lib/container_server.go
HasContainer
func (c *ContainerServer) HasContainer(id string) bool { return c.state.containers.Get(id) != nil }
go
func (c *ContainerServer) HasContainer(id string) bool { return c.state.containers.Get(id) != nil }
[ "func", "(", "c", "*", "ContainerServer", ")", "HasContainer", "(", "id", "string", ")", "bool", "{", "return", "c", ".", "state", ".", "containers", ".", "Get", "(", "id", ")", "!=", "nil", "\n", "}" ]
// HasContainer checks if a container exists in the state
[ "HasContainer", "checks", "if", "a", "container", "exists", "in", "the", "state" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L701-L703
train
cri-o/cri-o
lib/container_server.go
RemoveContainer
func (c *ContainerServer) RemoveContainer(ctr *oci.Container) { sbID := ctr.Sandbox() sb := c.state.sandboxes.Get(sbID) if sb == nil { return } sb.RemoveContainer(ctr) c.state.containers.Delete(ctr.ID()) }
go
func (c *ContainerServer) RemoveContainer(ctr *oci.Container) { sbID := ctr.Sandbox() sb := c.state.sandboxes.Get(sbID) if sb == nil { return } sb.RemoveContainer(ctr) c.state.containers.Delete(ctr.ID()) }
[ "func", "(", "c", "*", "ContainerServer", ")", "RemoveContainer", "(", "ctr", "*", "oci", ".", "Container", ")", "{", "sbID", ":=", "ctr", ".", "Sandbox", "(", ")", "\n", "sb", ":=", "c", ".", "state", ".", "sandboxes", ".", "Get", "(", "sbID", ")", "\n", "if", "sb", "==", "nil", "{", "return", "\n", "}", "\n", "sb", ".", "RemoveContainer", "(", "ctr", ")", "\n", "c", ".", "state", ".", "containers", ".", "Delete", "(", "ctr", ".", "ID", "(", ")", ")", "\n", "}" ]
// RemoveContainer removes a container from the container state store
[ "RemoveContainer", "removes", "a", "container", "from", "the", "container", "state", "store" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L706-L714
train
cri-o/cri-o
lib/container_server.go
RemoveInfraContainer
func (c *ContainerServer) RemoveInfraContainer(ctr *oci.Container) { c.state.infraContainers.Delete(ctr.ID()) }
go
func (c *ContainerServer) RemoveInfraContainer(ctr *oci.Container) { c.state.infraContainers.Delete(ctr.ID()) }
[ "func", "(", "c", "*", "ContainerServer", ")", "RemoveInfraContainer", "(", "ctr", "*", "oci", ".", "Container", ")", "{", "c", ".", "state", ".", "infraContainers", ".", "Delete", "(", "ctr", ".", "ID", "(", ")", ")", "\n", "}" ]
// RemoveInfraContainer removes a container from the container state store
[ "RemoveInfraContainer", "removes", "a", "container", "from", "the", "container", "state", "store" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L717-L719
train
cri-o/cri-o
lib/container_server.go
ListContainers
func (c *ContainerServer) ListContainers(filters ...func(*oci.Container) bool) ([]*oci.Container, error) { containers := c.listContainers() if len(filters) == 0 { return containers, nil } filteredContainers := make([]*oci.Container, 0, len(containers)) for _, container := range containers { for _, filter := range filters { if filter(container) { filteredContainers = append(filteredContainers, container) } } } return filteredContainers, nil }
go
func (c *ContainerServer) ListContainers(filters ...func(*oci.Container) bool) ([]*oci.Container, error) { containers := c.listContainers() if len(filters) == 0 { return containers, nil } filteredContainers := make([]*oci.Container, 0, len(containers)) for _, container := range containers { for _, filter := range filters { if filter(container) { filteredContainers = append(filteredContainers, container) } } } return filteredContainers, nil }
[ "func", "(", "c", "*", "ContainerServer", ")", "ListContainers", "(", "filters", "...", "func", "(", "*", "oci", ".", "Container", ")", "bool", ")", "(", "[", "]", "*", "oci", ".", "Container", ",", "error", ")", "{", "containers", ":=", "c", ".", "listContainers", "(", ")", "\n", "if", "len", "(", "filters", ")", "==", "0", "{", "return", "containers", ",", "nil", "\n", "}", "\n", "filteredContainers", ":=", "make", "(", "[", "]", "*", "oci", ".", "Container", ",", "0", ",", "len", "(", "containers", ")", ")", "\n", "for", "_", ",", "container", ":=", "range", "containers", "{", "for", "_", ",", "filter", ":=", "range", "filters", "{", "if", "filter", "(", "container", ")", "{", "filteredContainers", "=", "append", "(", "filteredContainers", ",", "container", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "filteredContainers", ",", "nil", "\n", "}" ]
// ListContainers returns a list of all containers stored by the server state // that match the given filter function
[ "ListContainers", "returns", "a", "list", "of", "all", "containers", "stored", "by", "the", "server", "state", "that", "match", "the", "given", "filter", "function" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L728-L742
train
cri-o/cri-o
lib/container_server.go
AddSandbox
func (c *ContainerServer) AddSandbox(sb *sandbox.Sandbox) error { c.state.sandboxes.Add(sb.ID(), sb) c.stateLock.Lock() defer c.stateLock.Unlock() return c.addSandboxPlatform(sb) }
go
func (c *ContainerServer) AddSandbox(sb *sandbox.Sandbox) error { c.state.sandboxes.Add(sb.ID(), sb) c.stateLock.Lock() defer c.stateLock.Unlock() return c.addSandboxPlatform(sb) }
[ "func", "(", "c", "*", "ContainerServer", ")", "AddSandbox", "(", "sb", "*", "sandbox", ".", "Sandbox", ")", "error", "{", "c", ".", "state", ".", "sandboxes", ".", "Add", "(", "sb", ".", "ID", "(", ")", ",", "sb", ")", "\n\n", "c", ".", "stateLock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "stateLock", ".", "Unlock", "(", ")", "\n", "return", "c", ".", "addSandboxPlatform", "(", "sb", ")", "\n", "}" ]
// AddSandbox adds a sandbox to the sandbox state store
[ "AddSandbox", "adds", "a", "sandbox", "to", "the", "sandbox", "state", "store" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L745-L751
train
cri-o/cri-o
lib/container_server.go
GetSandbox
func (c *ContainerServer) GetSandbox(id string) *sandbox.Sandbox { return c.state.sandboxes.Get(id) }
go
func (c *ContainerServer) GetSandbox(id string) *sandbox.Sandbox { return c.state.sandboxes.Get(id) }
[ "func", "(", "c", "*", "ContainerServer", ")", "GetSandbox", "(", "id", "string", ")", "*", "sandbox", ".", "Sandbox", "{", "return", "c", ".", "state", ".", "sandboxes", ".", "Get", "(", "id", ")", "\n", "}" ]
// GetSandbox returns a sandbox by its ID
[ "GetSandbox", "returns", "a", "sandbox", "by", "its", "ID" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L754-L756
train
cri-o/cri-o
lib/container_server.go
GetSandboxContainer
func (c *ContainerServer) GetSandboxContainer(id string) *oci.Container { sb := c.state.sandboxes.Get(id) if sb == nil { return nil } return sb.InfraContainer() }
go
func (c *ContainerServer) GetSandboxContainer(id string) *oci.Container { sb := c.state.sandboxes.Get(id) if sb == nil { return nil } return sb.InfraContainer() }
[ "func", "(", "c", "*", "ContainerServer", ")", "GetSandboxContainer", "(", "id", "string", ")", "*", "oci", ".", "Container", "{", "sb", ":=", "c", ".", "state", ".", "sandboxes", ".", "Get", "(", "id", ")", "\n", "if", "sb", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "sb", ".", "InfraContainer", "(", ")", "\n", "}" ]
// GetSandboxContainer returns a sandbox's infra container
[ "GetSandboxContainer", "returns", "a", "sandbox", "s", "infra", "container" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L759-L765
train
cri-o/cri-o
lib/container_server.go
HasSandbox
func (c *ContainerServer) HasSandbox(id string) bool { return c.state.sandboxes.Get(id) != nil }
go
func (c *ContainerServer) HasSandbox(id string) bool { return c.state.sandboxes.Get(id) != nil }
[ "func", "(", "c", "*", "ContainerServer", ")", "HasSandbox", "(", "id", "string", ")", "bool", "{", "return", "c", ".", "state", ".", "sandboxes", ".", "Get", "(", "id", ")", "!=", "nil", "\n", "}" ]
// HasSandbox checks if a sandbox exists in the state
[ "HasSandbox", "checks", "if", "a", "sandbox", "exists", "in", "the", "state" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L768-L770
train
cri-o/cri-o
lib/container_server.go
RemoveSandbox
func (c *ContainerServer) RemoveSandbox(id string) error { sb := c.state.sandboxes.Get(id) if sb == nil { return nil } c.stateLock.Lock() defer c.stateLock.Unlock() if err := c.removeSandboxPlatform(sb); err != nil { return err } c.state.sandboxes.Delete(id) return nil }
go
func (c *ContainerServer) RemoveSandbox(id string) error { sb := c.state.sandboxes.Get(id) if sb == nil { return nil } c.stateLock.Lock() defer c.stateLock.Unlock() if err := c.removeSandboxPlatform(sb); err != nil { return err } c.state.sandboxes.Delete(id) return nil }
[ "func", "(", "c", "*", "ContainerServer", ")", "RemoveSandbox", "(", "id", "string", ")", "error", "{", "sb", ":=", "c", ".", "state", ".", "sandboxes", ".", "Get", "(", "id", ")", "\n", "if", "sb", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "c", ".", "stateLock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "stateLock", ".", "Unlock", "(", ")", "\n", "if", "err", ":=", "c", ".", "removeSandboxPlatform", "(", "sb", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "c", ".", "state", ".", "sandboxes", ".", "Delete", "(", "id", ")", "\n", "return", "nil", "\n", "}" ]
// RemoveSandbox removes a sandbox from the state store
[ "RemoveSandbox", "removes", "a", "sandbox", "from", "the", "state", "store" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/container_server.go#L773-L787
train
cri-o/cri-o
server/sandbox_status.go
PodSandboxStatus
func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusRequest) (resp *pb.PodSandboxStatusResponse, err error) { const operation = "pod_sandbox_status" defer func() { recordOperation(operation, time.Now()) recordError(operation, err) }() logrus.Debugf("PodSandboxStatusRequest %+v", req) sb, err := s.getPodSandboxFromRequest(req.PodSandboxId) if err != nil { return nil, err } podInfraContainer := sb.InfraContainer() cState := podInfraContainer.State() rStatus := pb.PodSandboxState_SANDBOX_NOTREADY if cState.Status == oci.ContainerStateRunning { rStatus = pb.PodSandboxState_SANDBOX_READY } linux := &pb.LinuxPodSandboxStatus{ Namespaces: &pb.Namespace{ Options: &pb.NamespaceOption{ Network: sb.NamespaceOptions().GetNetwork(), Ipc: sb.NamespaceOptions().GetIpc(), Pid: sb.NamespaceOptions().GetPid(), }, }, } sandboxID := sb.ID() resp = &pb.PodSandboxStatusResponse{ Status: &pb.PodSandboxStatus{ Id: sandboxID, CreatedAt: podInfraContainer.CreatedAt().UnixNano(), Network: &pb.PodSandboxNetworkStatus{Ip: sb.IP()}, State: rStatus, Labels: sb.Labels(), Annotations: sb.Annotations(), Metadata: sb.Metadata(), Linux: linux, }, } logrus.Debugf("PodSandboxStatusResponse: %+v", resp) return resp, nil }
go
func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusRequest) (resp *pb.PodSandboxStatusResponse, err error) { const operation = "pod_sandbox_status" defer func() { recordOperation(operation, time.Now()) recordError(operation, err) }() logrus.Debugf("PodSandboxStatusRequest %+v", req) sb, err := s.getPodSandboxFromRequest(req.PodSandboxId) if err != nil { return nil, err } podInfraContainer := sb.InfraContainer() cState := podInfraContainer.State() rStatus := pb.PodSandboxState_SANDBOX_NOTREADY if cState.Status == oci.ContainerStateRunning { rStatus = pb.PodSandboxState_SANDBOX_READY } linux := &pb.LinuxPodSandboxStatus{ Namespaces: &pb.Namespace{ Options: &pb.NamespaceOption{ Network: sb.NamespaceOptions().GetNetwork(), Ipc: sb.NamespaceOptions().GetIpc(), Pid: sb.NamespaceOptions().GetPid(), }, }, } sandboxID := sb.ID() resp = &pb.PodSandboxStatusResponse{ Status: &pb.PodSandboxStatus{ Id: sandboxID, CreatedAt: podInfraContainer.CreatedAt().UnixNano(), Network: &pb.PodSandboxNetworkStatus{Ip: sb.IP()}, State: rStatus, Labels: sb.Labels(), Annotations: sb.Annotations(), Metadata: sb.Metadata(), Linux: linux, }, } logrus.Debugf("PodSandboxStatusResponse: %+v", resp) return resp, nil }
[ "func", "(", "s", "*", "Server", ")", "PodSandboxStatus", "(", "ctx", "context", ".", "Context", ",", "req", "*", "pb", ".", "PodSandboxStatusRequest", ")", "(", "resp", "*", "pb", ".", "PodSandboxStatusResponse", ",", "err", "error", ")", "{", "const", "operation", "=", "\"", "\"", "\n", "defer", "func", "(", ")", "{", "recordOperation", "(", "operation", ",", "time", ".", "Now", "(", ")", ")", "\n", "recordError", "(", "operation", ",", "err", ")", "\n", "}", "(", ")", "\n\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "req", ")", "\n", "sb", ",", "err", ":=", "s", ".", "getPodSandboxFromRequest", "(", "req", ".", "PodSandboxId", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "podInfraContainer", ":=", "sb", ".", "InfraContainer", "(", ")", "\n", "cState", ":=", "podInfraContainer", ".", "State", "(", ")", "\n\n", "rStatus", ":=", "pb", ".", "PodSandboxState_SANDBOX_NOTREADY", "\n", "if", "cState", ".", "Status", "==", "oci", ".", "ContainerStateRunning", "{", "rStatus", "=", "pb", ".", "PodSandboxState_SANDBOX_READY", "\n", "}", "\n\n", "linux", ":=", "&", "pb", ".", "LinuxPodSandboxStatus", "{", "Namespaces", ":", "&", "pb", ".", "Namespace", "{", "Options", ":", "&", "pb", ".", "NamespaceOption", "{", "Network", ":", "sb", ".", "NamespaceOptions", "(", ")", ".", "GetNetwork", "(", ")", ",", "Ipc", ":", "sb", ".", "NamespaceOptions", "(", ")", ".", "GetIpc", "(", ")", ",", "Pid", ":", "sb", ".", "NamespaceOptions", "(", ")", ".", "GetPid", "(", ")", ",", "}", ",", "}", ",", "}", "\n\n", "sandboxID", ":=", "sb", ".", "ID", "(", ")", "\n", "resp", "=", "&", "pb", ".", "PodSandboxStatusResponse", "{", "Status", ":", "&", "pb", ".", "PodSandboxStatus", "{", "Id", ":", "sandboxID", ",", "CreatedAt", ":", "podInfraContainer", ".", "CreatedAt", "(", ")", ".", "UnixNano", "(", ")", ",", "Network", ":", "&", "pb", ".", "PodSandboxNetworkStatus", "{", "Ip", ":", "sb", ".", "IP", "(", ")", "}", ",", "State", ":", "rStatus", ",", "Labels", ":", "sb", ".", "Labels", "(", ")", ",", "Annotations", ":", "sb", ".", "Annotations", "(", ")", ",", "Metadata", ":", "sb", ".", "Metadata", "(", ")", ",", "Linux", ":", "linux", ",", "}", ",", "}", "\n\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "resp", ")", "\n", "return", "resp", ",", "nil", "\n", "}" ]
// PodSandboxStatus returns the Status of the PodSandbox.
[ "PodSandboxStatus", "returns", "the", "Status", "of", "the", "PodSandbox", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/sandbox_status.go#L13-L60
train
cri-o/cri-o
server/runtime_status.go
Status
func (s *Server) Status(ctx context.Context, req *pb.StatusRequest) (resp *pb.StatusResponse, err error) { const operation = "status" defer func() { recordOperation(operation, time.Now()) recordError(operation, err) }() runtimeCondition := &pb.RuntimeCondition{ Type: pb.RuntimeReady, Status: true, } networkCondition := &pb.RuntimeCondition{ Type: pb.NetworkReady, Status: true, } if err := s.netPlugin.Status(); err != nil { networkCondition.Status = false networkCondition.Reason = networkNotReadyReason networkCondition.Message = fmt.Sprintf("Network plugin returns error: %v", err) } resp = &pb.StatusResponse{ Status: &pb.RuntimeStatus{ Conditions: []*pb.RuntimeCondition{ runtimeCondition, networkCondition, }, }, } return resp, nil }
go
func (s *Server) Status(ctx context.Context, req *pb.StatusRequest) (resp *pb.StatusResponse, err error) { const operation = "status" defer func() { recordOperation(operation, time.Now()) recordError(operation, err) }() runtimeCondition := &pb.RuntimeCondition{ Type: pb.RuntimeReady, Status: true, } networkCondition := &pb.RuntimeCondition{ Type: pb.NetworkReady, Status: true, } if err := s.netPlugin.Status(); err != nil { networkCondition.Status = false networkCondition.Reason = networkNotReadyReason networkCondition.Message = fmt.Sprintf("Network plugin returns error: %v", err) } resp = &pb.StatusResponse{ Status: &pb.RuntimeStatus{ Conditions: []*pb.RuntimeCondition{ runtimeCondition, networkCondition, }, }, } return resp, nil }
[ "func", "(", "s", "*", "Server", ")", "Status", "(", "ctx", "context", ".", "Context", ",", "req", "*", "pb", ".", "StatusRequest", ")", "(", "resp", "*", "pb", ".", "StatusResponse", ",", "err", "error", ")", "{", "const", "operation", "=", "\"", "\"", "\n", "defer", "func", "(", ")", "{", "recordOperation", "(", "operation", ",", "time", ".", "Now", "(", ")", ")", "\n", "recordError", "(", "operation", ",", "err", ")", "\n", "}", "(", ")", "\n\n", "runtimeCondition", ":=", "&", "pb", ".", "RuntimeCondition", "{", "Type", ":", "pb", ".", "RuntimeReady", ",", "Status", ":", "true", ",", "}", "\n", "networkCondition", ":=", "&", "pb", ".", "RuntimeCondition", "{", "Type", ":", "pb", ".", "NetworkReady", ",", "Status", ":", "true", ",", "}", "\n\n", "if", "err", ":=", "s", ".", "netPlugin", ".", "Status", "(", ")", ";", "err", "!=", "nil", "{", "networkCondition", ".", "Status", "=", "false", "\n", "networkCondition", ".", "Reason", "=", "networkNotReadyReason", "\n", "networkCondition", ".", "Message", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "resp", "=", "&", "pb", ".", "StatusResponse", "{", "Status", ":", "&", "pb", ".", "RuntimeStatus", "{", "Conditions", ":", "[", "]", "*", "pb", ".", "RuntimeCondition", "{", "runtimeCondition", ",", "networkCondition", ",", "}", ",", "}", ",", "}", "\n\n", "return", "resp", ",", "nil", "\n", "}" ]
// Status returns the status of the runtime
[ "Status", "returns", "the", "status", "of", "the", "runtime" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/runtime_status.go#L15-L47
train
cri-o/cri-o
server/metrics/metrics.go
Register
func Register() { registerMetrics.Do(func() { prometheus.MustRegister(CRIOOperations) prometheus.MustRegister(CRIOOperationsLatency) prometheus.MustRegister(CRIOOperationsErrors) }) }
go
func Register() { registerMetrics.Do(func() { prometheus.MustRegister(CRIOOperations) prometheus.MustRegister(CRIOOperationsLatency) prometheus.MustRegister(CRIOOperationsErrors) }) }
[ "func", "Register", "(", ")", "{", "registerMetrics", ".", "Do", "(", "func", "(", ")", "{", "prometheus", ".", "MustRegister", "(", "CRIOOperations", ")", "\n", "prometheus", ".", "MustRegister", "(", "CRIOOperationsLatency", ")", "\n", "prometheus", ".", "MustRegister", "(", "CRIOOperationsErrors", ")", "\n", "}", ")", "\n", "}" ]
// Register all metrics
[ "Register", "all", "metrics" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/metrics/metrics.go#L59-L65
train
cri-o/cri-o
pkg/storage/image.go
prepareReference
func (svc *imageService) prepareReference(imageName string, options *copy.Options) (types.ImageReference, error) { if imageName == "" { return nil, storage.ErrNotAnImage } srcRef, err := alltransports.ParseImageName(imageName) if err != nil { if svc.defaultTransport == "" { return nil, err } srcRef2, err2 := alltransports.ParseImageName(svc.defaultTransport + imageName) if err2 != nil { return nil, err } srcRef = srcRef2 } if options.SourceCtx == nil { options.SourceCtx = &types.SystemContext{} } if srcRef.DockerReference() != nil { hostname := reference.Domain(srcRef.DockerReference()) if secure := svc.isSecureIndex(hostname); !secure { options.SourceCtx.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!secure) } } return srcRef, nil }
go
func (svc *imageService) prepareReference(imageName string, options *copy.Options) (types.ImageReference, error) { if imageName == "" { return nil, storage.ErrNotAnImage } srcRef, err := alltransports.ParseImageName(imageName) if err != nil { if svc.defaultTransport == "" { return nil, err } srcRef2, err2 := alltransports.ParseImageName(svc.defaultTransport + imageName) if err2 != nil { return nil, err } srcRef = srcRef2 } if options.SourceCtx == nil { options.SourceCtx = &types.SystemContext{} } if srcRef.DockerReference() != nil { hostname := reference.Domain(srcRef.DockerReference()) if secure := svc.isSecureIndex(hostname); !secure { options.SourceCtx.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!secure) } } return srcRef, nil }
[ "func", "(", "svc", "*", "imageService", ")", "prepareReference", "(", "imageName", "string", ",", "options", "*", "copy", ".", "Options", ")", "(", "types", ".", "ImageReference", ",", "error", ")", "{", "if", "imageName", "==", "\"", "\"", "{", "return", "nil", ",", "storage", ".", "ErrNotAnImage", "\n", "}", "\n\n", "srcRef", ",", "err", ":=", "alltransports", ".", "ParseImageName", "(", "imageName", ")", "\n", "if", "err", "!=", "nil", "{", "if", "svc", ".", "defaultTransport", "==", "\"", "\"", "{", "return", "nil", ",", "err", "\n", "}", "\n", "srcRef2", ",", "err2", ":=", "alltransports", ".", "ParseImageName", "(", "svc", ".", "defaultTransport", "+", "imageName", ")", "\n", "if", "err2", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "srcRef", "=", "srcRef2", "\n", "}", "\n\n", "if", "options", ".", "SourceCtx", "==", "nil", "{", "options", ".", "SourceCtx", "=", "&", "types", ".", "SystemContext", "{", "}", "\n", "}", "\n\n", "if", "srcRef", ".", "DockerReference", "(", ")", "!=", "nil", "{", "hostname", ":=", "reference", ".", "Domain", "(", "srcRef", ".", "DockerReference", "(", ")", ")", "\n", "if", "secure", ":=", "svc", ".", "isSecureIndex", "(", "hostname", ")", ";", "!", "secure", "{", "options", ".", "SourceCtx", ".", "DockerInsecureSkipTLSVerify", "=", "types", ".", "NewOptionalBool", "(", "!", "secure", ")", "\n", "}", "\n", "}", "\n", "return", "srcRef", ",", "nil", "\n", "}" ]
// prepareReference creates an image reference from an image string and set options // for the source context
[ "prepareReference", "creates", "an", "image", "reference", "from", "an", "image", "string", "and", "set", "options", "for", "the", "source", "context" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/pkg/storage/image.go#L358-L386
train
cri-o/cri-o
server/container_updateruntimeconfig.go
UpdateRuntimeConfig
func (s *Server) UpdateRuntimeConfig(ctx context.Context, req *pb.UpdateRuntimeConfigRequest) (resp *pb.UpdateRuntimeConfigResponse, err error) { const operation = "update_runtime_config" defer func() { recordOperation(operation, time.Now()) recordError(operation, err) }() return &pb.UpdateRuntimeConfigResponse{}, nil }
go
func (s *Server) UpdateRuntimeConfig(ctx context.Context, req *pb.UpdateRuntimeConfigRequest) (resp *pb.UpdateRuntimeConfigResponse, err error) { const operation = "update_runtime_config" defer func() { recordOperation(operation, time.Now()) recordError(operation, err) }() return &pb.UpdateRuntimeConfigResponse{}, nil }
[ "func", "(", "s", "*", "Server", ")", "UpdateRuntimeConfig", "(", "ctx", "context", ".", "Context", ",", "req", "*", "pb", ".", "UpdateRuntimeConfigRequest", ")", "(", "resp", "*", "pb", ".", "UpdateRuntimeConfigResponse", ",", "err", "error", ")", "{", "const", "operation", "=", "\"", "\"", "\n", "defer", "func", "(", ")", "{", "recordOperation", "(", "operation", ",", "time", ".", "Now", "(", ")", ")", "\n", "recordError", "(", "operation", ",", "err", ")", "\n", "}", "(", ")", "\n\n", "return", "&", "pb", ".", "UpdateRuntimeConfigResponse", "{", "}", ",", "nil", "\n", "}" ]
// UpdateRuntimeConfig updates the configuration of a running container.
[ "UpdateRuntimeConfig", "updates", "the", "configuration", "of", "a", "running", "container", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/container_updateruntimeconfig.go#L11-L19
train
cri-o/cri-o
server/container_attach.go
Attach
func (ss StreamService) Attach(containerID string, inputStream io.Reader, outputStream, errorStream io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { c, err := ss.runtimeServer.GetContainerFromShortID(containerID) if err != nil { return fmt.Errorf("could not find container %q: %v", containerID, err) } if err := ss.runtimeServer.Runtime().UpdateContainerStatus(c); err != nil { return err } cState := c.State() if !(cState.Status == oci.ContainerStateRunning || cState.Status == oci.ContainerStateCreated) { return fmt.Errorf("container is not created or running") } return ss.runtimeServer.Runtime().AttachContainer(c, inputStream, outputStream, errorStream, tty, resize) }
go
func (ss StreamService) Attach(containerID string, inputStream io.Reader, outputStream, errorStream io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { c, err := ss.runtimeServer.GetContainerFromShortID(containerID) if err != nil { return fmt.Errorf("could not find container %q: %v", containerID, err) } if err := ss.runtimeServer.Runtime().UpdateContainerStatus(c); err != nil { return err } cState := c.State() if !(cState.Status == oci.ContainerStateRunning || cState.Status == oci.ContainerStateCreated) { return fmt.Errorf("container is not created or running") } return ss.runtimeServer.Runtime().AttachContainer(c, inputStream, outputStream, errorStream, tty, resize) }
[ "func", "(", "ss", "StreamService", ")", "Attach", "(", "containerID", "string", ",", "inputStream", "io", ".", "Reader", ",", "outputStream", ",", "errorStream", "io", ".", "WriteCloser", ",", "tty", "bool", ",", "resize", "<-", "chan", "remotecommand", ".", "TerminalSize", ")", "error", "{", "c", ",", "err", ":=", "ss", ".", "runtimeServer", ".", "GetContainerFromShortID", "(", "containerID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "containerID", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "ss", ".", "runtimeServer", ".", "Runtime", "(", ")", ".", "UpdateContainerStatus", "(", "c", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "cState", ":=", "c", ".", "State", "(", ")", "\n", "if", "!", "(", "cState", ".", "Status", "==", "oci", ".", "ContainerStateRunning", "||", "cState", ".", "Status", "==", "oci", ".", "ContainerStateCreated", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "ss", ".", "runtimeServer", ".", "Runtime", "(", ")", ".", "AttachContainer", "(", "c", ",", "inputStream", ",", "outputStream", ",", "errorStream", ",", "tty", ",", "resize", ")", "\n", "}" ]
// Attach endpoint for streaming.Runtime
[ "Attach", "endpoint", "for", "streaming", ".", "Runtime" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/container_attach.go#L33-L49
train
cri-o/cri-o
server/sandbox_network.go
networkStart
func (s *Server) networkStart(sb *sandbox.Sandbox) (podIP string, result cnitypes.Result, err error) { if sb.HostNetwork() { return s.hostIP, nil, nil } // Ensure network resources are cleaned up if the plugin succeeded // but an error happened between plugin success and the end of networkStart() defer func() { if err != nil { s.networkStop(sb) } }() podNetwork := newPodNetwork(sb) _, err = s.netPlugin.SetUpPod(podNetwork) if err != nil { err = fmt.Errorf("failed to create pod network sandbox %s(%s): %v", sb.Name(), sb.ID(), err) return } tmp, err := s.netPlugin.GetPodNetworkStatus(podNetwork) if err != nil { err = fmt.Errorf("failed to get network status for pod sandbox %s(%s): %v", sb.Name(), sb.ID(), err) return } // only one cnitypes.Result is returned since newPodNetwork sets Networks list empty result = tmp[0] logrus.Debugf("CNI setup result: %v", result) network, err := cnicurrent.GetResult(result) if err != nil { err = fmt.Errorf("failed to get network JSON for pod sandbox %s(%s): %v", sb.Name(), sb.ID(), err) return } podIP = strings.Split(network.IPs[0].Address.String(), "/")[0] if len(sb.PortMappings()) > 0 { ip := net.ParseIP(podIP) if ip == nil { err = fmt.Errorf("failed to get valid ip address for sandbox %s(%s)", sb.Name(), sb.ID()) return } err = s.hostportManager.Add(sb.ID(), &hostport.PodPortMapping{ Name: sb.Name(), PortMappings: sb.PortMappings(), IP: ip, HostNetwork: false, }, "lo") if err != nil { err = fmt.Errorf("failed to add hostport mapping for sandbox %s(%s): %v", sb.Name(), sb.ID(), err) return } } return }
go
func (s *Server) networkStart(sb *sandbox.Sandbox) (podIP string, result cnitypes.Result, err error) { if sb.HostNetwork() { return s.hostIP, nil, nil } // Ensure network resources are cleaned up if the plugin succeeded // but an error happened between plugin success and the end of networkStart() defer func() { if err != nil { s.networkStop(sb) } }() podNetwork := newPodNetwork(sb) _, err = s.netPlugin.SetUpPod(podNetwork) if err != nil { err = fmt.Errorf("failed to create pod network sandbox %s(%s): %v", sb.Name(), sb.ID(), err) return } tmp, err := s.netPlugin.GetPodNetworkStatus(podNetwork) if err != nil { err = fmt.Errorf("failed to get network status for pod sandbox %s(%s): %v", sb.Name(), sb.ID(), err) return } // only one cnitypes.Result is returned since newPodNetwork sets Networks list empty result = tmp[0] logrus.Debugf("CNI setup result: %v", result) network, err := cnicurrent.GetResult(result) if err != nil { err = fmt.Errorf("failed to get network JSON for pod sandbox %s(%s): %v", sb.Name(), sb.ID(), err) return } podIP = strings.Split(network.IPs[0].Address.String(), "/")[0] if len(sb.PortMappings()) > 0 { ip := net.ParseIP(podIP) if ip == nil { err = fmt.Errorf("failed to get valid ip address for sandbox %s(%s)", sb.Name(), sb.ID()) return } err = s.hostportManager.Add(sb.ID(), &hostport.PodPortMapping{ Name: sb.Name(), PortMappings: sb.PortMappings(), IP: ip, HostNetwork: false, }, "lo") if err != nil { err = fmt.Errorf("failed to add hostport mapping for sandbox %s(%s): %v", sb.Name(), sb.ID(), err) return } } return }
[ "func", "(", "s", "*", "Server", ")", "networkStart", "(", "sb", "*", "sandbox", ".", "Sandbox", ")", "(", "podIP", "string", ",", "result", "cnitypes", ".", "Result", ",", "err", "error", ")", "{", "if", "sb", ".", "HostNetwork", "(", ")", "{", "return", "s", ".", "hostIP", ",", "nil", ",", "nil", "\n", "}", "\n\n", "// Ensure network resources are cleaned up if the plugin succeeded", "// but an error happened between plugin success and the end of networkStart()", "defer", "func", "(", ")", "{", "if", "err", "!=", "nil", "{", "s", ".", "networkStop", "(", "sb", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "podNetwork", ":=", "newPodNetwork", "(", "sb", ")", "\n", "_", ",", "err", "=", "s", ".", "netPlugin", ".", "SetUpPod", "(", "podNetwork", ")", "\n", "if", "err", "!=", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "sb", ".", "Name", "(", ")", ",", "sb", ".", "ID", "(", ")", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "tmp", ",", "err", ":=", "s", ".", "netPlugin", ".", "GetPodNetworkStatus", "(", "podNetwork", ")", "\n", "if", "err", "!=", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "sb", ".", "Name", "(", ")", ",", "sb", ".", "ID", "(", ")", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "// only one cnitypes.Result is returned since newPodNetwork sets Networks list empty", "result", "=", "tmp", "[", "0", "]", "\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "result", ")", "\n\n", "network", ",", "err", ":=", "cnicurrent", ".", "GetResult", "(", "result", ")", "\n", "if", "err", "!=", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "sb", ".", "Name", "(", ")", ",", "sb", ".", "ID", "(", ")", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "podIP", "=", "strings", ".", "Split", "(", "network", ".", "IPs", "[", "0", "]", ".", "Address", ".", "String", "(", ")", ",", "\"", "\"", ")", "[", "0", "]", "\n\n", "if", "len", "(", "sb", ".", "PortMappings", "(", ")", ")", ">", "0", "{", "ip", ":=", "net", ".", "ParseIP", "(", "podIP", ")", "\n", "if", "ip", "==", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "sb", ".", "Name", "(", ")", ",", "sb", ".", "ID", "(", ")", ")", "\n", "return", "\n", "}", "\n\n", "err", "=", "s", ".", "hostportManager", ".", "Add", "(", "sb", ".", "ID", "(", ")", ",", "&", "hostport", ".", "PodPortMapping", "{", "Name", ":", "sb", ".", "Name", "(", ")", ",", "PortMappings", ":", "sb", ".", "PortMappings", "(", ")", ",", "IP", ":", "ip", ",", "HostNetwork", ":", "false", ",", "}", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "sb", ".", "Name", "(", ")", ",", "sb", ".", "ID", "(", ")", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "}", "\n", "return", "\n", "}" ]
// networkStart sets up the sandbox's network and returns the pod IP on success // or an error
[ "networkStart", "sets", "up", "the", "sandbox", "s", "network", "and", "returns", "the", "pod", "IP", "on", "success", "or", "an", "error" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/sandbox_network.go#L17-L75
train
cri-o/cri-o
server/sandbox_network.go
getSandboxIP
func (s *Server) getSandboxIP(sb *sandbox.Sandbox) (string, error) { if sb.HostNetwork() { return s.hostIP, nil } podNetwork := newPodNetwork(sb) result, err := s.netPlugin.GetPodNetworkStatus(podNetwork) if err != nil { return "", fmt.Errorf("failed to get network status for pod sandbox %s(%s): %v", sb.Name(), sb.ID(), err) } res, err := cnicurrent.GetResult(result[0]) if err != nil { return "", fmt.Errorf("failed to get network JSON for pod sandbox %s(%s): %v", sb.Name(), sb.ID(), err) } return strings.Split(res.IPs[0].Address.String(), "/")[0], nil }
go
func (s *Server) getSandboxIP(sb *sandbox.Sandbox) (string, error) { if sb.HostNetwork() { return s.hostIP, nil } podNetwork := newPodNetwork(sb) result, err := s.netPlugin.GetPodNetworkStatus(podNetwork) if err != nil { return "", fmt.Errorf("failed to get network status for pod sandbox %s(%s): %v", sb.Name(), sb.ID(), err) } res, err := cnicurrent.GetResult(result[0]) if err != nil { return "", fmt.Errorf("failed to get network JSON for pod sandbox %s(%s): %v", sb.Name(), sb.ID(), err) } return strings.Split(res.IPs[0].Address.String(), "/")[0], nil }
[ "func", "(", "s", "*", "Server", ")", "getSandboxIP", "(", "sb", "*", "sandbox", ".", "Sandbox", ")", "(", "string", ",", "error", ")", "{", "if", "sb", ".", "HostNetwork", "(", ")", "{", "return", "s", ".", "hostIP", ",", "nil", "\n", "}", "\n\n", "podNetwork", ":=", "newPodNetwork", "(", "sb", ")", "\n", "result", ",", "err", ":=", "s", ".", "netPlugin", ".", "GetPodNetworkStatus", "(", "podNetwork", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "sb", ".", "Name", "(", ")", ",", "sb", ".", "ID", "(", ")", ",", "err", ")", "\n", "}", "\n\n", "res", ",", "err", ":=", "cnicurrent", ".", "GetResult", "(", "result", "[", "0", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "sb", ".", "Name", "(", ")", ",", "sb", ".", "ID", "(", ")", ",", "err", ")", "\n", "}", "\n\n", "return", "strings", ".", "Split", "(", "res", ".", "IPs", "[", "0", "]", ".", "Address", ".", "String", "(", ")", ",", "\"", "\"", ")", "[", "0", "]", ",", "nil", "\n", "}" ]
// getSandboxIP retrieves the IP address for the sandbox
[ "getSandboxIP", "retrieves", "the", "IP", "address", "for", "the", "sandbox" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/sandbox_network.go#L78-L95
train
cri-o/cri-o
server/sandbox_network.go
networkStop
func (s *Server) networkStop(sb *sandbox.Sandbox) { if sb.HostNetwork() { return } if err := s.hostportManager.Remove(sb.ID(), &hostport.PodPortMapping{ Name: sb.Name(), PortMappings: sb.PortMappings(), HostNetwork: false, }); err != nil { logrus.Warnf("failed to remove hostport for pod sandbox %s(%s): %v", sb.Name(), sb.ID(), err) } podNetwork := newPodNetwork(sb) if err := s.netPlugin.TearDownPod(podNetwork); err != nil { logrus.Warnf("failed to destroy network for pod sandbox %s(%s): %v", sb.Name(), sb.ID(), err) } }
go
func (s *Server) networkStop(sb *sandbox.Sandbox) { if sb.HostNetwork() { return } if err := s.hostportManager.Remove(sb.ID(), &hostport.PodPortMapping{ Name: sb.Name(), PortMappings: sb.PortMappings(), HostNetwork: false, }); err != nil { logrus.Warnf("failed to remove hostport for pod sandbox %s(%s): %v", sb.Name(), sb.ID(), err) } podNetwork := newPodNetwork(sb) if err := s.netPlugin.TearDownPod(podNetwork); err != nil { logrus.Warnf("failed to destroy network for pod sandbox %s(%s): %v", sb.Name(), sb.ID(), err) } }
[ "func", "(", "s", "*", "Server", ")", "networkStop", "(", "sb", "*", "sandbox", ".", "Sandbox", ")", "{", "if", "sb", ".", "HostNetwork", "(", ")", "{", "return", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "hostportManager", ".", "Remove", "(", "sb", ".", "ID", "(", ")", ",", "&", "hostport", ".", "PodPortMapping", "{", "Name", ":", "sb", ".", "Name", "(", ")", ",", "PortMappings", ":", "sb", ".", "PortMappings", "(", ")", ",", "HostNetwork", ":", "false", ",", "}", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "sb", ".", "Name", "(", ")", ",", "sb", ".", "ID", "(", ")", ",", "err", ")", "\n", "}", "\n\n", "podNetwork", ":=", "newPodNetwork", "(", "sb", ")", "\n", "if", "err", ":=", "s", ".", "netPlugin", ".", "TearDownPod", "(", "podNetwork", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "sb", ".", "Name", "(", ")", ",", "sb", ".", "ID", "(", ")", ",", "err", ")", "\n", "}", "\n", "}" ]
// networkStop cleans up and removes a pod's network. It is best-effort and // must call the network plugin even if the network namespace is already gone
[ "networkStop", "cleans", "up", "and", "removes", "a", "pod", "s", "network", ".", "It", "is", "best", "-", "effort", "and", "must", "call", "the", "network", "plugin", "even", "if", "the", "network", "namespace", "is", "already", "gone" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/sandbox_network.go#L99-L118
train
cri-o/cri-o
server/image_status.go
getUserFromImage
func getUserFromImage(user string) (*int64, string) { // return both empty if user is not specified in the image. if user == "" { return nil, "" } // split instances where the id may contain user:group user = strings.Split(user, ":")[0] // user could be either uid or user name. Try to interpret as numeric uid. uid, err := strconv.ParseInt(user, 10, 64) if err != nil { // If user is non numeric, assume it's user name. return nil, user } // If user is a numeric uid. return &uid, "" }
go
func getUserFromImage(user string) (*int64, string) { // return both empty if user is not specified in the image. if user == "" { return nil, "" } // split instances where the id may contain user:group user = strings.Split(user, ":")[0] // user could be either uid or user name. Try to interpret as numeric uid. uid, err := strconv.ParseInt(user, 10, 64) if err != nil { // If user is non numeric, assume it's user name. return nil, user } // If user is a numeric uid. return &uid, "" }
[ "func", "getUserFromImage", "(", "user", "string", ")", "(", "*", "int64", ",", "string", ")", "{", "// return both empty if user is not specified in the image.", "if", "user", "==", "\"", "\"", "{", "return", "nil", ",", "\"", "\"", "\n", "}", "\n", "// split instances where the id may contain user:group", "user", "=", "strings", ".", "Split", "(", "user", ",", "\"", "\"", ")", "[", "0", "]", "\n", "// user could be either uid or user name. Try to interpret as numeric uid.", "uid", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "user", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "// If user is non numeric, assume it's user name.", "return", "nil", ",", "user", "\n", "}", "\n", "// If user is a numeric uid.", "return", "&", "uid", ",", "\"", "\"", "\n", "}" ]
// getUserFromImage gets uid or user name of the image user. // If user is numeric, it will be treated as uid; or else, it is treated as user name.
[ "getUserFromImage", "gets", "uid", "or", "user", "name", "of", "the", "image", "user", ".", "If", "user", "is", "numeric", "it", "will", "be", "treated", "as", "uid", ";", "or", "else", "it", "is", "treated", "as", "user", "name", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/image_status.go#L94-L109
train
cri-o/cri-o
server/container_reopen_log.go
ReopenContainerLog
func (s *Server) ReopenContainerLog(ctx context.Context, req *pb.ReopenContainerLogRequest) (resp *pb.ReopenContainerLogResponse, err error) { const operation = "container_reopen_log" defer func() { recordOperation(operation, time.Now()) recordError(operation, err) }() logrus.Debugf("ReopenContainerLogRequest %+v", req) containerID := req.ContainerId c := s.GetContainer(containerID) if c == nil { return nil, fmt.Errorf("could not find container %q", containerID) } if err := s.ContainerServer.Runtime().UpdateContainerStatus(c); err != nil { return nil, err } cState := c.State() if !(cState.Status == oci.ContainerStateRunning || cState.Status == oci.ContainerStateCreated) { return nil, fmt.Errorf("container is not created or running") } err = s.ContainerServer.Runtime().ReopenContainerLog(c) if err == nil { resp = &pb.ReopenContainerLogResponse{} } logrus.Debugf("ReopenContainerLogResponse %s: %+v", containerID, resp) return resp, err }
go
func (s *Server) ReopenContainerLog(ctx context.Context, req *pb.ReopenContainerLogRequest) (resp *pb.ReopenContainerLogResponse, err error) { const operation = "container_reopen_log" defer func() { recordOperation(operation, time.Now()) recordError(operation, err) }() logrus.Debugf("ReopenContainerLogRequest %+v", req) containerID := req.ContainerId c := s.GetContainer(containerID) if c == nil { return nil, fmt.Errorf("could not find container %q", containerID) } if err := s.ContainerServer.Runtime().UpdateContainerStatus(c); err != nil { return nil, err } cState := c.State() if !(cState.Status == oci.ContainerStateRunning || cState.Status == oci.ContainerStateCreated) { return nil, fmt.Errorf("container is not created or running") } err = s.ContainerServer.Runtime().ReopenContainerLog(c) if err == nil { resp = &pb.ReopenContainerLogResponse{} } logrus.Debugf("ReopenContainerLogResponse %s: %+v", containerID, resp) return resp, err }
[ "func", "(", "s", "*", "Server", ")", "ReopenContainerLog", "(", "ctx", "context", ".", "Context", ",", "req", "*", "pb", ".", "ReopenContainerLogRequest", ")", "(", "resp", "*", "pb", ".", "ReopenContainerLogResponse", ",", "err", "error", ")", "{", "const", "operation", "=", "\"", "\"", "\n", "defer", "func", "(", ")", "{", "recordOperation", "(", "operation", ",", "time", ".", "Now", "(", ")", ")", "\n", "recordError", "(", "operation", ",", "err", ")", "\n", "}", "(", ")", "\n\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "req", ")", "\n", "containerID", ":=", "req", ".", "ContainerId", "\n", "c", ":=", "s", ".", "GetContainer", "(", "containerID", ")", "\n\n", "if", "c", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "containerID", ")", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "ContainerServer", ".", "Runtime", "(", ")", ".", "UpdateContainerStatus", "(", "c", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "cState", ":=", "c", ".", "State", "(", ")", "\n", "if", "!", "(", "cState", ".", "Status", "==", "oci", ".", "ContainerStateRunning", "||", "cState", ".", "Status", "==", "oci", ".", "ContainerStateCreated", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "err", "=", "s", ".", "ContainerServer", ".", "Runtime", "(", ")", ".", "ReopenContainerLog", "(", "c", ")", "\n", "if", "err", "==", "nil", "{", "resp", "=", "&", "pb", ".", "ReopenContainerLogResponse", "{", "}", "\n", "}", "\n\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "containerID", ",", "resp", ")", "\n", "return", "resp", ",", "err", "\n", "}" ]
// ReopenContainerLog reopens the containers log file
[ "ReopenContainerLog", "reopens", "the", "containers", "log", "file" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/container_reopen_log.go#L14-L45
train
cri-o/cri-o
server/sandbox_list.go
filterSandbox
func filterSandbox(p *pb.PodSandbox, filter *pb.PodSandboxFilter) bool { if filter != nil { if filter.State != nil { if p.State != filter.State.State { return false } } if filter.LabelSelector != nil { sel := fields.SelectorFromSet(filter.LabelSelector) if !sel.Matches(fields.Set(p.Labels)) { return false } } } return true }
go
func filterSandbox(p *pb.PodSandbox, filter *pb.PodSandboxFilter) bool { if filter != nil { if filter.State != nil { if p.State != filter.State.State { return false } } if filter.LabelSelector != nil { sel := fields.SelectorFromSet(filter.LabelSelector) if !sel.Matches(fields.Set(p.Labels)) { return false } } } return true }
[ "func", "filterSandbox", "(", "p", "*", "pb", ".", "PodSandbox", ",", "filter", "*", "pb", ".", "PodSandboxFilter", ")", "bool", "{", "if", "filter", "!=", "nil", "{", "if", "filter", ".", "State", "!=", "nil", "{", "if", "p", ".", "State", "!=", "filter", ".", "State", ".", "State", "{", "return", "false", "\n", "}", "\n", "}", "\n", "if", "filter", ".", "LabelSelector", "!=", "nil", "{", "sel", ":=", "fields", ".", "SelectorFromSet", "(", "filter", ".", "LabelSelector", ")", "\n", "if", "!", "sel", ".", "Matches", "(", "fields", ".", "Set", "(", "p", ".", "Labels", ")", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// filterSandbox returns whether passed container matches filtering criteria
[ "filterSandbox", "returns", "whether", "passed", "container", "matches", "filtering", "criteria" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/sandbox_list.go#L15-L30
train
cri-o/cri-o
server/sandbox_list.go
ListPodSandbox
func (s *Server) ListPodSandbox(ctx context.Context, req *pb.ListPodSandboxRequest) (resp *pb.ListPodSandboxResponse, err error) { const operation = "list_pod_sandbox" defer func() { recordOperation(operation, time.Now()) recordError(operation, err) }() logrus.Debugf("ListPodSandboxRequest %+v", req) var pods []*pb.PodSandbox var podList []*sandbox.Sandbox podList = append(podList, s.ContainerServer.ListSandboxes()...) filter := req.Filter // Filter by pod id first. if filter != nil { if filter.Id != "" { id, err := s.PodIDIndex().Get(filter.Id) if err != nil { // Not finding an ID in a filtered list should not be considered // and error; it might have been deleted when stop was done. // Log and return an empty struct. logrus.Warnf("unable to find pod %s with filter", filter.Id) return &pb.ListPodSandboxResponse{}, nil } sb := s.getSandbox(id) if sb == nil { podList = []*sandbox.Sandbox{} } else { podList = []*sandbox.Sandbox{sb} } } } for _, sb := range podList { // Skip sandboxes that aren't created yet if !sb.Created() { continue } podInfraContainer := sb.InfraContainer() if podInfraContainer == nil { // this can't really happen, but if it does because of a bug // it's better not to panic continue } cState := podInfraContainer.StateNoLock() rStatus := pb.PodSandboxState_SANDBOX_NOTREADY if cState.Status == oci.ContainerStateRunning { rStatus = pb.PodSandboxState_SANDBOX_READY } pod := &pb.PodSandbox{ Id: sb.ID(), CreatedAt: podInfraContainer.CreatedAt().UnixNano(), State: rStatus, Labels: sb.Labels(), Annotations: sb.Annotations(), Metadata: sb.Metadata(), } // Filter by other criteria such as state and labels. if filterSandbox(pod, req.Filter) { pods = append(pods, pod) } } resp = &pb.ListPodSandboxResponse{ Items: pods, } logrus.Debugf("ListPodSandboxResponse %+v", resp) return resp, nil }
go
func (s *Server) ListPodSandbox(ctx context.Context, req *pb.ListPodSandboxRequest) (resp *pb.ListPodSandboxResponse, err error) { const operation = "list_pod_sandbox" defer func() { recordOperation(operation, time.Now()) recordError(operation, err) }() logrus.Debugf("ListPodSandboxRequest %+v", req) var pods []*pb.PodSandbox var podList []*sandbox.Sandbox podList = append(podList, s.ContainerServer.ListSandboxes()...) filter := req.Filter // Filter by pod id first. if filter != nil { if filter.Id != "" { id, err := s.PodIDIndex().Get(filter.Id) if err != nil { // Not finding an ID in a filtered list should not be considered // and error; it might have been deleted when stop was done. // Log and return an empty struct. logrus.Warnf("unable to find pod %s with filter", filter.Id) return &pb.ListPodSandboxResponse{}, nil } sb := s.getSandbox(id) if sb == nil { podList = []*sandbox.Sandbox{} } else { podList = []*sandbox.Sandbox{sb} } } } for _, sb := range podList { // Skip sandboxes that aren't created yet if !sb.Created() { continue } podInfraContainer := sb.InfraContainer() if podInfraContainer == nil { // this can't really happen, but if it does because of a bug // it's better not to panic continue } cState := podInfraContainer.StateNoLock() rStatus := pb.PodSandboxState_SANDBOX_NOTREADY if cState.Status == oci.ContainerStateRunning { rStatus = pb.PodSandboxState_SANDBOX_READY } pod := &pb.PodSandbox{ Id: sb.ID(), CreatedAt: podInfraContainer.CreatedAt().UnixNano(), State: rStatus, Labels: sb.Labels(), Annotations: sb.Annotations(), Metadata: sb.Metadata(), } // Filter by other criteria such as state and labels. if filterSandbox(pod, req.Filter) { pods = append(pods, pod) } } resp = &pb.ListPodSandboxResponse{ Items: pods, } logrus.Debugf("ListPodSandboxResponse %+v", resp) return resp, nil }
[ "func", "(", "s", "*", "Server", ")", "ListPodSandbox", "(", "ctx", "context", ".", "Context", ",", "req", "*", "pb", ".", "ListPodSandboxRequest", ")", "(", "resp", "*", "pb", ".", "ListPodSandboxResponse", ",", "err", "error", ")", "{", "const", "operation", "=", "\"", "\"", "\n", "defer", "func", "(", ")", "{", "recordOperation", "(", "operation", ",", "time", ".", "Now", "(", ")", ")", "\n", "recordError", "(", "operation", ",", "err", ")", "\n", "}", "(", ")", "\n\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "req", ")", "\n", "var", "pods", "[", "]", "*", "pb", ".", "PodSandbox", "\n", "var", "podList", "[", "]", "*", "sandbox", ".", "Sandbox", "\n", "podList", "=", "append", "(", "podList", ",", "s", ".", "ContainerServer", ".", "ListSandboxes", "(", ")", "...", ")", "\n\n", "filter", ":=", "req", ".", "Filter", "\n", "// Filter by pod id first.", "if", "filter", "!=", "nil", "{", "if", "filter", ".", "Id", "!=", "\"", "\"", "{", "id", ",", "err", ":=", "s", ".", "PodIDIndex", "(", ")", ".", "Get", "(", "filter", ".", "Id", ")", "\n", "if", "err", "!=", "nil", "{", "// Not finding an ID in a filtered list should not be considered", "// and error; it might have been deleted when stop was done.", "// Log and return an empty struct.", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "filter", ".", "Id", ")", "\n", "return", "&", "pb", ".", "ListPodSandboxResponse", "{", "}", ",", "nil", "\n", "}", "\n", "sb", ":=", "s", ".", "getSandbox", "(", "id", ")", "\n", "if", "sb", "==", "nil", "{", "podList", "=", "[", "]", "*", "sandbox", ".", "Sandbox", "{", "}", "\n", "}", "else", "{", "podList", "=", "[", "]", "*", "sandbox", ".", "Sandbox", "{", "sb", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "sb", ":=", "range", "podList", "{", "// Skip sandboxes that aren't created yet", "if", "!", "sb", ".", "Created", "(", ")", "{", "continue", "\n", "}", "\n", "podInfraContainer", ":=", "sb", ".", "InfraContainer", "(", ")", "\n", "if", "podInfraContainer", "==", "nil", "{", "// this can't really happen, but if it does because of a bug", "// it's better not to panic", "continue", "\n", "}", "\n", "cState", ":=", "podInfraContainer", ".", "StateNoLock", "(", ")", "\n", "rStatus", ":=", "pb", ".", "PodSandboxState_SANDBOX_NOTREADY", "\n", "if", "cState", ".", "Status", "==", "oci", ".", "ContainerStateRunning", "{", "rStatus", "=", "pb", ".", "PodSandboxState_SANDBOX_READY", "\n", "}", "\n\n", "pod", ":=", "&", "pb", ".", "PodSandbox", "{", "Id", ":", "sb", ".", "ID", "(", ")", ",", "CreatedAt", ":", "podInfraContainer", ".", "CreatedAt", "(", ")", ".", "UnixNano", "(", ")", ",", "State", ":", "rStatus", ",", "Labels", ":", "sb", ".", "Labels", "(", ")", ",", "Annotations", ":", "sb", ".", "Annotations", "(", ")", ",", "Metadata", ":", "sb", ".", "Metadata", "(", ")", ",", "}", "\n\n", "// Filter by other criteria such as state and labels.", "if", "filterSandbox", "(", "pod", ",", "req", ".", "Filter", ")", "{", "pods", "=", "append", "(", "pods", ",", "pod", ")", "\n", "}", "\n", "}", "\n\n", "resp", "=", "&", "pb", ".", "ListPodSandboxResponse", "{", "Items", ":", "pods", ",", "}", "\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "resp", ")", "\n", "return", "resp", ",", "nil", "\n", "}" ]
// ListPodSandbox returns a list of SandBoxes.
[ "ListPodSandbox", "returns", "a", "list", "of", "SandBoxes", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/sandbox_list.go#L33-L103
train
cri-o/cri-o
server/container_remove.go
RemoveContainer
func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerRequest) (resp *pb.RemoveContainerResponse, err error) { const operation = "remove_container" defer func() { recordOperation(operation, time.Now()) recordError(operation, err) }() logrus.Debugf("RemoveContainerRequest: %+v", req) // save container description to print c, err := s.GetContainerFromShortID(req.ContainerId) if err != nil { return nil, err } _, err = s.ContainerServer.Remove(ctx, req.ContainerId, true) if err != nil { return nil, err } logrus.Infof("Removed container %s", c.Description()) resp = &pb.RemoveContainerResponse{} logrus.Debugf("RemoveContainerResponse: %+v", resp) return resp, nil }
go
func (s *Server) RemoveContainer(ctx context.Context, req *pb.RemoveContainerRequest) (resp *pb.RemoveContainerResponse, err error) { const operation = "remove_container" defer func() { recordOperation(operation, time.Now()) recordError(operation, err) }() logrus.Debugf("RemoveContainerRequest: %+v", req) // save container description to print c, err := s.GetContainerFromShortID(req.ContainerId) if err != nil { return nil, err } _, err = s.ContainerServer.Remove(ctx, req.ContainerId, true) if err != nil { return nil, err } logrus.Infof("Removed container %s", c.Description()) resp = &pb.RemoveContainerResponse{} logrus.Debugf("RemoveContainerResponse: %+v", resp) return resp, nil }
[ "func", "(", "s", "*", "Server", ")", "RemoveContainer", "(", "ctx", "context", ".", "Context", ",", "req", "*", "pb", ".", "RemoveContainerRequest", ")", "(", "resp", "*", "pb", ".", "RemoveContainerResponse", ",", "err", "error", ")", "{", "const", "operation", "=", "\"", "\"", "\n", "defer", "func", "(", ")", "{", "recordOperation", "(", "operation", ",", "time", ".", "Now", "(", ")", ")", "\n", "recordError", "(", "operation", ",", "err", ")", "\n", "}", "(", ")", "\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "req", ")", "\n\n", "// save container description to print", "c", ",", "err", ":=", "s", ".", "GetContainerFromShortID", "(", "req", ".", "ContainerId", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "_", ",", "err", "=", "s", ".", "ContainerServer", ".", "Remove", "(", "ctx", ",", "req", ".", "ContainerId", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "c", ".", "Description", "(", ")", ")", "\n", "resp", "=", "&", "pb", ".", "RemoveContainerResponse", "{", "}", "\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "resp", ")", "\n", "return", "resp", ",", "nil", "\n", "}" ]
// RemoveContainer removes the container. If the container is running, the container // should be force removed.
[ "RemoveContainer", "removes", "the", "container", ".", "If", "the", "container", "is", "running", "the", "container", "should", "be", "force", "removed", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/container_remove.go#L13-L36
train
cri-o/cri-o
utils/ioutil/read_closer.go
Close
func (w *wrapReadCloser) Close() error { w.reader.Close() w.writer.Close() return nil }
go
func (w *wrapReadCloser) Close() error { w.reader.Close() w.writer.Close() return nil }
[ "func", "(", "w", "*", "wrapReadCloser", ")", "Close", "(", ")", "error", "{", "w", ".", "reader", ".", "Close", "(", ")", "\n", "w", ".", "writer", ".", "Close", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Close closes read closer.
[ "Close", "closes", "read", "closer", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/ioutil/read_closer.go#L53-L57
train
cri-o/cri-o
server/config.go
Validate
func (c *Config) Validate(onExecution bool) error { switch c.ImageVolumes { case lib.ImageVolumesMkdir: case lib.ImageVolumesIgnore: case lib.ImageVolumesBind: default: return fmt.Errorf("unrecognized image volume type specified") } if err := c.Config.Validate(onExecution); err != nil { return errors.Wrapf(err, "library config validation") } if c.UIDMappings != "" && c.ManageNetworkNSLifecycle { return fmt.Errorf("cannot use UIDMappings with ManageNetworkNSLifecycle") } if c.GIDMappings != "" && c.ManageNetworkNSLifecycle { return fmt.Errorf("cannot use GIDMappings with ManageNetworkNSLifecycle") } if c.LogSizeMax >= 0 && c.LogSizeMax < oci.BufSize { return fmt.Errorf("log size max should be negative or >= %d", oci.BufSize) } return nil }
go
func (c *Config) Validate(onExecution bool) error { switch c.ImageVolumes { case lib.ImageVolumesMkdir: case lib.ImageVolumesIgnore: case lib.ImageVolumesBind: default: return fmt.Errorf("unrecognized image volume type specified") } if err := c.Config.Validate(onExecution); err != nil { return errors.Wrapf(err, "library config validation") } if c.UIDMappings != "" && c.ManageNetworkNSLifecycle { return fmt.Errorf("cannot use UIDMappings with ManageNetworkNSLifecycle") } if c.GIDMappings != "" && c.ManageNetworkNSLifecycle { return fmt.Errorf("cannot use GIDMappings with ManageNetworkNSLifecycle") } if c.LogSizeMax >= 0 && c.LogSizeMax < oci.BufSize { return fmt.Errorf("log size max should be negative or >= %d", oci.BufSize) } return nil }
[ "func", "(", "c", "*", "Config", ")", "Validate", "(", "onExecution", "bool", ")", "error", "{", "switch", "c", ".", "ImageVolumes", "{", "case", "lib", ".", "ImageVolumesMkdir", ":", "case", "lib", ".", "ImageVolumesIgnore", ":", "case", "lib", ".", "ImageVolumesBind", ":", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "err", ":=", "c", ".", "Config", ".", "Validate", "(", "onExecution", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "c", ".", "UIDMappings", "!=", "\"", "\"", "&&", "c", ".", "ManageNetworkNSLifecycle", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "c", ".", "GIDMappings", "!=", "\"", "\"", "&&", "c", ".", "ManageNetworkNSLifecycle", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "c", ".", "LogSizeMax", ">=", "0", "&&", "c", ".", "LogSizeMax", "<", "oci", ".", "BufSize", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "oci", ".", "BufSize", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Validate is the main entry point for configuration validation // The parameter `onExecution` specifies if the validation should include // execution checks. It returns an `error` on validation failure, otherwise // `nil`.
[ "Validate", "is", "the", "main", "entry", "point", "for", "configuration", "validation", "The", "parameter", "onExecution", "specifies", "if", "the", "validation", "should", "include", "execution", "checks", ".", "It", "returns", "an", "error", "on", "validation", "failure", "otherwise", "nil", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/server/config.go#L167-L192
train
cri-o/cri-o
oci/runtime_oci.go
newRuntimeOCI
func newRuntimeOCI(r *Runtime, handler *RuntimeHandler) RuntimeImpl { return &runtimeOCI{ Runtime: r, path: handler.RuntimePath, root: handler.RuntimeRoot, } }
go
func newRuntimeOCI(r *Runtime, handler *RuntimeHandler) RuntimeImpl { return &runtimeOCI{ Runtime: r, path: handler.RuntimePath, root: handler.RuntimeRoot, } }
[ "func", "newRuntimeOCI", "(", "r", "*", "Runtime", ",", "handler", "*", "RuntimeHandler", ")", "RuntimeImpl", "{", "return", "&", "runtimeOCI", "{", "Runtime", ":", "r", ",", "path", ":", "handler", ".", "RuntimePath", ",", "root", ":", "handler", ".", "RuntimeRoot", ",", "}", "\n", "}" ]
// newRuntimeOCI creates a new runtimeOCI instance
[ "newRuntimeOCI", "creates", "a", "new", "runtimeOCI", "instance" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/oci/runtime_oci.go#L49-L55
train
cri-o/cri-o
lib/sandbox/history.go
Less
func (history *History) Less(i, j int) bool { sandboxes := *history // FIXME: state access should be serialized return sandboxes[j].createdAt.Before(sandboxes[i].createdAt) }
go
func (history *History) Less(i, j int) bool { sandboxes := *history // FIXME: state access should be serialized return sandboxes[j].createdAt.Before(sandboxes[i].createdAt) }
[ "func", "(", "history", "*", "History", ")", "Less", "(", "i", ",", "j", "int", ")", "bool", "{", "sandboxes", ":=", "*", "history", "\n", "// FIXME: state access should be serialized", "return", "sandboxes", "[", "j", "]", ".", "createdAt", ".", "Before", "(", "sandboxes", "[", "i", "]", ".", "createdAt", ")", "\n", "}" ]
// Less compares two sandboxes and returns true if the second one // was created before the first one.
[ "Less", "compares", "two", "sandboxes", "and", "returns", "true", "if", "the", "second", "one", "was", "created", "before", "the", "first", "one", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/sandbox/history.go#L16-L20
train
cri-o/cri-o
lib/sandbox/history.go
Swap
func (history *History) Swap(i, j int) { sandboxes := *history sandboxes[i], sandboxes[j] = sandboxes[j], sandboxes[i] }
go
func (history *History) Swap(i, j int) { sandboxes := *history sandboxes[i], sandboxes[j] = sandboxes[j], sandboxes[i] }
[ "func", "(", "history", "*", "History", ")", "Swap", "(", "i", ",", "j", "int", ")", "{", "sandboxes", ":=", "*", "history", "\n", "sandboxes", "[", "i", "]", ",", "sandboxes", "[", "j", "]", "=", "sandboxes", "[", "j", "]", ",", "sandboxes", "[", "i", "]", "\n", "}" ]
// Swap switches sandboxes i and j positions in the history.
[ "Swap", "switches", "sandboxes", "i", "and", "j", "positions", "in", "the", "history", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/sandbox/history.go#L23-L26
train
cri-o/cri-o
utils/io/exec_io.go
NewExecIO
func NewExecIO(id, root string, tty, stdin bool) (*ExecIO, error) { fifos, err := newFifos(root, id, tty, stdin) if err != nil { return nil, err } stdio, closer, err := newStdioPipes(fifos) if err != nil { return nil, err } return &ExecIO{ id: id, fifos: fifos, stdioPipes: stdio, closer: closer, }, nil }
go
func NewExecIO(id, root string, tty, stdin bool) (*ExecIO, error) { fifos, err := newFifos(root, id, tty, stdin) if err != nil { return nil, err } stdio, closer, err := newStdioPipes(fifos) if err != nil { return nil, err } return &ExecIO{ id: id, fifos: fifos, stdioPipes: stdio, closer: closer, }, nil }
[ "func", "NewExecIO", "(", "id", ",", "root", "string", ",", "tty", ",", "stdin", "bool", ")", "(", "*", "ExecIO", ",", "error", ")", "{", "fifos", ",", "err", ":=", "newFifos", "(", "root", ",", "id", ",", "tty", ",", "stdin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "stdio", ",", "closer", ",", "err", ":=", "newStdioPipes", "(", "fifos", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "ExecIO", "{", "id", ":", "id", ",", "fifos", ":", "fifos", ",", "stdioPipes", ":", "stdio", ",", "closer", ":", "closer", ",", "}", ",", "nil", "\n", "}" ]
// NewExecIO creates exec io.
[ "NewExecIO", "creates", "exec", "io", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/io/exec_io.go#L40-L55
train
cri-o/cri-o
utils/io/exec_io.go
Attach
func (e *ExecIO) Attach(opts AttachOptions) <-chan struct{} { var wg sync.WaitGroup var stdinStreamRC io.ReadCloser if e.stdin != nil && opts.Stdin != nil { stdinStreamRC = cioutil.NewWrapReadCloser(opts.Stdin) wg.Add(1) go func() { if _, err := io.Copy(e.stdin, stdinStreamRC); err != nil { logrus.WithError(err).Errorf("Failed to redirect stdin for container exec %q", e.id) } logrus.Infof("Container exec %q stdin closed", e.id) if opts.StdinOnce && !opts.Tty { e.stdin.Close() if err := opts.CloseStdin(); err != nil { logrus.WithError(err).Errorf("Failed to close stdin for container exec %q", e.id) } } else { if e.stdout != nil { e.stdout.Close() } if e.stderr != nil { e.stderr.Close() } } wg.Done() }() } attachOutput := func(t StreamType, stream io.WriteCloser, out io.ReadCloser) { if _, err := io.Copy(stream, out); err != nil { logrus.WithError(err).Errorf("Failed to pipe %q for container exec %q", t, e.id) } out.Close() stream.Close() if stdinStreamRC != nil { stdinStreamRC.Close() } e.closer.wg.Done() wg.Done() logrus.Infof("Finish piping %q of container exec %q", t, e.id) } if opts.Stdout != nil { wg.Add(1) // Closer should wait for this routine to be over. e.closer.wg.Add(1) go attachOutput(Stdout, opts.Stdout, e.stdout) } if !opts.Tty && opts.Stderr != nil { wg.Add(1) // Closer should wait for this routine to be over. e.closer.wg.Add(1) go attachOutput(Stderr, opts.Stderr, e.stderr) } done := make(chan struct{}) go func() { wg.Wait() close(done) }() return done }
go
func (e *ExecIO) Attach(opts AttachOptions) <-chan struct{} { var wg sync.WaitGroup var stdinStreamRC io.ReadCloser if e.stdin != nil && opts.Stdin != nil { stdinStreamRC = cioutil.NewWrapReadCloser(opts.Stdin) wg.Add(1) go func() { if _, err := io.Copy(e.stdin, stdinStreamRC); err != nil { logrus.WithError(err).Errorf("Failed to redirect stdin for container exec %q", e.id) } logrus.Infof("Container exec %q stdin closed", e.id) if opts.StdinOnce && !opts.Tty { e.stdin.Close() if err := opts.CloseStdin(); err != nil { logrus.WithError(err).Errorf("Failed to close stdin for container exec %q", e.id) } } else { if e.stdout != nil { e.stdout.Close() } if e.stderr != nil { e.stderr.Close() } } wg.Done() }() } attachOutput := func(t StreamType, stream io.WriteCloser, out io.ReadCloser) { if _, err := io.Copy(stream, out); err != nil { logrus.WithError(err).Errorf("Failed to pipe %q for container exec %q", t, e.id) } out.Close() stream.Close() if stdinStreamRC != nil { stdinStreamRC.Close() } e.closer.wg.Done() wg.Done() logrus.Infof("Finish piping %q of container exec %q", t, e.id) } if opts.Stdout != nil { wg.Add(1) // Closer should wait for this routine to be over. e.closer.wg.Add(1) go attachOutput(Stdout, opts.Stdout, e.stdout) } if !opts.Tty && opts.Stderr != nil { wg.Add(1) // Closer should wait for this routine to be over. e.closer.wg.Add(1) go attachOutput(Stderr, opts.Stderr, e.stderr) } done := make(chan struct{}) go func() { wg.Wait() close(done) }() return done }
[ "func", "(", "e", "*", "ExecIO", ")", "Attach", "(", "opts", "AttachOptions", ")", "<-", "chan", "struct", "{", "}", "{", "var", "wg", "sync", ".", "WaitGroup", "\n", "var", "stdinStreamRC", "io", ".", "ReadCloser", "\n", "if", "e", ".", "stdin", "!=", "nil", "&&", "opts", ".", "Stdin", "!=", "nil", "{", "stdinStreamRC", "=", "cioutil", ".", "NewWrapReadCloser", "(", "opts", ".", "Stdin", ")", "\n", "wg", ".", "Add", "(", "1", ")", "\n", "go", "func", "(", ")", "{", "if", "_", ",", "err", ":=", "io", ".", "Copy", "(", "e", ".", "stdin", ",", "stdinStreamRC", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "WithError", "(", "err", ")", ".", "Errorf", "(", "\"", "\"", ",", "e", ".", "id", ")", "\n", "}", "\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "e", ".", "id", ")", "\n", "if", "opts", ".", "StdinOnce", "&&", "!", "opts", ".", "Tty", "{", "e", ".", "stdin", ".", "Close", "(", ")", "\n", "if", "err", ":=", "opts", ".", "CloseStdin", "(", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "WithError", "(", "err", ")", ".", "Errorf", "(", "\"", "\"", ",", "e", ".", "id", ")", "\n", "}", "\n", "}", "else", "{", "if", "e", ".", "stdout", "!=", "nil", "{", "e", ".", "stdout", ".", "Close", "(", ")", "\n", "}", "\n", "if", "e", ".", "stderr", "!=", "nil", "{", "e", ".", "stderr", ".", "Close", "(", ")", "\n", "}", "\n", "}", "\n", "wg", ".", "Done", "(", ")", "\n", "}", "(", ")", "\n", "}", "\n\n", "attachOutput", ":=", "func", "(", "t", "StreamType", ",", "stream", "io", ".", "WriteCloser", ",", "out", "io", ".", "ReadCloser", ")", "{", "if", "_", ",", "err", ":=", "io", ".", "Copy", "(", "stream", ",", "out", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "WithError", "(", "err", ")", ".", "Errorf", "(", "\"", "\"", ",", "t", ",", "e", ".", "id", ")", "\n", "}", "\n", "out", ".", "Close", "(", ")", "\n", "stream", ".", "Close", "(", ")", "\n", "if", "stdinStreamRC", "!=", "nil", "{", "stdinStreamRC", ".", "Close", "(", ")", "\n", "}", "\n", "e", ".", "closer", ".", "wg", ".", "Done", "(", ")", "\n", "wg", ".", "Done", "(", ")", "\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "t", ",", "e", ".", "id", ")", "\n", "}", "\n\n", "if", "opts", ".", "Stdout", "!=", "nil", "{", "wg", ".", "Add", "(", "1", ")", "\n", "// Closer should wait for this routine to be over.", "e", ".", "closer", ".", "wg", ".", "Add", "(", "1", ")", "\n", "go", "attachOutput", "(", "Stdout", ",", "opts", ".", "Stdout", ",", "e", ".", "stdout", ")", "\n", "}", "\n\n", "if", "!", "opts", ".", "Tty", "&&", "opts", ".", "Stderr", "!=", "nil", "{", "wg", ".", "Add", "(", "1", ")", "\n", "// Closer should wait for this routine to be over.", "e", ".", "closer", ".", "wg", ".", "Add", "(", "1", ")", "\n", "go", "attachOutput", "(", "Stderr", ",", "opts", ".", "Stderr", ",", "e", ".", "stderr", ")", "\n", "}", "\n\n", "done", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "go", "func", "(", ")", "{", "wg", ".", "Wait", "(", ")", "\n", "close", "(", "done", ")", "\n", "}", "(", ")", "\n", "return", "done", "\n", "}" ]
// Attach attaches exec stdio. The logic is similar with container io attach.
[ "Attach", "attaches", "exec", "stdio", ".", "The", "logic", "is", "similar", "with", "container", "io", "attach", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/io/exec_io.go#L63-L125
train
cri-o/cri-o
oci/stats.go
getContainerNetIO
func getContainerNetIO(stats *libcontainer.Stats) (received uint64, transmitted uint64) { for _, iface := range stats.Interfaces { received += iface.RxBytes transmitted += iface.TxBytes } return }
go
func getContainerNetIO(stats *libcontainer.Stats) (received uint64, transmitted uint64) { for _, iface := range stats.Interfaces { received += iface.RxBytes transmitted += iface.TxBytes } return }
[ "func", "getContainerNetIO", "(", "stats", "*", "libcontainer", ".", "Stats", ")", "(", "received", "uint64", ",", "transmitted", "uint64", ")", "{", "for", "_", ",", "iface", ":=", "range", "stats", ".", "Interfaces", "{", "received", "+=", "iface", ".", "RxBytes", "\n", "transmitted", "+=", "iface", ".", "TxBytes", "\n", "}", "\n", "return", "\n", "}" ]
// Returns the total number of bytes transmitted and received for the given container stats
[ "Returns", "the", "total", "number", "of", "bytes", "transmitted", "and", "received", "for", "the", "given", "container", "stats" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/oci/stats.go#L27-L33
train
cri-o/cri-o
oci/stats.go
getMemLimit
func getMemLimit(cgroupLimit uint64) uint64 { si := &syscall.Sysinfo_t{} err := syscall.Sysinfo(si) if err != nil { return cgroupLimit } physicalLimit := si.Totalram if cgroupLimit > physicalLimit { return physicalLimit } return cgroupLimit }
go
func getMemLimit(cgroupLimit uint64) uint64 { si := &syscall.Sysinfo_t{} err := syscall.Sysinfo(si) if err != nil { return cgroupLimit } physicalLimit := si.Totalram if cgroupLimit > physicalLimit { return physicalLimit } return cgroupLimit }
[ "func", "getMemLimit", "(", "cgroupLimit", "uint64", ")", "uint64", "{", "si", ":=", "&", "syscall", ".", "Sysinfo_t", "{", "}", "\n", "err", ":=", "syscall", ".", "Sysinfo", "(", "si", ")", "\n", "if", "err", "!=", "nil", "{", "return", "cgroupLimit", "\n", "}", "\n\n", "physicalLimit", ":=", "si", ".", "Totalram", "\n", "if", "cgroupLimit", ">", "physicalLimit", "{", "return", "physicalLimit", "\n", "}", "\n", "return", "cgroupLimit", "\n", "}" ]
// getMemory limit returns the memory limit for a given cgroup // If the configured memory limit is larger than the total memory on the sys, the // physical system memory size is returned
[ "getMemory", "limit", "returns", "the", "memory", "limit", "for", "a", "given", "cgroup", "If", "the", "configured", "memory", "limit", "is", "larger", "than", "the", "total", "memory", "on", "the", "sys", "the", "physical", "system", "memory", "size", "is", "returned" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/oci/stats.go#L50-L62
train
cri-o/cri-o
utils/io/container_io.go
streamKey
func streamKey(id, name string, stream StreamType) string { return strings.Join([]string{id, name, string(stream)}, "-") }
go
func streamKey(id, name string, stream StreamType) string { return strings.Join([]string{id, name, string(stream)}, "-") }
[ "func", "streamKey", "(", "id", ",", "name", "string", ",", "stream", "StreamType", ")", "string", "{", "return", "strings", ".", "Join", "(", "[", "]", "string", "{", "id", ",", "name", ",", "string", "(", "stream", ")", "}", ",", "\"", "\"", ")", "\n", "}" ]
// streamKey generates a key for the stream.
[ "streamKey", "generates", "a", "key", "for", "the", "stream", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/io/container_io.go#L33-L35
train
cri-o/cri-o
utils/io/container_io.go
WithFIFOs
func WithFIFOs(fifos *cio.FIFOSet) ContainerIOOpts { return func(c *ContainerIO) error { c.fifos = fifos return nil } }
go
func WithFIFOs(fifos *cio.FIFOSet) ContainerIOOpts { return func(c *ContainerIO) error { c.fifos = fifos return nil } }
[ "func", "WithFIFOs", "(", "fifos", "*", "cio", ".", "FIFOSet", ")", "ContainerIOOpts", "{", "return", "func", "(", "c", "*", "ContainerIO", ")", "error", "{", "c", ".", "fifos", "=", "fifos", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithFIFOs specifies existing fifos for the container io.
[ "WithFIFOs", "specifies", "existing", "fifos", "for", "the", "container", "io", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/io/container_io.go#L56-L61
train
cri-o/cri-o
utils/io/container_io.go
WithNewFIFOs
func WithNewFIFOs(root string, tty, stdin bool) ContainerIOOpts { return func(c *ContainerIO) error { fifos, err := newFifos(root, c.id, tty, stdin) if err != nil { return err } return WithFIFOs(fifos)(c) } }
go
func WithNewFIFOs(root string, tty, stdin bool) ContainerIOOpts { return func(c *ContainerIO) error { fifos, err := newFifos(root, c.id, tty, stdin) if err != nil { return err } return WithFIFOs(fifos)(c) } }
[ "func", "WithNewFIFOs", "(", "root", "string", ",", "tty", ",", "stdin", "bool", ")", "ContainerIOOpts", "{", "return", "func", "(", "c", "*", "ContainerIO", ")", "error", "{", "fifos", ",", "err", ":=", "newFifos", "(", "root", ",", "c", ".", "id", ",", "tty", ",", "stdin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "WithFIFOs", "(", "fifos", ")", "(", "c", ")", "\n", "}", "\n", "}" ]
// WithNewFIFOs creates new fifos for the container io.
[ "WithNewFIFOs", "creates", "new", "fifos", "for", "the", "container", "io", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/io/container_io.go#L64-L72
train
cri-o/cri-o
utils/io/container_io.go
NewContainerIO
func NewContainerIO(id string, opts ...ContainerIOOpts) (_ *ContainerIO, err error) { c := &ContainerIO{ id: id, stdoutGroup: cioutil.NewWriterGroup(), stderrGroup: cioutil.NewWriterGroup(), } for _, opt := range opts { if err := opt(c); err != nil { return nil, err } } if c.fifos == nil { return nil, errors.New("fifos are not set") } // Create actual fifos. stdio, closer, err := newStdioPipes(c.fifos) if err != nil { return nil, err } c.stdioPipes = stdio c.closer = closer return c, nil }
go
func NewContainerIO(id string, opts ...ContainerIOOpts) (_ *ContainerIO, err error) { c := &ContainerIO{ id: id, stdoutGroup: cioutil.NewWriterGroup(), stderrGroup: cioutil.NewWriterGroup(), } for _, opt := range opts { if err := opt(c); err != nil { return nil, err } } if c.fifos == nil { return nil, errors.New("fifos are not set") } // Create actual fifos. stdio, closer, err := newStdioPipes(c.fifos) if err != nil { return nil, err } c.stdioPipes = stdio c.closer = closer return c, nil }
[ "func", "NewContainerIO", "(", "id", "string", ",", "opts", "...", "ContainerIOOpts", ")", "(", "_", "*", "ContainerIO", ",", "err", "error", ")", "{", "c", ":=", "&", "ContainerIO", "{", "id", ":", "id", ",", "stdoutGroup", ":", "cioutil", ".", "NewWriterGroup", "(", ")", ",", "stderrGroup", ":", "cioutil", ".", "NewWriterGroup", "(", ")", ",", "}", "\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "if", "err", ":=", "opt", "(", "c", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "if", "c", ".", "fifos", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "// Create actual fifos.", "stdio", ",", "closer", ",", "err", ":=", "newStdioPipes", "(", "c", ".", "fifos", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ".", "stdioPipes", "=", "stdio", "\n", "c", ".", "closer", "=", "closer", "\n", "return", "c", ",", "nil", "\n", "}" ]
// NewContainerIO creates container io.
[ "NewContainerIO", "creates", "container", "io", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/io/container_io.go#L75-L97
train
cri-o/cri-o
utils/io/container_io.go
Pipe
func (c *ContainerIO) Pipe() { wg := c.closer.wg wg.Add(1) go func() { if _, err := io.Copy(c.stdoutGroup, c.stdout); err != nil { logrus.WithError(err).Errorf("Failed to pipe stdout of container %q", c.id) } c.stdout.Close() c.stdoutGroup.Close() wg.Done() logrus.Infof("Finish piping stdout of container %q", c.id) }() if !c.fifos.Terminal { wg.Add(1) go func() { if _, err := io.Copy(c.stderrGroup, c.stderr); err != nil { logrus.WithError(err).Errorf("Failed to pipe stderr of container %q", c.id) } c.stderr.Close() c.stderrGroup.Close() wg.Done() logrus.Infof("Finish piping stderr of container %q", c.id) }() } }
go
func (c *ContainerIO) Pipe() { wg := c.closer.wg wg.Add(1) go func() { if _, err := io.Copy(c.stdoutGroup, c.stdout); err != nil { logrus.WithError(err).Errorf("Failed to pipe stdout of container %q", c.id) } c.stdout.Close() c.stdoutGroup.Close() wg.Done() logrus.Infof("Finish piping stdout of container %q", c.id) }() if !c.fifos.Terminal { wg.Add(1) go func() { if _, err := io.Copy(c.stderrGroup, c.stderr); err != nil { logrus.WithError(err).Errorf("Failed to pipe stderr of container %q", c.id) } c.stderr.Close() c.stderrGroup.Close() wg.Done() logrus.Infof("Finish piping stderr of container %q", c.id) }() } }
[ "func", "(", "c", "*", "ContainerIO", ")", "Pipe", "(", ")", "{", "wg", ":=", "c", ".", "closer", ".", "wg", "\n", "wg", ".", "Add", "(", "1", ")", "\n", "go", "func", "(", ")", "{", "if", "_", ",", "err", ":=", "io", ".", "Copy", "(", "c", ".", "stdoutGroup", ",", "c", ".", "stdout", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "WithError", "(", "err", ")", ".", "Errorf", "(", "\"", "\"", ",", "c", ".", "id", ")", "\n", "}", "\n", "c", ".", "stdout", ".", "Close", "(", ")", "\n", "c", ".", "stdoutGroup", ".", "Close", "(", ")", "\n", "wg", ".", "Done", "(", ")", "\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "c", ".", "id", ")", "\n", "}", "(", ")", "\n\n", "if", "!", "c", ".", "fifos", ".", "Terminal", "{", "wg", ".", "Add", "(", "1", ")", "\n", "go", "func", "(", ")", "{", "if", "_", ",", "err", ":=", "io", ".", "Copy", "(", "c", ".", "stderrGroup", ",", "c", ".", "stderr", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "WithError", "(", "err", ")", ".", "Errorf", "(", "\"", "\"", ",", "c", ".", "id", ")", "\n", "}", "\n", "c", ".", "stderr", ".", "Close", "(", ")", "\n", "c", ".", "stderrGroup", ".", "Close", "(", ")", "\n", "wg", ".", "Done", "(", ")", "\n", "logrus", ".", "Infof", "(", "\"", "\"", ",", "c", ".", "id", ")", "\n", "}", "(", ")", "\n", "}", "\n", "}" ]
// Pipe creates container fifos and pipe container output // to output stream.
[ "Pipe", "creates", "container", "fifos", "and", "pipe", "container", "output", "to", "output", "stream", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/io/container_io.go#L106-L131
train
cri-o/cri-o
utils/io/container_io.go
AddOutput
func (c *ContainerIO) AddOutput(name string, stdout, stderr io.WriteCloser) (io.WriteCloser, io.WriteCloser) { var oldStdout, oldStderr io.WriteCloser if stdout != nil { key := streamKey(c.id, name, Stdout) oldStdout = c.stdoutGroup.Get(key) c.stdoutGroup.Add(key, stdout) } if stderr != nil { key := streamKey(c.id, name, Stderr) oldStderr = c.stderrGroup.Get(key) c.stderrGroup.Add(key, stderr) } return oldStdout, oldStderr }
go
func (c *ContainerIO) AddOutput(name string, stdout, stderr io.WriteCloser) (io.WriteCloser, io.WriteCloser) { var oldStdout, oldStderr io.WriteCloser if stdout != nil { key := streamKey(c.id, name, Stdout) oldStdout = c.stdoutGroup.Get(key) c.stdoutGroup.Add(key, stdout) } if stderr != nil { key := streamKey(c.id, name, Stderr) oldStderr = c.stderrGroup.Get(key) c.stderrGroup.Add(key, stderr) } return oldStdout, oldStderr }
[ "func", "(", "c", "*", "ContainerIO", ")", "AddOutput", "(", "name", "string", ",", "stdout", ",", "stderr", "io", ".", "WriteCloser", ")", "(", "io", ".", "WriteCloser", ",", "io", ".", "WriteCloser", ")", "{", "var", "oldStdout", ",", "oldStderr", "io", ".", "WriteCloser", "\n", "if", "stdout", "!=", "nil", "{", "key", ":=", "streamKey", "(", "c", ".", "id", ",", "name", ",", "Stdout", ")", "\n", "oldStdout", "=", "c", ".", "stdoutGroup", ".", "Get", "(", "key", ")", "\n", "c", ".", "stdoutGroup", ".", "Add", "(", "key", ",", "stdout", ")", "\n", "}", "\n", "if", "stderr", "!=", "nil", "{", "key", ":=", "streamKey", "(", "c", ".", "id", ",", "name", ",", "Stderr", ")", "\n", "oldStderr", "=", "c", ".", "stderrGroup", ".", "Get", "(", "key", ")", "\n", "c", ".", "stderrGroup", ".", "Add", "(", "key", ",", "stderr", ")", "\n", "}", "\n", "return", "oldStdout", ",", "oldStderr", "\n", "}" ]
// AddOutput adds new write closers to the container stream, and returns existing // write closers if there are any.
[ "AddOutput", "adds", "new", "write", "closers", "to", "the", "container", "stream", "and", "returns", "existing", "write", "closers", "if", "there", "are", "any", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/io/container_io.go#L202-L215
train
cri-o/cri-o
lib/logs.go
GetLogs
func (c *ContainerServer) GetLogs(container string, logChan chan string, opts LogOptions) error { defer close(logChan) // Get the full ID of the container ctr, err := c.LookupContainer(container) if err != nil { return err } containerID := ctr.ID() sandbox := ctr.Sandbox() if sandbox == "" { sandbox = containerID } // Read the log line by line and pass it into the pipe logsFile := path.Join(c.config.LogDir, sandbox, containerID+".log") seekInfo := &tail.SeekInfo{Offset: 0, Whence: 0} if opts.Tail > 0 { // seek to correct position in logs files seekInfo.Offset = int64(opts.Tail) seekInfo.Whence = 2 } t, err := tail.TailFile(logsFile, tail.Config{Follow: false, ReOpen: false, Location: seekInfo}) for line := range t.Lines { if since, err := logSinceTime(opts.SinceTime, line.Text); err != nil || !since { continue } logMessage := line.Text[secondSpaceIndex(line.Text):] logChan <- logMessage } return err }
go
func (c *ContainerServer) GetLogs(container string, logChan chan string, opts LogOptions) error { defer close(logChan) // Get the full ID of the container ctr, err := c.LookupContainer(container) if err != nil { return err } containerID := ctr.ID() sandbox := ctr.Sandbox() if sandbox == "" { sandbox = containerID } // Read the log line by line and pass it into the pipe logsFile := path.Join(c.config.LogDir, sandbox, containerID+".log") seekInfo := &tail.SeekInfo{Offset: 0, Whence: 0} if opts.Tail > 0 { // seek to correct position in logs files seekInfo.Offset = int64(opts.Tail) seekInfo.Whence = 2 } t, err := tail.TailFile(logsFile, tail.Config{Follow: false, ReOpen: false, Location: seekInfo}) for line := range t.Lines { if since, err := logSinceTime(opts.SinceTime, line.Text); err != nil || !since { continue } logMessage := line.Text[secondSpaceIndex(line.Text):] logChan <- logMessage } return err }
[ "func", "(", "c", "*", "ContainerServer", ")", "GetLogs", "(", "container", "string", ",", "logChan", "chan", "string", ",", "opts", "LogOptions", ")", "error", "{", "defer", "close", "(", "logChan", ")", "\n", "// Get the full ID of the container", "ctr", ",", "err", ":=", "c", ".", "LookupContainer", "(", "container", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "containerID", ":=", "ctr", ".", "ID", "(", ")", "\n", "sandbox", ":=", "ctr", ".", "Sandbox", "(", ")", "\n", "if", "sandbox", "==", "\"", "\"", "{", "sandbox", "=", "containerID", "\n", "}", "\n", "// Read the log line by line and pass it into the pipe", "logsFile", ":=", "path", ".", "Join", "(", "c", ".", "config", ".", "LogDir", ",", "sandbox", ",", "containerID", "+", "\"", "\"", ")", "\n\n", "seekInfo", ":=", "&", "tail", ".", "SeekInfo", "{", "Offset", ":", "0", ",", "Whence", ":", "0", "}", "\n", "if", "opts", ".", "Tail", ">", "0", "{", "// seek to correct position in logs files", "seekInfo", ".", "Offset", "=", "int64", "(", "opts", ".", "Tail", ")", "\n", "seekInfo", ".", "Whence", "=", "2", "\n", "}", "\n\n", "t", ",", "err", ":=", "tail", ".", "TailFile", "(", "logsFile", ",", "tail", ".", "Config", "{", "Follow", ":", "false", ",", "ReOpen", ":", "false", ",", "Location", ":", "seekInfo", "}", ")", "\n", "for", "line", ":=", "range", "t", ".", "Lines", "{", "if", "since", ",", "err", ":=", "logSinceTime", "(", "opts", ".", "SinceTime", ",", "line", ".", "Text", ")", ";", "err", "!=", "nil", "||", "!", "since", "{", "continue", "\n", "}", "\n", "logMessage", ":=", "line", ".", "Text", "[", "secondSpaceIndex", "(", "line", ".", "Text", ")", ":", "]", "\n", "logChan", "<-", "logMessage", "\n", "}", "\n", "return", "err", "\n", "}" ]
// GetLogs gets each line of a log file and, if it matches the criteria in logOptions, sends it down logChan
[ "GetLogs", "gets", "each", "line", "of", "a", "log", "file", "and", "if", "it", "matches", "the", "criteria", "in", "logOptions", "sends", "it", "down", "logChan" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/lib/logs.go#L20-L52
train
cri-o/cri-o
oci/container.go
NewContainer
func NewContainer(id string, name string, bundlePath string, logPath string, netns string, labels map[string]string, crioAnnotations map[string]string, annotations map[string]string, image string, imageName string, imageRef string, metadata *pb.ContainerMetadata, sandbox string, terminal bool, stdin bool, stdinOnce bool, privileged bool, runtimeHandler string, dir string, created time.Time, stopSignal string) (*Container, error) { state := &ContainerState{} state.Created = created c := &Container{ id: id, name: name, bundlePath: bundlePath, logPath: logPath, labels: labels, sandbox: sandbox, netns: netns, terminal: terminal, stdin: stdin, stdinOnce: stdinOnce, privileged: privileged, runtimeHandler: runtimeHandler, metadata: metadata, annotations: annotations, crioAnnotations: crioAnnotations, image: image, imageName: imageName, imageRef: imageRef, dir: dir, state: state, stopSignal: stopSignal, } return c, nil }
go
func NewContainer(id string, name string, bundlePath string, logPath string, netns string, labels map[string]string, crioAnnotations map[string]string, annotations map[string]string, image string, imageName string, imageRef string, metadata *pb.ContainerMetadata, sandbox string, terminal bool, stdin bool, stdinOnce bool, privileged bool, runtimeHandler string, dir string, created time.Time, stopSignal string) (*Container, error) { state := &ContainerState{} state.Created = created c := &Container{ id: id, name: name, bundlePath: bundlePath, logPath: logPath, labels: labels, sandbox: sandbox, netns: netns, terminal: terminal, stdin: stdin, stdinOnce: stdinOnce, privileged: privileged, runtimeHandler: runtimeHandler, metadata: metadata, annotations: annotations, crioAnnotations: crioAnnotations, image: image, imageName: imageName, imageRef: imageRef, dir: dir, state: state, stopSignal: stopSignal, } return c, nil }
[ "func", "NewContainer", "(", "id", "string", ",", "name", "string", ",", "bundlePath", "string", ",", "logPath", "string", ",", "netns", "string", ",", "labels", "map", "[", "string", "]", "string", ",", "crioAnnotations", "map", "[", "string", "]", "string", ",", "annotations", "map", "[", "string", "]", "string", ",", "image", "string", ",", "imageName", "string", ",", "imageRef", "string", ",", "metadata", "*", "pb", ".", "ContainerMetadata", ",", "sandbox", "string", ",", "terminal", "bool", ",", "stdin", "bool", ",", "stdinOnce", "bool", ",", "privileged", "bool", ",", "runtimeHandler", "string", ",", "dir", "string", ",", "created", "time", ".", "Time", ",", "stopSignal", "string", ")", "(", "*", "Container", ",", "error", ")", "{", "state", ":=", "&", "ContainerState", "{", "}", "\n", "state", ".", "Created", "=", "created", "\n", "c", ":=", "&", "Container", "{", "id", ":", "id", ",", "name", ":", "name", ",", "bundlePath", ":", "bundlePath", ",", "logPath", ":", "logPath", ",", "labels", ":", "labels", ",", "sandbox", ":", "sandbox", ",", "netns", ":", "netns", ",", "terminal", ":", "terminal", ",", "stdin", ":", "stdin", ",", "stdinOnce", ":", "stdinOnce", ",", "privileged", ":", "privileged", ",", "runtimeHandler", ":", "runtimeHandler", ",", "metadata", ":", "metadata", ",", "annotations", ":", "annotations", ",", "crioAnnotations", ":", "crioAnnotations", ",", "image", ":", "image", ",", "imageName", ":", "imageName", ",", "imageRef", ":", "imageRef", ",", "dir", ":", "dir", ",", "state", ":", "state", ",", "stopSignal", ":", "stopSignal", ",", "}", "\n", "return", "c", ",", "nil", "\n", "}" ]
// NewContainer creates a container object.
[ "NewContainer", "creates", "a", "container", "object", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/oci/container.go#L79-L106
train
cri-o/cri-o
oci/container.go
GetStopSignal
func (c *Container) GetStopSignal() string { if c.stopSignal == "" { return defaultStopSignal } cleanSignal := strings.TrimPrefix(strings.ToUpper(c.stopSignal), "SIG") _, ok := signal.SignalMap[cleanSignal] if !ok { return defaultStopSignal } return cleanSignal }
go
func (c *Container) GetStopSignal() string { if c.stopSignal == "" { return defaultStopSignal } cleanSignal := strings.TrimPrefix(strings.ToUpper(c.stopSignal), "SIG") _, ok := signal.SignalMap[cleanSignal] if !ok { return defaultStopSignal } return cleanSignal }
[ "func", "(", "c", "*", "Container", ")", "GetStopSignal", "(", ")", "string", "{", "if", "c", ".", "stopSignal", "==", "\"", "\"", "{", "return", "defaultStopSignal", "\n", "}", "\n", "cleanSignal", ":=", "strings", ".", "TrimPrefix", "(", "strings", ".", "ToUpper", "(", "c", ".", "stopSignal", ")", ",", "\"", "\"", ")", "\n", "_", ",", "ok", ":=", "signal", ".", "SignalMap", "[", "cleanSignal", "]", "\n", "if", "!", "ok", "{", "return", "defaultStopSignal", "\n", "}", "\n", "return", "cleanSignal", "\n", "}" ]
// GetStopSignal returns the container's own stop signal configured from the // image configuration or the default one.
[ "GetStopSignal", "returns", "the", "container", "s", "own", "stop", "signal", "configured", "from", "the", "image", "configuration", "or", "the", "default", "one", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/oci/container.go#L120-L130
train
cri-o/cri-o
oci/container.go
StopSignal
func (c *Container) StopSignal() syscall.Signal { if c.stopSignal == "" { return defaultStopSignalInt } cleanSignal := strings.TrimPrefix(strings.ToUpper(c.stopSignal), "SIG") sig, ok := signal.SignalMap[cleanSignal] if !ok { return defaultStopSignalInt } return sig }
go
func (c *Container) StopSignal() syscall.Signal { if c.stopSignal == "" { return defaultStopSignalInt } cleanSignal := strings.TrimPrefix(strings.ToUpper(c.stopSignal), "SIG") sig, ok := signal.SignalMap[cleanSignal] if !ok { return defaultStopSignalInt } return sig }
[ "func", "(", "c", "*", "Container", ")", "StopSignal", "(", ")", "syscall", ".", "Signal", "{", "if", "c", ".", "stopSignal", "==", "\"", "\"", "{", "return", "defaultStopSignalInt", "\n", "}", "\n", "cleanSignal", ":=", "strings", ".", "TrimPrefix", "(", "strings", ".", "ToUpper", "(", "c", ".", "stopSignal", ")", ",", "\"", "\"", ")", "\n", "sig", ",", "ok", ":=", "signal", ".", "SignalMap", "[", "cleanSignal", "]", "\n", "if", "!", "ok", "{", "return", "defaultStopSignalInt", "\n", "}", "\n", "return", "sig", "\n", "}" ]
// StopSignal returns the container's own stop signal configured from // the image configuration or the default one.
[ "StopSignal", "returns", "the", "container", "s", "own", "stop", "signal", "configured", "from", "the", "image", "configuration", "or", "the", "default", "one", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/oci/container.go#L134-L144
train
cri-o/cri-o
oci/container.go
FromDisk
func (c *Container) FromDisk() error { jsonSource, err := os.Open(c.StatePath()) if err != nil { return err } defer jsonSource.Close() dec := json.NewDecoder(jsonSource) return dec.Decode(c.state) }
go
func (c *Container) FromDisk() error { jsonSource, err := os.Open(c.StatePath()) if err != nil { return err } defer jsonSource.Close() dec := json.NewDecoder(jsonSource) return dec.Decode(c.state) }
[ "func", "(", "c", "*", "Container", ")", "FromDisk", "(", ")", "error", "{", "jsonSource", ",", "err", ":=", "os", ".", "Open", "(", "c", ".", "StatePath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "jsonSource", ".", "Close", "(", ")", "\n\n", "dec", ":=", "json", ".", "NewDecoder", "(", "jsonSource", ")", "\n", "return", "dec", ".", "Decode", "(", "c", ".", "state", ")", "\n", "}" ]
// FromDisk restores container's state from disk
[ "FromDisk", "restores", "container", "s", "state", "from", "disk" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/oci/container.go#L147-L156
train
cri-o/cri-o
oci/container.go
NetNsPath
func (c *Container) NetNsPath() (string, error) { if c.state == nil { return "", fmt.Errorf("container state is not populated") } if c.netns == "" { return fmt.Sprintf("/proc/%d/ns/net", c.state.Pid), nil } return c.netns, nil }
go
func (c *Container) NetNsPath() (string, error) { if c.state == nil { return "", fmt.Errorf("container state is not populated") } if c.netns == "" { return fmt.Sprintf("/proc/%d/ns/net", c.state.Pid), nil } return c.netns, nil }
[ "func", "(", "c", "*", "Container", ")", "NetNsPath", "(", ")", "(", "string", ",", "error", ")", "{", "if", "c", ".", "state", "==", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "c", ".", "netns", "==", "\"", "\"", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "state", ".", "Pid", ")", ",", "nil", "\n", "}", "\n\n", "return", "c", ".", "netns", ",", "nil", "\n", "}" ]
// NetNsPath returns the path to the network namespace of the container.
[ "NetNsPath", "returns", "the", "path", "to", "the", "network", "namespace", "of", "the", "container", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/oci/container.go#L239-L249
train
cri-o/cri-o
oci/container.go
State
func (c *Container) State() *ContainerState { c.opLock.RLock() defer c.opLock.RUnlock() return c.state }
go
func (c *Container) State() *ContainerState { c.opLock.RLock() defer c.opLock.RUnlock() return c.state }
[ "func", "(", "c", "*", "Container", ")", "State", "(", ")", "*", "ContainerState", "{", "c", ".", "opLock", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "opLock", ".", "RUnlock", "(", ")", "\n", "return", "c", ".", "state", "\n", "}" ]
// State returns the state of the running container
[ "State", "returns", "the", "state", "of", "the", "running", "container" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/oci/container.go#L257-L261
train
cri-o/cri-o
oci/container.go
AddVolume
func (c *Container) AddVolume(v ContainerVolume) { c.volumes = append(c.volumes, v) }
go
func (c *Container) AddVolume(v ContainerVolume) { c.volumes = append(c.volumes, v) }
[ "func", "(", "c", "*", "Container", ")", "AddVolume", "(", "v", "ContainerVolume", ")", "{", "c", ".", "volumes", "=", "append", "(", "c", ".", "volumes", ",", "v", ")", "\n", "}" ]
// AddVolume adds a volume to list of container volumes.
[ "AddVolume", "adds", "a", "volume", "to", "list", "of", "container", "volumes", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/oci/container.go#L269-L271
train
cri-o/cri-o
oci/container.go
SetStartFailed
func (c *Container) SetStartFailed(err error) { c.opLock.Lock() defer c.opLock.Unlock() // adjust finished and started times c.state.Finished, c.state.Started = c.state.Created, c.state.Created if err != nil { c.state.Error = err.Error() } }
go
func (c *Container) SetStartFailed(err error) { c.opLock.Lock() defer c.opLock.Unlock() // adjust finished and started times c.state.Finished, c.state.Started = c.state.Created, c.state.Created if err != nil { c.state.Error = err.Error() } }
[ "func", "(", "c", "*", "Container", ")", "SetStartFailed", "(", "err", "error", ")", "{", "c", ".", "opLock", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "opLock", ".", "Unlock", "(", ")", "\n", "// adjust finished and started times", "c", ".", "state", ".", "Finished", ",", "c", ".", "state", ".", "Started", "=", "c", ".", "state", ".", "Created", ",", "c", ".", "state", ".", "Created", "\n", "if", "err", "!=", "nil", "{", "c", ".", "state", ".", "Error", "=", "err", ".", "Error", "(", ")", "\n", "}", "\n", "}" ]
// SetStartFailed sets the container state appropriately after a start failure
[ "SetStartFailed", "sets", "the", "container", "state", "appropriately", "after", "a", "start", "failure" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/oci/container.go#L310-L318
train
cri-o/cri-o
oci/container.go
Description
func (c *Container) Description() string { return fmt.Sprintf("%s/%s/%s", c.Labels()[types.KubernetesPodNamespaceLabel], c.Labels()[types.KubernetesPodNameLabel], c.Labels()[types.KubernetesContainerNameLabel]) }
go
func (c *Container) Description() string { return fmt.Sprintf("%s/%s/%s", c.Labels()[types.KubernetesPodNamespaceLabel], c.Labels()[types.KubernetesPodNameLabel], c.Labels()[types.KubernetesContainerNameLabel]) }
[ "func", "(", "c", "*", "Container", ")", "Description", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "Labels", "(", ")", "[", "types", ".", "KubernetesPodNamespaceLabel", "]", ",", "c", ".", "Labels", "(", ")", "[", "types", ".", "KubernetesPodNameLabel", "]", ",", "c", ".", "Labels", "(", ")", "[", "types", ".", "KubernetesContainerNameLabel", "]", ")", "\n", "}" ]
// Description returns a description for the container
[ "Description", "returns", "a", "description", "for", "the", "container" ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/oci/container.go#L321-L323
train
cri-o/cri-o
utils/ioutil/write_closer.go
NewWriteCloseInformer
func NewWriteCloseInformer(wc io.WriteCloser) (io.WriteCloser, <-chan struct{}) { close := make(chan struct{}) return &writeCloseInformer{ close: close, wc: wc, }, close }
go
func NewWriteCloseInformer(wc io.WriteCloser) (io.WriteCloser, <-chan struct{}) { close := make(chan struct{}) return &writeCloseInformer{ close: close, wc: wc, }, close }
[ "func", "NewWriteCloseInformer", "(", "wc", "io", ".", "WriteCloser", ")", "(", "io", ".", "WriteCloser", ",", "<-", "chan", "struct", "{", "}", ")", "{", "close", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "return", "&", "writeCloseInformer", "{", "close", ":", "close", ",", "wc", ":", "wc", ",", "}", ",", "close", "\n", "}" ]
// NewWriteCloseInformer creates the writeCloseInformer from a write closer.
[ "NewWriteCloseInformer", "creates", "the", "writeCloseInformer", "from", "a", "write", "closer", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/ioutil/write_closer.go#L33-L39
train
cri-o/cri-o
utils/ioutil/write_closer.go
Write
func (w *writeCloseInformer) Write(p []byte) (int, error) { return w.wc.Write(p) }
go
func (w *writeCloseInformer) Write(p []byte) (int, error) { return w.wc.Write(p) }
[ "func", "(", "w", "*", "writeCloseInformer", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "return", "w", ".", "wc", ".", "Write", "(", "p", ")", "\n", "}" ]
// Write passes through the data into the internal write closer.
[ "Write", "passes", "through", "the", "data", "into", "the", "internal", "write", "closer", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/ioutil/write_closer.go#L42-L44
train
cri-o/cri-o
utils/ioutil/write_closer.go
Close
func (w *writeCloseInformer) Close() error { err := w.wc.Close() close(w.close) return err }
go
func (w *writeCloseInformer) Close() error { err := w.wc.Close() close(w.close) return err }
[ "func", "(", "w", "*", "writeCloseInformer", ")", "Close", "(", ")", "error", "{", "err", ":=", "w", ".", "wc", ".", "Close", "(", ")", "\n", "close", "(", "w", ".", "close", ")", "\n", "return", "err", "\n", "}" ]
// Close closes the internal write closer and inform the close channel.
[ "Close", "closes", "the", "internal", "write", "closer", "and", "inform", "the", "close", "channel", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/ioutil/write_closer.go#L47-L51
train
cri-o/cri-o
utils/ioutil/write_closer.go
Write
func (n *nopWriteCloser) Write(p []byte) (int, error) { return n.w.Write(p) }
go
func (n *nopWriteCloser) Write(p []byte) (int, error) { return n.w.Write(p) }
[ "func", "(", "n", "*", "nopWriteCloser", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "return", "n", ".", "w", ".", "Write", "(", "p", ")", "\n", "}" ]
// Write passes through the data into the internal writer.
[ "Write", "passes", "through", "the", "data", "into", "the", "internal", "writer", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/ioutil/write_closer.go#L64-L66
train
cri-o/cri-o
utils/ioutil/write_closer.go
Write
func (s *serialWriteCloser) Write(data []byte) (int, error) { s.mu.Lock() defer s.mu.Unlock() return s.wc.Write(data) }
go
func (s *serialWriteCloser) Write(data []byte) (int, error) { s.mu.Lock() defer s.mu.Unlock() return s.wc.Write(data) }
[ "func", "(", "s", "*", "serialWriteCloser", ")", "Write", "(", "data", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "s", ".", "wc", ".", "Write", "(", "data", ")", "\n", "}" ]
// Write writes a group of byte arrays in order atomically.
[ "Write", "writes", "a", "group", "of", "byte", "arrays", "in", "order", "atomically", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/ioutil/write_closer.go#L91-L95
train
cri-o/cri-o
utils/ioutil/write_closer.go
Close
func (s *serialWriteCloser) Close() error { s.mu.Lock() defer s.mu.Unlock() return s.wc.Close() }
go
func (s *serialWriteCloser) Close() error { s.mu.Lock() defer s.mu.Unlock() return s.wc.Close() }
[ "func", "(", "s", "*", "serialWriteCloser", ")", "Close", "(", ")", "error", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "s", ".", "wc", ".", "Close", "(", ")", "\n", "}" ]
// Close closes the write closer.
[ "Close", "closes", "the", "write", "closer", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/utils/ioutil/write_closer.go#L98-L102
train
cri-o/cri-o
pkg/seccomp/seccomp.go
IsEnabled
func IsEnabled() bool { enabled := false // Check if Seccomp is supported, via CONFIG_SECCOMP. if err := unix.Prctl(unix.PR_GET_SECCOMP, 0, 0, 0, 0); err != unix.EINVAL { // Make sure the kernel has CONFIG_SECCOMP_FILTER. if err := unix.Prctl(unix.PR_SET_SECCOMP, unix.SECCOMP_MODE_FILTER, 0, 0, 0); err != unix.EINVAL { enabled = true } } logrus.Debugf("seccomp status: %v", enabled) return enabled }
go
func IsEnabled() bool { enabled := false // Check if Seccomp is supported, via CONFIG_SECCOMP. if err := unix.Prctl(unix.PR_GET_SECCOMP, 0, 0, 0, 0); err != unix.EINVAL { // Make sure the kernel has CONFIG_SECCOMP_FILTER. if err := unix.Prctl(unix.PR_SET_SECCOMP, unix.SECCOMP_MODE_FILTER, 0, 0, 0); err != unix.EINVAL { enabled = true } } logrus.Debugf("seccomp status: %v", enabled) return enabled }
[ "func", "IsEnabled", "(", ")", "bool", "{", "enabled", ":=", "false", "\n", "// Check if Seccomp is supported, via CONFIG_SECCOMP.", "if", "err", ":=", "unix", ".", "Prctl", "(", "unix", ".", "PR_GET_SECCOMP", ",", "0", ",", "0", ",", "0", ",", "0", ")", ";", "err", "!=", "unix", ".", "EINVAL", "{", "// Make sure the kernel has CONFIG_SECCOMP_FILTER.", "if", "err", ":=", "unix", ".", "Prctl", "(", "unix", ".", "PR_SET_SECCOMP", ",", "unix", ".", "SECCOMP_MODE_FILTER", ",", "0", ",", "0", ",", "0", ")", ";", "err", "!=", "unix", ".", "EINVAL", "{", "enabled", "=", "true", "\n", "}", "\n", "}", "\n", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "enabled", ")", "\n", "return", "enabled", "\n", "}" ]
// IsEnabled returns true if seccomp is enabled for the host.
[ "IsEnabled", "returns", "true", "if", "seccomp", "is", "enabled", "for", "the", "host", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/pkg/seccomp/seccomp.go#L19-L30
train
cri-o/cri-o
pkg/seccomp/seccomp.go
LoadProfileFromStruct
func LoadProfileFromStruct(config *Seccomp, specgen *generate.Generator) error { return setupSeccomp(config, specgen) }
go
func LoadProfileFromStruct(config *Seccomp, specgen *generate.Generator) error { return setupSeccomp(config, specgen) }
[ "func", "LoadProfileFromStruct", "(", "config", "*", "Seccomp", ",", "specgen", "*", "generate", ".", "Generator", ")", "error", "{", "return", "setupSeccomp", "(", "config", ",", "specgen", ")", "\n", "}" ]
// LoadProfileFromStruct takes a Seccomp struct and setup seccomp in the spec.
[ "LoadProfileFromStruct", "takes", "a", "Seccomp", "struct", "and", "setup", "seccomp", "in", "the", "spec", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/pkg/seccomp/seccomp.go#L33-L35
train
cri-o/cri-o
pkg/seccomp/seccomp.go
LoadProfileFromBytes
func LoadProfileFromBytes(body []byte, specgen *generate.Generator) error { config := &Seccomp{} if err := json.Unmarshal(body, config); err != nil { return fmt.Errorf("decoding seccomp profile failed: %v", err) } return setupSeccomp(config, specgen) }
go
func LoadProfileFromBytes(body []byte, specgen *generate.Generator) error { config := &Seccomp{} if err := json.Unmarshal(body, config); err != nil { return fmt.Errorf("decoding seccomp profile failed: %v", err) } return setupSeccomp(config, specgen) }
[ "func", "LoadProfileFromBytes", "(", "body", "[", "]", "byte", ",", "specgen", "*", "generate", ".", "Generator", ")", "error", "{", "config", ":=", "&", "Seccomp", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "body", ",", "config", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "setupSeccomp", "(", "config", ",", "specgen", ")", "\n", "}" ]
// LoadProfileFromBytes takes a byte slice and decodes the seccomp profile.
[ "LoadProfileFromBytes", "takes", "a", "byte", "slice", "and", "decodes", "the", "seccomp", "profile", "." ]
0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5
https://github.com/cri-o/cri-o/blob/0eac7be02d0a9d12b8b4bd1f2f0919c386ed61f5/pkg/seccomp/seccomp.go#L38-L44
train