Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgroup cleanups #2959

Merged
merged 8 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions cmd/internal/container/mesos/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type mesosFactory struct {
machineInfoFactory info.MachineInfoFactory

// Information about the cgroup subsystems.
cgroupSubsystems libcontainer.CgroupSubsystems
cgroupSubsystems map[string]string

// Information about mounted filesystems.
fsInfo fs.FsInfo
Expand All @@ -68,7 +68,7 @@ func (f *mesosFactory) NewContainerHandler(name string, metadataEnvAllowList []s

return newMesosContainerHandler(
name,
&f.cgroupSubsystems,
f.cgroupSubsystems,
f.machineInfoFactory,
f.fsInfo,
f.includedMetrics,
Expand Down
4 changes: 1 addition & 3 deletions cmd/internal/container/mesos/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (

mesos "github.com/mesos/mesos-go/api/v1/lib"
"github.com/stretchr/testify/assert"

containerlibcontainer "github.com/google/cadvisor/container/libcontainer"
)

func TestIsContainerName(t *testing.T) {
Expand Down Expand Up @@ -59,7 +57,7 @@ func TestCanHandleAndAccept(t *testing.T) {

f := &mesosFactory{
machineInfoFactory: nil,
cgroupSubsystems: containerlibcontainer.CgroupSubsystems{},
cgroupSubsystems: nil,
fsInfo: nil,
includedMetrics: nil,
client: fakeMesosAgentClient(testContainers, nil),
Expand Down
4 changes: 2 additions & 2 deletions cmd/internal/container/mesos/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ type mesosContainerHandler struct {

func newMesosContainerHandler(
name string,
cgroupSubsystems *containerlibcontainer.CgroupSubsystems,
cgroupSubsystems map[string]string,
machineInfoFactory info.MachineInfoFactory,
fsInfo fs.FsInfo,
includedMetrics container.MetricSet,
inHostNamespace bool,
metadataEnvAllowList []string,
client mesosAgentClient,
) (container.ContainerHandler, error) {
cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems.MountPoints, name)
cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems, name)

// Generate the equivalent cgroup manager for this container.
cgroupManager, err := containerlibcontainer.NewCgroupManager(name, cgroupPaths)
Expand Down
9 changes: 4 additions & 5 deletions cmd/internal/container/mesos/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/stretchr/testify/assert"

"github.com/google/cadvisor/container"
containerlibcontainer "github.com/google/cadvisor/container/libcontainer"
"github.com/google/cadvisor/fs"
info "github.com/google/cadvisor/info/v1"
)
Expand All @@ -42,7 +41,7 @@ func TestContainerReference(t *testing.T) {
name string
machineInfoFactory info.MachineInfoFactory
fsInfo fs.FsInfo
cgroupSubsystems *containerlibcontainer.CgroupSubsystems
cgroupSubsystems map[string]string
inHostNamespace bool
metadataEnvAllowList []string
includedMetrics container.MetricSet
Expand All @@ -57,7 +56,7 @@ func TestContainerReference(t *testing.T) {
"/mesos/04e20821-67d3-4bf7-96b4-7d4495f50b28",
nil,
nil,
&containerlibcontainer.CgroupSubsystems{},
nil,
false,
[]string{},
nil,
Expand All @@ -71,7 +70,7 @@ func TestContainerReference(t *testing.T) {
"/mesos/04e20821-67d3-4bf7-96b4-7d4495f50b28",
nil,
nil,
&containerlibcontainer.CgroupSubsystems{},
nil,
false,
[]string{},
nil,
Expand All @@ -85,7 +84,7 @@ func TestContainerReference(t *testing.T) {
"/mesos/04e20821-67d3-4bf7-96b4-7d4495f50b28",
nil,
nil,
&containerlibcontainer.CgroupSubsystems{},
nil,
false,
[]string{},
nil,
Expand Down
4 changes: 2 additions & 2 deletions container/containerd/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type containerdFactory struct {
client ContainerdClient
version string
// Information about the mounted cgroup subsystems.
cgroupSubsystems libcontainer.CgroupSubsystems
cgroupSubsystems map[string]string
// Information about mounted filesystems.
fsInfo fs.FsInfo
includedMetrics container.MetricSet
Expand Down Expand Up @@ -76,7 +76,7 @@ func (f *containerdFactory) NewContainerHandler(name string, metadataEnvAllowLis
name,
f.machineInfoFactory,
f.fsInfo,
&f.cgroupSubsystems,
f.cgroupSubsystems,
inHostNamespace,
containerdMetadataEnvAllowList,
f.includedMetrics,
Expand Down
4 changes: 1 addition & 3 deletions container/containerd/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"github.com/containerd/typeurl"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"

containerlibcontainer "github.com/google/cadvisor/container/libcontainer"
)

func TestIsContainerName(t *testing.T) {
Expand Down Expand Up @@ -59,7 +57,7 @@ func TestCanHandleAndAccept(t *testing.T) {

f := &containerdFactory{
client: mockcontainerdClient(testContainers, nil),
cgroupSubsystems: containerlibcontainer.CgroupSubsystems{},
cgroupSubsystems: nil,
fsInfo: nil,
machineInfoFactory: nil,
includedMetrics: nil,
Expand Down
11 changes: 8 additions & 3 deletions container/containerd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/containerd/containerd/errdefs"
"github.com/opencontainers/runc/libcontainer/cgroups"
"golang.org/x/net/context"

specs "github.com/opencontainers/runtime-spec/specs-go"
Expand Down Expand Up @@ -59,13 +60,13 @@ func newContainerdContainerHandler(
name string,
machineInfoFactory info.MachineInfoFactory,
fsInfo fs.FsInfo,
cgroupSubsystems *containerlibcontainer.CgroupSubsystems,
cgroupSubsystems map[string]string,
inHostNamespace bool,
metadataEnvAllowList []string,
includedMetrics container.MetricSet,
) (container.ContainerHandler, error) {
// Create the cgroup paths.
cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems.MountPoints, name)
cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems, name)

// Generate the equivalent cgroup manager for this container.
cgroupManager, err := containerlibcontainer.NewCgroupManager(name, cgroupPaths)
Expand Down Expand Up @@ -216,7 +217,11 @@ func (h *containerdContainerHandler) ListContainers(listType container.ListType)
}

func (h *containerdContainerHandler) GetCgroupPath(resource string) (string, error) {
path, ok := h.cgroupPaths[resource]
var res string
if !cgroups.IsCgroup2UnifiedMode() {
res = resource
}
path, ok := h.cgroupPaths[res]
if !ok {
return "", fmt.Errorf("could not find path for resource %q for container %q", resource, h.reference.Name)
}
Expand Down
9 changes: 4 additions & 5 deletions container/containerd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/stretchr/testify/assert"

"github.com/google/cadvisor/container"
containerlibcontainer "github.com/google/cadvisor/container/libcontainer"
"github.com/google/cadvisor/fs"
info "github.com/google/cadvisor/info/v1"
)
Expand All @@ -50,7 +49,7 @@ func TestHandler(t *testing.T) {
name string
machineInfoFactory info.MachineInfoFactory
fsInfo fs.FsInfo
cgroupSubsystems *containerlibcontainer.CgroupSubsystems
cgroupSubsystems map[string]string
inHostNamespace bool
metadataEnvAllowList []string
includedMetrics container.MetricSet
Expand All @@ -74,7 +73,7 @@ func TestHandler(t *testing.T) {
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9",
nil,
nil,
&containerlibcontainer.CgroupSubsystems{},
nil,
false,
nil,
nil,
Expand All @@ -88,7 +87,7 @@ func TestHandler(t *testing.T) {
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9",
&mockedMachineInfo{},
nil,
&containerlibcontainer.CgroupSubsystems{},
nil,
false,
nil,
nil,
Expand All @@ -107,7 +106,7 @@ func TestHandler(t *testing.T) {
"/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9",
&mockedMachineInfo{},
nil,
&containerlibcontainer.CgroupSubsystems{},
nil,
false,
[]string{"TEST"},
nil,
Expand Down
4 changes: 2 additions & 2 deletions container/crio/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type crioFactory struct {
storageDir string

// Information about the mounted cgroup subsystems.
cgroupSubsystems libcontainer.CgroupSubsystems
cgroupSubsystems map[string]string

// Information about mounted filesystems.
fsInfo fs.FsInfo
Expand All @@ -76,7 +76,7 @@ func (f *crioFactory) NewContainerHandler(name string, metadataEnvAllowList []st
f.fsInfo,
f.storageDriver,
f.storageDir,
&f.cgroupSubsystems,
f.cgroupSubsystems,
inHostNamespace,
metadataEnvAllowList,
f.includedMetrics,
Expand Down
4 changes: 1 addition & 3 deletions container/crio/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ import (
"testing"

"github.com/stretchr/testify/assert"

containerlibcontainer "github.com/google/cadvisor/container/libcontainer"
)

func TestCanHandleAndAccept(t *testing.T) {
as := assert.New(t)
f := &crioFactory{
client: nil,
cgroupSubsystems: containerlibcontainer.CgroupSubsystems{},
cgroupSubsystems: nil,
fsInfo: nil,
machineInfoFactory: nil,
storageDriver: "",
Expand Down
10 changes: 7 additions & 3 deletions container/crio/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func newCrioContainerHandler(
fsInfo fs.FsInfo,
storageDriver storageDriver,
storageDir string,
cgroupSubsystems *containerlibcontainer.CgroupSubsystems,
cgroupSubsystems map[string]string,
inHostNamespace bool,
metadataEnvAllowList []string,
includedMetrics container.MetricSet,
) (container.ContainerHandler, error) {
// Create the cgroup paths.
cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems.MountPoints, name)
cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems, name)

// Generate the equivalent cgroup manager for this container.
cgroupManager, err := containerlibcontainer.NewCgroupManager(name, cgroupPaths)
Expand Down Expand Up @@ -328,7 +328,11 @@ func (h *crioContainerHandler) ListContainers(listType container.ListType) ([]in
}

func (h *crioContainerHandler) GetCgroupPath(resource string) (string, error) {
path, ok := h.cgroupPaths[resource]
var res string
if !cgroups.IsCgroup2UnifiedMode() {
res = resource
}
path, ok := h.cgroupPaths[res]
if !ok {
return "", fmt.Errorf("could not find path for resource %q for container %q", resource, h.reference.Name)
}
Expand Down
9 changes: 4 additions & 5 deletions container/crio/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/stretchr/testify/assert"

"github.com/google/cadvisor/container"
containerlibcontainer "github.com/google/cadvisor/container/libcontainer"
"github.com/google/cadvisor/fs"
info "github.com/google/cadvisor/info/v1"
)
Expand All @@ -35,7 +34,7 @@ func TestHandler(t *testing.T) {
fsInfo fs.FsInfo
storageDriver storageDriver
storageDir string
cgroupSubsystems *containerlibcontainer.CgroupSubsystems
cgroupSubsystems map[string]string
inHostNamespace bool
metadataEnvAllowList []string
includedMetrics container.MetricSet
Expand All @@ -52,7 +51,7 @@ func TestHandler(t *testing.T) {
nil,
"",
"",
&containerlibcontainer.CgroupSubsystems{},
nil,
false,
nil,
nil,
Expand All @@ -68,7 +67,7 @@ func TestHandler(t *testing.T) {
nil,
"",
"",
&containerlibcontainer.CgroupSubsystems{},
nil,
false,
nil,
nil,
Expand All @@ -88,7 +87,7 @@ func TestHandler(t *testing.T) {
nil,
"",
"",
&containerlibcontainer.CgroupSubsystems{},
nil,
false,
nil,
nil,
Expand Down
4 changes: 2 additions & 2 deletions container/docker/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ type dockerFactory struct {
client *docker.Client

// Information about the mounted cgroup subsystems.
cgroupSubsystems libcontainer.CgroupSubsystems
cgroupSubsystems map[string]string

// Information about mounted filesystems.
fsInfo fs.FsInfo
Expand Down Expand Up @@ -157,7 +157,7 @@ func (f *dockerFactory) NewContainerHandler(name string, metadataEnvAllowList []
f.fsInfo,
f.storageDriver,
f.storageDir,
&f.cgroupSubsystems,
f.cgroupSubsystems,
inHostNamespace,
dockerMetadataEnvAllowList,
f.dockerVersion,
Expand Down
11 changes: 8 additions & 3 deletions container/docker/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/google/cadvisor/fs"
info "github.com/google/cadvisor/info/v1"
"github.com/google/cadvisor/zfs"
"github.com/opencontainers/runc/libcontainer/cgroups"
kolyshkin marked this conversation as resolved.
Show resolved Hide resolved

dockercontainer "github.com/docker/docker/api/types/container"
docker "github.com/docker/docker/client"
Expand Down Expand Up @@ -121,7 +122,7 @@ func newDockerContainerHandler(
fsInfo fs.FsInfo,
storageDriver storageDriver,
storageDir string,
cgroupSubsystems *containerlibcontainer.CgroupSubsystems,
cgroupSubsystems map[string]string,
inHostNamespace bool,
metadataEnvAllowList []string,
dockerVersion []int,
Expand All @@ -131,7 +132,7 @@ func newDockerContainerHandler(
zfsWatcher *zfs.ZfsWatcher,
) (container.ContainerHandler, error) {
// Create the cgroup paths.
cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems.MountPoints, name)
cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems, name)

// Generate the equivalent cgroup manager for this container.
cgroupManager, err := containerlibcontainer.NewCgroupManager(name, cgroupPaths)
Expand Down Expand Up @@ -484,7 +485,11 @@ func (h *dockerContainerHandler) ListContainers(listType container.ListType) ([]
}

func (h *dockerContainerHandler) GetCgroupPath(resource string) (string, error) {
path, ok := h.cgroupPaths[resource]
var res string
if !cgroups.IsCgroup2UnifiedMode() {
res = resource
}
path, ok := h.cgroupPaths[res]
if !ok {
return "", fmt.Errorf("could not find path for resource %q for container %q", resource, h.reference.Name)
}
Expand Down
Loading