Remove systemd docker container name check
This commit is contained in:
parent
960b4e99e3
commit
31dcb5f3b7
@ -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")
|
||||
@ -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")
|
||||
|
||||
@ -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
|
||||
}
|
||||
@ -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
|
||||
@ -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)
|
||||
@ -278,6 +237,7 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo) error {
|
||||
storageDriver: storageDriver(sd),
|
||||
storageDir: storageDir,
|
||||
}
|
||||
|
||||
container.RegisterContainerHandlerFactory(f)
|
||||
return nil
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user