Skip to content

Commit

Permalink
Remove systemd docker container name check
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson committed Feb 6, 2016
1 parent 960b4e9 commit 31dcb5f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 50 deletions.
50 changes: 5 additions & 45 deletions container/docker/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ import (
"regexp"
"strconv"
"strings"
"sync"

"github.com/google/cadvisor/container"
"github.com/google/cadvisor/container/libcontainer"
"github.com/google/cadvisor/fs"
info "github.com/google/cadvisor/info/v1"
"github.com/google/cadvisor/utils"

"github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
"github.com/opencontainers/runc/libcontainer/cgroups"
)

var ArgDockerEndpoint = flag.String("docker", "unix:///var/run/docker.sock", "docker endpoint")
Expand All @@ -46,9 +43,7 @@ var dockerRunDir = flag.String("docker_run", "/var/run/docker", "Absolute path t

// Regexp that identifies docker cgroups, containers started with
// --cgroup-parent have another prefix than 'docker'
var dockerCgroupRegexp = regexp.MustCompile(`.+-([a-z0-9]{64})\.scope$`)

var noSystemd = flag.Bool("nosystemd", false, "Explicitly disable systemd support for Docker containers")
var dockerCgroupRegexp = regexp.MustCompile(`([a-z0-9]{64})`)

var dockerEnvWhitelist = flag.String("docker_env_metadata_whitelist", "", "a comma-separated list of environment variable keys that needs to be collected for docker containers")

Expand All @@ -58,36 +53,10 @@ func DockerStateDir() string {
return libcontainer.DockerStateDir(*dockerRootDir)
}

// Whether the system is using Systemd.
var useSystemd = false
var check = sync.Once{}

const (
dockerRootDirKey = "Root Dir"
)

func UseSystemd() bool {
check.Do(func() {
if *noSystemd {
return
}
// Check for system.slice in systemd and cpu cgroup.
for _, cgroupType := range []string{"name=systemd", "cpu"} {
mnt, err := cgroups.FindCgroupMountpoint(cgroupType)
if err == nil {
// systemd presence does not mean systemd controls cgroups.
// If system.slice cgroup exists, then systemd is taking control.
// This breaks if user creates system.slice manually :)
if utils.FileExists(path.Join(mnt, "system.slice")) {
useSystemd = true
break
}
}
}
})
return useSystemd
}

func RootDir() string {
return *dockerRootDir
}
Expand Down Expand Up @@ -150,21 +119,15 @@ func (self *dockerFactory) NewContainerHandler(name string, inHostNamespace bool
func ContainerNameToDockerId(name string) string {
id := path.Base(name)

// Turn systemd cgroup name into Docker ID.
if UseSystemd() {
if matches := dockerCgroupRegexp.FindStringSubmatch(id); matches != nil {
id = matches[1]
}
if matches := dockerCgroupRegexp.FindStringSubmatch(id); matches != nil {
return matches[1]
}

return id
}

func isContainerName(name string) bool {
if UseSystemd() {
return dockerCgroupRegexp.MatchString(path.Base(name))
}
return true
return dockerCgroupRegexp.MatchString(path.Base(name))
}

// Docker handles all containers under /docker
Expand Down Expand Up @@ -216,10 +179,6 @@ func parseDockerVersion(full_version_string string) ([]int, error) {

// Register root container before running this function!
func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo) error {
if UseSystemd() {
glog.Infof("System is using systemd")
}

client, err := Client()
if err != nil {
return fmt.Errorf("unable to communicate with docker daemon: %v", err)
Expand Down Expand Up @@ -278,6 +237,7 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo) error {
storageDriver: storageDriver(sd),
storageDir: storageDir,
}

container.RegisterContainerHandlerFactory(f)
return nil
}
5 changes: 0 additions & 5 deletions validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,6 @@ func validateDockerInfo() (string, string) {
execDriver := info.Get("ExecutionDriver")
storageDriver := info.Get("Driver")
desc := fmt.Sprintf("Docker exec driver is %s. Storage driver is %s.\n", execDriver, storageDriver)
if docker.UseSystemd() {
desc += "\tsystemd is being used to create cgroups.\n"
} else {
desc += "\tCgroups are being created through cgroup filesystem.\n"
}
if strings.Contains(execDriver, "native") {
stateFile := docker.DockerStateDir()
if !utils.FileExists(stateFile) {
Expand Down

0 comments on commit 31dcb5f

Please sign in to comment.