Skip to content

Commit 3beb265

Browse files
kolyshkinPaweł Szulik
authored andcommitted
manager: simplify createContainer
The code to initialize perf collector is almost the same between cgroup v1 and v2, the only difference is how we get cgroup path. Since now GetCgroupPath is v2 ready, we can use it, and thus unify these two cases. This commit is best reviewed with --ignore-space-change. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent c985f28 commit 3beb265

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

cmd/internal/container/mesos/factory_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919

2020
mesos "github.com/mesos/mesos-go/api/v1/lib"
2121
"github.com/stretchr/testify/assert"
22-
23-
containerlibcontainer "github.com/google/cadvisor/container/libcontainer"
2422
)
2523

2624
func TestIsContainerName(t *testing.T) {

manager/manager.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import (
4747
"github.com/google/cadvisor/watcher"
4848

4949
"github.com/opencontainers/runc/libcontainer/cgroups"
50-
"github.com/opencontainers/runc/libcontainer/cgroups/fs2"
5150

5251
"k8s.io/klog/v2"
5352
"k8s.io/utils/clock"
@@ -937,15 +936,7 @@ func (m *manager) createContainerLocked(containerName string, watchSource watche
937936
return err
938937
}
939938

940-
if cgroups.IsCgroup2UnifiedMode() {
941-
if m.includedMetrics.Has(container.PerfMetrics) {
942-
perfCgroupPath := path.Join(fs2.UnifiedMountpoint, containerName)
943-
cont.perfCollector, err = m.perfManager.GetCollector(perfCgroupPath)
944-
if err != nil {
945-
klog.Errorf("Perf event metrics will not be available for container %q: %v", containerName, err)
946-
}
947-
}
948-
} else {
939+
if !cgroups.IsCgroup2UnifiedMode() {
949940
devicesCgroupPath, err := handler.GetCgroupPath("devices")
950941
if err != nil {
951942
klog.Warningf("Error getting devices cgroup path: %v", err)
@@ -955,15 +946,15 @@ func (m *manager) createContainerLocked(containerName string, watchSource watche
955946
klog.V(4).Infof("GPU metrics may be unavailable/incomplete for container %s: %s", cont.info.Name, err)
956947
}
957948
}
958-
if m.includedMetrics.Has(container.PerfMetrics) {
959-
perfCgroupPath, err := handler.GetCgroupPath("perf_event")
949+
}
950+
if m.includedMetrics.Has(container.PerfMetrics) {
951+
perfCgroupPath, err := handler.GetCgroupPath("perf_event")
952+
if err != nil {
953+
klog.Warningf("Error getting perf_event cgroup path: %q", err)
954+
} else {
955+
cont.perfCollector, err = m.perfManager.GetCollector(perfCgroupPath)
960956
if err != nil {
961-
klog.Warningf("Error getting perf_event cgroup path: %q", err)
962-
} else {
963-
cont.perfCollector, err = m.perfManager.GetCollector(perfCgroupPath)
964-
if err != nil {
965-
klog.Errorf("Perf event metrics will not be available for container %q: %v", containerName, err)
966-
}
957+
klog.Errorf("Perf event metrics will not be available for container %q: %v", containerName, err)
967958
}
968959
}
969960
}

0 commit comments

Comments
 (0)