Merge pull request #64987 from dashpole/update_cadvisor_v0.30.1

Automatic merge from submit-queue (batch tested with PRs 64503, 64903, 64643, 64987). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Update cadvisor godeps to v0.30.1 to revert cadvisor#1916

/sig node
/priority critical-urgent
/kind bug

**What this PR does / why we need it**:

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #64933

**Release note**:

```release-note
Kubernetes depends on v0.30.1 of cAdvisor
```
pull/8/head
Kubernetes Submit Queue 2018-06-11 17:29:22 -07:00 committed by GitHub
commit 6decdaa775
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 127 additions and 125 deletions

172
Godeps/Godeps.json generated
View File

@ -1508,218 +1508,218 @@
}, },
{ {
"ImportPath": "github.com/google/cadvisor/accelerators", "ImportPath": "github.com/google/cadvisor/accelerators",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/api", "ImportPath": "github.com/google/cadvisor/api",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/cache/memory", "ImportPath": "github.com/google/cadvisor/cache/memory",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/client/v2", "ImportPath": "github.com/google/cadvisor/client/v2",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/collector", "ImportPath": "github.com/google/cadvisor/collector",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/container", "ImportPath": "github.com/google/cadvisor/container",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/container/common", "ImportPath": "github.com/google/cadvisor/container/common",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/container/containerd", "ImportPath": "github.com/google/cadvisor/container/containerd",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/container/crio", "ImportPath": "github.com/google/cadvisor/container/crio",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/container/docker", "ImportPath": "github.com/google/cadvisor/container/docker",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/container/libcontainer", "ImportPath": "github.com/google/cadvisor/container/libcontainer",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/container/raw", "ImportPath": "github.com/google/cadvisor/container/raw",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/container/rkt", "ImportPath": "github.com/google/cadvisor/container/rkt",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/container/systemd", "ImportPath": "github.com/google/cadvisor/container/systemd",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/devicemapper", "ImportPath": "github.com/google/cadvisor/devicemapper",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/events", "ImportPath": "github.com/google/cadvisor/events",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/fs", "ImportPath": "github.com/google/cadvisor/fs",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/healthz", "ImportPath": "github.com/google/cadvisor/healthz",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/http", "ImportPath": "github.com/google/cadvisor/http",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/http/mux", "ImportPath": "github.com/google/cadvisor/http/mux",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/info/v1", "ImportPath": "github.com/google/cadvisor/info/v1",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/info/v2", "ImportPath": "github.com/google/cadvisor/info/v2",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/machine", "ImportPath": "github.com/google/cadvisor/machine",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/manager", "ImportPath": "github.com/google/cadvisor/manager",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/manager/watcher", "ImportPath": "github.com/google/cadvisor/manager/watcher",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/manager/watcher/raw", "ImportPath": "github.com/google/cadvisor/manager/watcher/raw",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/manager/watcher/rkt", "ImportPath": "github.com/google/cadvisor/manager/watcher/rkt",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/metrics", "ImportPath": "github.com/google/cadvisor/metrics",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/pages", "ImportPath": "github.com/google/cadvisor/pages",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/pages/static", "ImportPath": "github.com/google/cadvisor/pages/static",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/storage", "ImportPath": "github.com/google/cadvisor/storage",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/summary", "ImportPath": "github.com/google/cadvisor/summary",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/utils", "ImportPath": "github.com/google/cadvisor/utils",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/utils/cloudinfo", "ImportPath": "github.com/google/cadvisor/utils/cloudinfo",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/utils/cpuload", "ImportPath": "github.com/google/cadvisor/utils/cpuload",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/utils/cpuload/netlink", "ImportPath": "github.com/google/cadvisor/utils/cpuload/netlink",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/utils/docker", "ImportPath": "github.com/google/cadvisor/utils/docker",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/utils/oomparser", "ImportPath": "github.com/google/cadvisor/utils/oomparser",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/utils/sysfs", "ImportPath": "github.com/google/cadvisor/utils/sysfs",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/utils/sysinfo", "ImportPath": "github.com/google/cadvisor/utils/sysinfo",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/validate", "ImportPath": "github.com/google/cadvisor/validate",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/version", "ImportPath": "github.com/google/cadvisor/version",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/cadvisor/zfs", "ImportPath": "github.com/google/cadvisor/zfs",
"Comment": "v0.30.0", "Comment": "v0.30.1",
"Rev": "f6359ffcbdec3c228bf312e6939ea6edf556ce52" "Rev": "49c4fae21f151168b09758b7da1968fed8cd56a0"
}, },
{ {
"ImportPath": "github.com/google/certificate-transparency-go", "ImportPath": "github.com/google/certificate-transparency-go",

View File

@ -5,18 +5,18 @@ go_library(
srcs = [ srcs = [
"container_hints.go", "container_hints.go",
"fsHandler.go", "fsHandler.go",
"fsnotify_watcher.go",
"helpers.go", "helpers.go",
"inotify_watcher.go",
], ],
importpath = "github.com/google/cadvisor/container/common", importpath = "github.com/google/cadvisor/container/common",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
"//vendor/github.com/fsnotify/fsnotify:go_default_library",
"//vendor/github.com/golang/glog:go_default_library", "//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/google/cadvisor/container:go_default_library", "//vendor/github.com/google/cadvisor/container:go_default_library",
"//vendor/github.com/google/cadvisor/fs:go_default_library", "//vendor/github.com/google/cadvisor/fs:go_default_library",
"//vendor/github.com/google/cadvisor/info/v1:go_default_library", "//vendor/github.com/google/cadvisor/info/v1:go_default_library",
"//vendor/github.com/google/cadvisor/utils:go_default_library", "//vendor/github.com/google/cadvisor/utils:go_default_library",
"//vendor/golang.org/x/exp/inotify:go_default_library",
], ],
) )

