Skip to content

Commit

Permalink
Merge pull request #1573 from derekwaynecarr/ingore_docker_mount
Browse files Browse the repository at this point in the history
Ignore any .mount cgroup in docker
  • Loading branch information
derekwaynecarr authored Jan 16, 2017
2 parents 1fa56cb + 4ad5c58 commit c30a9e7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
16 changes: 10 additions & 6 deletions container/docker/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,21 @@ func ContainerNameToDockerId(name string) string {
return id
}

// isContainerName returns true if the cgroup with associated name
// corresponds to a docker container.
func isContainerName(name string) bool {
// always ignore .mount cgroup even if associated with docker and delegate to systemd
if strings.HasSuffix(name, ".mount") {
return false
}
return dockerCgroupRegexp.MatchString(path.Base(name))
}

// Docker handles all containers under /docker
func (self *dockerFactory) CanHandleAndAccept(name string) (bool, bool, error) {
// docker factory accepts all containers it can handle.
canAccept := true

// if the container is not associated with docker, we can't handle it or accept it.
if !isContainerName(name) {
return false, canAccept, fmt.Errorf("invalid container name")
return false, false, nil
}

// Check if the container is known to docker and it is active.
Expand All @@ -160,10 +164,10 @@ func (self *dockerFactory) CanHandleAndAccept(name string) (bool, bool, error) {
// We assume that if Inspect fails then the container is not known to docker.
ctnr, err := self.client.ContainerInspect(context.Background(), id)
if err != nil || !ctnr.State.Running {
return false, canAccept, fmt.Errorf("error inspecting container: %v", err)
return false, true, fmt.Errorf("error inspecting container: %v", err)
}

return true, canAccept, nil
return true, true, nil
}

func (self *dockerFactory) DebugInfo() map[string][]string {
Expand Down
21 changes: 21 additions & 0 deletions container/docker/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,24 @@ func TestEnsureThinLsKernelVersion(t *testing.T) {
}
}
}

func TestIsContainerName(t *testing.T) {
tests := []struct {
name string
expected bool
}{
{
name: "/system.slice/var-lib-docker-overlay-9f086b233ab7c786bf8b40b164680b658a8f00e94323868e288d6ce20bc92193-merged.mount",
expected: false,
},
{
name: "/system.slice/docker-72e5a5ff5eef3c4222a6551b992b9360a99122f77d2229783f0ee0946dfd800e.scope",
expected: true,
},
}
for _, test := range tests {
if actual := isContainerName(test.name); actual != test.expected {
t.Errorf("%s: expected: %v, actual: %v", test.name, test.expected, actual)
}
}
}

0 comments on commit c30a9e7

Please sign in to comment.