Check docker container existance the same way as raw & rkt
This commit is contained in:
parent
4a8f3e4c93
commit
dc6415aef7
@ -191,3 +191,13 @@ func MakeCgroupPaths(mountPoints map[string]string, name string) map[string]stri
|
||||
|
||||
return cgroupPaths
|
||||
}
|
||||
|
||||
func CgroupExists(cgroupPaths map[string]string) bool {
|
||||
// If any cgroup exists, the container is still alive.
|
||||
for _, cgroupPath := range cgroupPaths {
|
||||
if utils.FileExists(cgroupPath) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ func (self *dockerContainerHandler) StopWatchingSubcontainers() error {
|
||||
}
|
||||
|
||||
func (self *dockerContainerHandler) Exists() bool {
|
||||
return containerlibcontainer.Exists(*dockerRootDir, *dockerRunDir, self.id)
|
||||
return common.CgroupExists(self.cgroupPaths)
|
||||
}
|
||||
|
||||
func DockerInfo() (docker.DockerInfo, error) {
|
||||
|
@ -1,50 +0,0 @@
|
||||
// Copyright 2015 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package libcontainer
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
"github.com/google/cadvisor/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
// Relative path to the libcontainer execdriver directory.
|
||||
libcontainerExecDriverPath = "execdriver/native"
|
||||
// Absolute path of the containerd directory.
|
||||
containerdPath = "/run/containerd"
|
||||
)
|
||||
|
||||
// Gets the path to the libcontainer configuration.
|
||||
func configPath(dockerRun, containerID string) string {
|
||||
return path.Join(dockerRun, libcontainerExecDriverPath, containerID, "state.json")
|
||||
}
|
||||
|
||||
func containerdConfigPath(dockerRun, containerID string) string {
|
||||
return path.Join(containerdPath, containerID, "state.json")
|
||||
}
|
||||
|
||||
// Gets the path to the old libcontainer configuration.
|
||||
func oldConfigPath(dockerRoot, containerID string) string {
|
||||
return path.Join(dockerRoot, libcontainerExecDriverPath, containerID, "container.json")
|
||||
}
|
||||
|
||||
// Gets whether the specified container exists.
|
||||
func Exists(dockerRoot, dockerRun, containerID string) bool {
|
||||
// New or old config must exist for the container to be considered alive.
|
||||
return utils.FileExists(containerdConfigPath(dockerRun, containerID)) ||
|
||||
utils.FileExists(configPath(dockerRun, containerID)) ||
|
||||
utils.FileExists(oldConfigPath(dockerRoot, containerID))
|
||||
}
|
@ -26,7 +26,6 @@ import (
|
||||
"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/google/cadvisor/utils/machine"
|
||||
|
||||
"github.com/golang/glog"
|
||||
@ -444,11 +443,5 @@ func (self *rawContainerHandler) StopWatchingSubcontainers() error {
|
||||
}
|
||||
|
||||
func (self *rawContainerHandler) Exists() bool {
|
||||
// If any cgroup exists, the container is still alive.
|
||||
for _, cgroupPath := range self.cgroupPaths {
|
||||
if utils.FileExists(cgroupPath) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return common.CgroupExists(self.cgroupPaths)
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ import (
|
||||
"github.com/google/cadvisor/container/libcontainer"
|
||||
"github.com/google/cadvisor/fs"
|
||||
info "github.com/google/cadvisor/info/v1"
|
||||
"github.com/google/cadvisor/utils"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/golang/glog"
|
||||
@ -324,11 +323,5 @@ func (handler *rktContainerHandler) StopWatchingSubcontainers() error {
|
||||
}
|
||||
|
||||
func (handler *rktContainerHandler) Exists() bool {
|
||||
// If any cgroup exists, the container is still alive.
|
||||
for _, cgroupPath := range handler.cgroupPaths {
|
||||
if utils.FileExists(cgroupPath) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return common.CgroupExists(handler.cgroupPaths)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user