MCPcopy
hub / github.com/google/cadvisor / newCrioContainerHandler

Function newCrioContainerHandler

lib/container/crio/handler.go:82–205  ·  view source on GitHub ↗

newCrioContainerHandler returns a new container.ContainerHandler

(
	client CrioClient,
	name string,
	machineInfoFactory info.MachineInfoFactory,
	fsInfo fs.FsInfo,
	storageDriver storageDriver,
	storageDir string,
	cgroupSubsystems map[string]string,
	inHostNamespace bool,
	metadataEnvAllowList []string,
	includedMetrics container.MetricSet,
)

Source from the content-addressed store, hash-verified

80
81// newCrioContainerHandler returns a new container.ContainerHandler
82func newCrioContainerHandler(
83 client CrioClient,
84 name string,
85 machineInfoFactory info.MachineInfoFactory,
86 fsInfo fs.FsInfo,
87 storageDriver storageDriver,
88 storageDir string,
89 cgroupSubsystems map[string]string,
90 inHostNamespace bool,
91 metadataEnvAllowList []string,
92 includedMetrics container.MetricSet,
93) (container.ContainerHandler, error) {
94 // Create the cgroup paths.
95 cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems, name)
96
97 // Generate the equivalent cgroup manager for this container.
98 cgroupManager, err := containerlibcontainer.NewCgroupManager(name, cgroupPaths)
99 if err != nil {
100 return nil, err
101 }
102
103 rootFs := "/"
104 if !inHostNamespace {
105 rootFs = "/rootfs"
106 }
107
108 id := ContainerNameToCrioId(name)
109 pidKnown := true
110
111 cInfo, err := client.ContainerInfo(id)
112 if err != nil {
113 return nil, err
114 }
115 if cInfo.Pid == 0 {
116 // If pid is not known yet, network related stats can not be retrieved by the
117 // libcontainer handler GetStats(). In this case, the crio handler GetStats()
118 // will reattempt to get the pid and, if now known, will construct the libcontainer
119 // handler. This libcontainer handler is then cached and reused without additional
120 // calls to crio.
121 pidKnown = false
122 }
123
124 // passed to fs handler below ...
125 // XXX: this is using the full container logpath, as constructed by the CRI
126 // /var/log/pods/<pod_uuid>/container_instance.log
127 // It's not actually a log dir, as the CRI doesn't have per-container dirs
128 // under /var/log/pods/<pod_uuid>/
129 // We can't use /var/log/pods/<pod_uuid>/ to count per-container log usage.
130 // We use the container log file directly.
131 storageLogDir := cInfo.LogPath
132
133 // Determine the rootfs storage dir
134 rootfsStorageDir := cInfo.Root
135 // TODO(runcom): CRI-O doesn't strip /merged but we need to in order to
136 // get device ID from root, otherwise, it's going to error out as overlay
137 // mounts doesn't have fixed dev ids.
138 rootfsStorageDir = strings.TrimSuffix(rootfsStorageDir, "/merged")
139 switch storageDriver {

Callers 2

NewContainerHandlerMethod · 0.85
TestHandlerFunction · 0.85

Calls 6

MakeCgroupPathsFunction · 0.92
RemoveNetMetricsFunction · 0.92
NewFsHandlerFunction · 0.92
ContainerNameToCrioIdFunction · 0.85
HasMethod · 0.80
ContainerInfoMethod · 0.65

Tested by 1

TestHandlerFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…