View File

@ -40,7 +40,7 @@ func DebugInfo(watches map[string][]string) map[string][]string {
lines = append(lines, fmt.Sprintf("\t%s", cg)) lines = append(lines, fmt.Sprintf("\t%s", cg))
} }
} }
out["Fsnotify watches"] = lines out["Inotify watches"] = lines
return out return out
} }

View File

@ -17,15 +17,15 @@ package common
import ( import (
"sync" "sync"
"github.com/fsnotify/fsnotify" "golang.org/x/exp/inotify"
) )
// Watcher for container-related fsnotify events in the cgroup hierarchy. // Watcher for container-related inotify events in the cgroup hierarchy.
// //
// Implementation is thread-safe. // Implementation is thread-safe.
type FsnotifyWatcher struct { type InotifyWatcher struct {
// Underlying fsnotify watcher. // Underlying inotify watcher.
watcher *fsnotify.Watcher watcher *inotify.Watcher
// Map of containers being watched to cgroup paths watched for that container. // Map of containers being watched to cgroup paths watched for that container.
containersWatched map[string]map[string]bool containersWatched map[string]map[string]bool
@ -34,28 +34,28 @@ type FsnotifyWatcher struct {
lock sync.Mutex lock sync.Mutex
} }
func NewFsnotifyWatcher() (*FsnotifyWatcher, error) { func NewInotifyWatcher() (*InotifyWatcher, error) {
w, err := fsnotify.NewWatcher() w, err := inotify.NewWatcher()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &FsnotifyWatcher{ return &InotifyWatcher{
watcher: w, watcher: w,
containersWatched: make(map[string]map[string]bool), containersWatched: make(map[string]map[string]bool),
}, nil }, nil
} }
// Add a watch to the specified directory. Returns if the container was already being watched. // Add a watch to the specified directory. Returns if the container was already being watched.
func (iw *FsnotifyWatcher) AddWatch(containerName, dir string) (bool, error) { func (iw *InotifyWatcher) AddWatch(containerName, dir string) (bool, error) {
iw.lock.Lock() iw.lock.Lock()
defer iw.lock.Unlock() defer iw.lock.Unlock()
cgroupsWatched, alreadyWatched := iw.containersWatched[containerName] cgroupsWatched, alreadyWatched := iw.containersWatched[containerName]
// Register an fsnotify notification. // Register an inotify notification.
if !cgroupsWatched[dir] { if !cgroupsWatched[dir] {
err := iw.watcher.Add(dir) err := iw.watcher.AddWatch(dir, inotify.IN_CREATE|inotify.IN_DELETE|inotify.IN_MOVE)
if err != nil { if err != nil {
return alreadyWatched, err return alreadyWatched, err
} }
@ -74,7 +74,7 @@ func (iw *FsnotifyWatcher) AddWatch(containerName, dir string) (bool, error) {
} }
// Remove watch from the specified directory. Returns if this was the last watch on the specified container. // Remove watch from the specified directory. Returns if this was the last watch on the specified container.
func (iw *FsnotifyWatcher) RemoveWatch(containerName, dir string) (bool, error) { func (iw *InotifyWatcher) RemoveWatch(containerName, dir string) (bool, error) {
iw.lock.Lock() iw.lock.Lock()
defer iw.lock.Unlock() defer iw.lock.Unlock()
@ -84,9 +84,9 @@ func (iw *FsnotifyWatcher) RemoveWatch(containerName, dir string) (bool, error)
return false, nil return false, nil
} }
// Remove the fsnotify watch if it exists. // Remove the inotify watch if it exists.
if cgroupsWatched[dir] { if cgroupsWatched[dir] {
err := iw.watcher.Remove(dir) err := iw.watcher.RemoveWatch(dir)
if err != nil { if err != nil {
return false, nil return false, nil
} }
@ -103,22 +103,22 @@ func (iw *FsnotifyWatcher) RemoveWatch(containerName, dir string) (bool, error)
} }
// Errors are returned on this channel. // Errors are returned on this channel.
func (iw *FsnotifyWatcher) Error() chan error { func (iw *InotifyWatcher) Error() chan error {
return iw.watcher.Errors return iw.watcher.Error
} }
// Events are returned on this channel. // Events are returned on this channel.
func (iw *FsnotifyWatcher) Event() chan fsnotify.Event { func (iw *InotifyWatcher) Event() chan *inotify.Event {
return iw.watcher.Events return iw.watcher.Event
} }
// Closes the fsnotify watcher. // Closes the inotify watcher.
func (iw *FsnotifyWatcher) Close() error { func (iw *InotifyWatcher) Close() error {
return iw.watcher.Close() return iw.watcher.Close()
} }
// Returns a map of containers to the cgroup paths being watched. // Returns a map of containers to the cgroup paths being watched.
func (iw *FsnotifyWatcher) GetWatches() map[string][]string { func (iw *InotifyWatcher) GetWatches() map[string][]string {
out := make(map[string][]string, len(iw.containersWatched)) out := make(map[string][]string, len(iw.containersWatched))
for k, v := range iw.containersWatched { for k, v := range iw.containersWatched {
out[k] = mapToSlice(v) out[k] = mapToSlice(v)

View File

@ -40,8 +40,8 @@ type rawFactory struct {
// Information about mounted filesystems. // Information about mounted filesystems.
fsInfo fs.FsInfo fsInfo fs.FsInfo
// Watcher for fsnotify events. // Watcher for inotify events.
watcher *common.FsnotifyWatcher watcher *common.InotifyWatcher
// List of metrics to be ignored. // List of metrics to be ignored.
ignoreMetrics map[container.MetricKind]struct{} ignoreMetrics map[container.MetricKind]struct{}
@ -78,7 +78,7 @@ func Register(machineInfoFactory info.MachineInfoFactory, fsInfo fs.FsInfo, igno
return fmt.Errorf("failed to find supported cgroup mounts for the raw factory") return fmt.Errorf("failed to find supported cgroup mounts for the raw factory")
} }
watcher, err := common.NewFsnotifyWatcher() watcher, err := common.NewInotifyWatcher()
if err != nil { if err != nil {
return err return err
} }

View File

@ -49,7 +49,7 @@ func isRootCgroup(name string) bool {
return name == "/" return name == "/"
} }
func newRawContainerHandler(name string, cgroupSubsystems *libcontainer.CgroupSubsystems, machineInfoFactory info.MachineInfoFactory, fsInfo fs.FsInfo, watcher *common.FsnotifyWatcher, rootFs string, ignoreMetrics container.MetricSet) (container.ContainerHandler, error) { func newRawContainerHandler(name string, cgroupSubsystems *libcontainer.CgroupSubsystems, machineInfoFactory info.MachineInfoFactory, fsInfo fs.FsInfo, watcher *common.InotifyWatcher, rootFs string, ignoreMetrics container.MetricSet) (container.ContainerHandler, error) {
cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems.MountPoints, name) cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems.MountPoints, name)
cHints, err := common.GetContainerHintsFromFile(*common.ArgContainerHints) cHints, err := common.GetContainerHintsFromFile(*common.ArgContainerHints)

View File

@ -6,11 +6,11 @@ go_library(
importpath = "github.com/google/cadvisor/manager/watcher/raw", importpath = "github.com/google/cadvisor/manager/watcher/raw",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
"//vendor/github.com/fsnotify/fsnotify:go_default_library",
"//vendor/github.com/golang/glog:go_default_library", "//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/google/cadvisor/container/common:go_default_library", "//vendor/github.com/google/cadvisor/container/common:go_default_library",
"//vendor/github.com/google/cadvisor/container/libcontainer:go_default_library", "//vendor/github.com/google/cadvisor/container/libcontainer:go_default_library",
"//vendor/github.com/google/cadvisor/manager/watcher:go_default_library", "//vendor/github.com/google/cadvisor/manager/watcher:go_default_library",
"//vendor/golang.org/x/exp/inotify:go_default_library",
], ],
) )

View File

@ -27,8 +27,8 @@ import (
"github.com/google/cadvisor/container/libcontainer" "github.com/google/cadvisor/container/libcontainer"
"github.com/google/cadvisor/manager/watcher" "github.com/google/cadvisor/manager/watcher"
"github.com/fsnotify/fsnotify"
"github.com/golang/glog" "github.com/golang/glog"
"golang.org/x/exp/inotify"
) )
type rawContainerWatcher struct { type rawContainerWatcher struct {
@ -37,8 +37,8 @@ type rawContainerWatcher struct {
cgroupSubsystems *libcontainer.CgroupSubsystems cgroupSubsystems *libcontainer.CgroupSubsystems
// Fsnotify event watcher. // Inotify event watcher.
watcher *common.FsnotifyWatcher watcher *common.InotifyWatcher
// Signal for watcher thread to stop. // Signal for watcher thread to stop.
stopWatcher chan error stopWatcher chan error
@ -53,7 +53,7 @@ func NewRawContainerWatcher() (watcher.ContainerWatcher, error) {
return nil, fmt.Errorf("failed to find supported cgroup mounts for the raw factory") return nil, fmt.Errorf("failed to find supported cgroup mounts for the raw factory")
} }
watcher, err := common.NewFsnotifyWatcher() watcher, err := common.NewInotifyWatcher()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -121,7 +121,7 @@ func (self *rawContainerWatcher) watchDirectory(events chan watcher.ContainerEve
if cleanup { if cleanup {
_, err := self.watcher.RemoveWatch(containerName, dir) _, err := self.watcher.RemoveWatch(containerName, dir)
if err != nil { if err != nil {
glog.Warningf("Failed to remove fsnotify watch for %q: %v", dir, err) glog.Warningf("Failed to remove inotify watch for %q: %v", dir, err)
} }
} }
}() }()
@ -163,16 +163,18 @@ func (self *rawContainerWatcher) watchDirectory(events chan watcher.ContainerEve
return alreadyWatching, nil return alreadyWatching, nil
} }
func (self *rawContainerWatcher) processEvent(event fsnotify.Event, events chan watcher.ContainerEvent) error { func (self *rawContainerWatcher) processEvent(event *inotify.Event, events chan watcher.ContainerEvent) error {
// Convert the fsnotify event type to a container create or delete. // Convert the inotify event type to a container create or delete.
var eventType watcher.ContainerEventType var eventType watcher.ContainerEventType
switch { switch {
case event.Op == fsnotify.Create: case (event.Mask & inotify.IN_CREATE) > 0:
eventType = watcher.ContainerAdd eventType = watcher.ContainerAdd
case event.Op == fsnotify.Remove: case (event.Mask & inotify.IN_DELETE) > 0:
eventType = watcher.ContainerDelete eventType = watcher.ContainerDelete
case event.Op == fsnotify.Rename: case (event.Mask & inotify.IN_MOVED_FROM) > 0:
eventType = watcher.ContainerDelete eventType = watcher.ContainerDelete
case (event.Mask & inotify.IN_MOVED_TO) > 0:
eventType = watcher.ContainerAdd
default: default:
// Ignore other events. // Ignore other events.
return nil return nil