Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion container/crio/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import (
)

type crioContainerHandler struct {
client crioClient
name string

machineInfoFactory info.MachineInfoFactory

// Absolute path to the cgroup hierarchies of this container.
Expand Down Expand Up @@ -68,6 +71,9 @@ type crioContainerHandler struct {
reference info.ContainerReference

libcontainerHandler *containerlibcontainer.Handler
cgroupManager *cgroupfs.Manager
rootFs string
pidKnown bool
}

var _ container.ContainerHandler = &crioContainerHandler{}
Expand Down Expand Up @@ -106,11 +112,20 @@ func newCrioContainerHandler(
}

id := ContainerNameToCrioId(name)
pidKnown := true

cInfo, err := client.ContainerInfo(id)
if err != nil {
return nil, err
}
if cInfo.Pid == 0 {
// If pid is not known yet, network related stats can not be retrieved by the
// libcontainer handler GetStats(). In this case, the crio handler GetStats()
// will reattempt to get the pid and, if now known, will construct the libcontainer
// handler. This libcontainer handler is then cached and reused without additional
// calls to crio.
pidKnown = false
}

// passed to fs handler below ...
// XXX: this is using the full container logpath, as constructed by the CRI
Expand Down Expand Up @@ -145,6 +160,8 @@ func newCrioContainerHandler(

// TODO: extract object mother method
handler := &crioContainerHandler{
client: client,
name: name,
machineInfoFactory: machineInfoFactory,
cgroupPaths: cgroupPaths,
storageDriver: storageDriver,
Expand All @@ -155,6 +172,9 @@ func newCrioContainerHandler(
includedMetrics: includedMetrics,
reference: containerReference,
libcontainerHandler: libcontainerHandler,
cgroupManager: cgroupManager,
rootFs: rootFs,
pidKnown: pidKnown,
}

handler.image = cInfo.Image
Expand Down Expand Up @@ -266,8 +286,27 @@ func (self *crioContainerHandler) getFsStats(stats *info.ContainerStats) error {
return nil
}

func (self *crioContainerHandler) getLibcontainerHandler() *containerlibcontainer.Handler {
if self.pidKnown {
return self.libcontainerHandler
}

id := ContainerNameToCrioId(self.name)

cInfo, err := self.client.ContainerInfo(id)
if err != nil || cInfo.Pid == 0 {
return self.libcontainerHandler
}

self.pidKnown = true
self.libcontainerHandler = containerlibcontainer.NewHandler(self.cgroupManager, self.rootFs, cInfo.Pid, self.includedMetrics)

return self.libcontainerHandler
}

func (self *crioContainerHandler) GetStats() (*info.ContainerStats, error) {
stats, err := self.libcontainerHandler.GetStats()
libcontainerHandler := self.getLibcontainerHandler()
stats, err := libcontainerHandler.GetStats()
if err != nil {
return stats, err
}
Expand Down