Skip to content

Commit

Permalink
cgroups: Fix race to load cgroup.hostRoot option
Browse files Browse the repository at this point in the history
While loading, the package 'pkg/cgroups/manager' sets the global variable 'cgroupRoot' from the 'pkg/cgroups' package.
This occurs before the configuration is fully loaded and the correct path is set in the 'pkg/cgroups' package.

This variable is later used by the 'validateCgroupPath' function.
As a result, the 'validateCgroupPath' function always works with the default value instead of the user-defined one.

Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
  • Loading branch information
kvaps committed Aug 17, 2023
1 parent 016c170 commit ceca6e4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/cgroups/manager/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

var (
cgroupRoot = cgroups.GetCgroupRoot()
// example default cgroup path in kubernetes environments
// /kubepods/burstable/pod1858680e-b044-4fd5-9dd4-f137e30e2180/e275d1a37782ab30008aa3ae6666cccefe53b3a14a2ab5a8dc459939107c8c0
defaultCgroupBasePath = "/kubepods"
Expand Down Expand Up @@ -164,7 +163,7 @@ func getSystemdContainerPathCommon(subPaths []string, podId string, containerId
}

func validateCgroupPath(path string) (string, error) {
fullPath := cgroupRoot + path
fullPath := cgroups.GetCgroupRoot() + path

if _, err := fschecker.Stat(fullPath); err == nil {
return fullPath, nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/cgroups/manager/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

. "github.com/cilium/checkmate"

"github.com/cilium/cilium/pkg/cgroups"
"github.com/cilium/cilium/pkg/checker"
v1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/api/core/v1"
)
Expand All @@ -30,6 +31,7 @@ var (
fsMockSystemdNested = fsMock{
getFullPath(nestedSystemdCgroupBasePath): struct{}{},
}
cgroupRoot = cgroups.GetCgroupRoot()
cDefaultPath = cgroupRoot + "/kubepods/burstable/pod1858680e-b044-4fd5-9dd4-f137e30e2180/" + c1Id
cDefaultGuaranteedPath = cgroupRoot + "/kubepods/pod1858680e-b044-4fd5-9dd4-f137e30e2180/" + c1Id
cSystemdPath = cgroupRoot + "/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod1858680e_b044_4fd5_9dd4_f137e30e2180.slice/" + "cri-containerd-" + c1Id + ".scope"
Expand Down

0 comments on commit ceca6e4

Please sign in to comment.