Skip to content

Commit

Permalink
Merge pull request kubernetes#492 from vmarmol/nested
Browse files Browse the repository at this point in the history
Detect Docker containers by asking the Docker.
  • Loading branch information
rjnagal committed Feb 6, 2015
2 parents f2efed3 + 131a0c2 commit 3d07070
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions container/docker/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,31 +94,14 @@ func (self *dockerFactory) NewContainerHandler(name string) (handler container.C
return
}

// Returns whether the specified full container name corresponds to a Docker container.
func IsDockerContainerName(name string) bool {
if useSystemd {
// In systemd systems the containers are: /system.slice/docker-{ID}
return strings.HasPrefix(name, "/system.slice/docker-")
} else {
return strings.HasPrefix(name, "/docker/")
}
}

// Returns the Docker ID from the full container name.
func ContainerNameToDockerId(name string) string {
id := path.Base(name)

// Turn systemd cgroup name into Docker ID.
if useSystemd {
const systemdDockerPrefix = "docker-"
if strings.HasPrefix(id, systemdDockerPrefix) {
id = id[len(systemdDockerPrefix):]
}

const systemdScopeSuffix = ".scope"
if strings.HasSuffix(id, systemdScopeSuffix) {
id = id[:len(id)-len(systemdScopeSuffix)]
}
id = strings.TrimPrefix(id, "docker-")
id = strings.TrimSuffix(id, ".scope")
}

return id
Expand All @@ -136,10 +119,6 @@ func FullContainerName(dockerId string) string {

// Docker handles all containers under /docker
func (self *dockerFactory) CanHandle(name string) (bool, error) {
if !IsDockerContainerName(name) {
return false, nil
}

// Check if the container is known to docker and it is active.
id := ContainerNameToDockerId(name)

Expand Down

0 comments on commit 3d07070

Please sign in to comment.