Undo changes to if statements as requested by vmarmol. Fix typos in my changes.
This commit is contained in:
parent
bae82a583d
commit
8551d376d8
@ -12,14 +12,14 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Pacakge container defines types for sub-container events and also
|
||||
// Package container defines types for sub-container events and also
|
||||
// defines an interface for container operation handlers.
|
||||
package container
|
||||
|
||||
import "github.com/google/cadvisor/info"
|
||||
|
||||
// ListType describes whether listing should be just for a
|
||||
// specific container or performed recurisvely.
|
||||
// specific container or performed recursively.
|
||||
type ListType int
|
||||
|
||||
const (
|
||||
@ -27,8 +27,7 @@ const (
|
||||
ListRecursive
|
||||
)
|
||||
|
||||
// SubcontainerEventType indicated whether the event
|
||||
// specifies an addition or deletion.
|
||||
// SubcontainerEventType indicates an addition or deletion event.
|
||||
type SubcontainerEventType int
|
||||
|
||||
const (
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// TODO(cAdvosor): Package comment.
|
||||
// TODO(cAdvisor): Package comment.
|
||||
package raw
|
||||
|
||||
import (
|
||||
@ -167,7 +167,8 @@ func listDirectories(dirpath string, parent string, recursive bool, output map[s
|
||||
|
||||
// List subcontainers if asked to.
|
||||
if recursive {
|
||||
if err := listDirectories(path.Join(dirpath, entry.Name()), name, true, output); err != nil {
|
||||
err := listDirectories(path.Join(dirpath, entry.Name()), name, true, output)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -206,7 +207,8 @@ func (self *rawContainerHandler) ListProcesses(listType container.ListType) ([]i
|
||||
}
|
||||
|
||||
func (self *rawContainerHandler) watchDirectory(dir string, containerName string) error {
|
||||
if err := self.watcher.AddWatch(dir, inotify.IN_CREATE|inotify.IN_DELETE|inotify.IN_MOVE); err != nil {
|
||||
err := self.watcher.AddWatch(dir, inotify.IN_CREATE|inotify.IN_DELETE|inotify.IN_MOVE)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
self.watches[containerName] = struct{}{}
|
||||
@ -266,7 +268,8 @@ func (self *rawContainerHandler) processEvent(event *inotify.Event, events chan
|
||||
}
|
||||
|
||||
// New container was created, watch it.
|
||||
if err := self.watchDirectory(event.Name, containerName); err != nil {
|
||||
err := self.watchDirectory(event.Name, containerName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case eventType == container.SubcontainerDelete:
|
||||
@ -305,7 +308,8 @@ func (self *rawContainerHandler) WatchSubcontainers(events chan container.Subcon
|
||||
|
||||
// Watch this container (all its cgroups) and all subdirectories.
|
||||
for _, mnt := range self.cgroupSubsystems.mounts {
|
||||
if err := self.watchDirectory(path.Join(mnt.Mountpoint, self.name), self.name); err != nil {
|
||||
err := self.watchDirectory(path.Join(mnt.Mountpoint, self.name), self.name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package mananger provides per-container manager support.
|
||||
package manager
|
||||
|
||||
import (
|
||||
@ -197,7 +196,8 @@ func (c *containerData) updateStats() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = c.storageDriver.AddStats(ref, stats); err != nil {
|
||||
err = c.storageDriver.AddStats(ref, stats)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -83,7 +83,8 @@ func TestUpdateSubcontainersWithError(t *testing.T) {
|
||||
fmt.Errorf("some error"),
|
||||
)
|
||||
|
||||
if err := cd.updateSubcontainers(); err == nil {
|
||||
err := cd.updateSubcontainers()
|
||||
if err == nil {
|
||||
t.Fatal("updateSubcontainers should return error")
|
||||
}
|
||||
if len(cd.info.Subcontainers) != 0 {
|
||||
@ -105,7 +106,8 @@ func TestUpdateStats(t *testing.T) {
|
||||
|
||||
mockDriver.On("AddStats", info.ContainerReference{Name: mockHandler.Name}, stats).Return(nil)
|
||||
|
||||
if err := cd.updateStats(); err != nil {
|
||||
err := cd.updateStats()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -94,11 +94,13 @@ type manager struct {
|
||||
// Start the container manager.
|
||||
func (self *manager) Start() error {
|
||||
// Create root and then recover all containers.
|
||||
if err := self.createContainer("/"); err != nil {
|
||||
err := self.createContainer("/")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
glog.Infof("Starting recovery of all containers")
|
||||
if err := self.detectSubcontainers("/"); err != nil {
|
||||
err = self.detectSubcontainers("/")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
glog.Infof("Recovery completed")
|
||||
@ -143,6 +145,7 @@ func (self *manager) globalHousekeeping(quit chan error) {
|
||||
}
|
||||
|
||||
ticker := time.Tick(*globalHousekeepingInterval)
|
||||
<<<<<<< HEAD
|
||||
for {
|
||||
select {
|
||||
case t := <-ticker:
|
||||
@ -153,6 +156,16 @@ func (self *manager) globalHousekeeping(quit chan error) {
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to detect containers: %s", err)
|
||||
}
|
||||
=======
|
||||
for t := range ticker {
|
||||
start := time.Now()
|
||||
|
||||
// Check for new containers.
|
||||
err := self.detectSubcontainers("/")
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to detect containers: %s", err)
|
||||
}
|
||||
>>>>>>> Undo changes to if statements as requested by vmarmol. Fix typos in my changes.
|
||||
|
||||
// Log if housekeeping took too long.
|
||||
duration := time.Since(start)
|
||||
@ -278,8 +291,9 @@ func (m *manager) createContainer(containerName string) error {
|
||||
m.containersLock.Lock()
|
||||
defer m.containersLock.Unlock()
|
||||
|
||||
// Check that the container didn't already exist
|
||||
if _, ok := m.containers[containerName]; ok {
|
||||
// Check that the container didn't already exist\
|
||||
_, ok := m.containers[containerName]
|
||||
if ok {
|
||||
return true
|
||||
}
|
||||
|
||||
@ -354,7 +368,8 @@ func (m *manager) getContainersDiff(containerName string) (added []info.Containe
|
||||
// Added containers
|
||||
for _, c := range allContainers {
|
||||
delete(allContainersSet, c.Name)
|
||||
if _, ok := m.containers[c.Name]; !ok {
|
||||
_, ok := m.containers[c.Name]
|
||||
if !ok {
|
||||
added = append(added, c)
|
||||
}
|
||||
}
|
||||
@ -384,7 +399,8 @@ func (m *manager) detectSubcontainers(containerName string) error {
|
||||
|
||||
// Remove the old containers.
|
||||
for _, cont := range removed {
|
||||
if err = m.destroyContainer(cont.Name); err != nil {
|
||||
err = m.destroyContainer(cont.Name)
|
||||
if err != nil {
|
||||
glog.Errorf("failed to destroy existing container: %s: %s", cont.Name, err)
|
||||
}
|
||||
}
|
||||
@ -412,7 +428,8 @@ func (self *manager) watchForNewContainers(quit chan error) error {
|
||||
|
||||
// Register for new subcontainers.
|
||||
events := make(chan container.SubcontainerEvent, 16)
|
||||
if err := root.handler.WatchSubcontainers(events); err != nil {
|
||||
err := root.handler.WatchSubcontainers(events)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -422,6 +439,7 @@ func (self *manager) watchForNewContainers(quit chan error) error {
|
||||
}
|
||||
|
||||
// Listen to events from the container handler.
|
||||
<<<<<<< HEAD
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
@ -444,6 +462,17 @@ func (self *manager) watchForNewContainers(quit chan error) error {
|
||||
return
|
||||
}
|
||||
}
|
||||
=======
|
||||
for event := range events {
|
||||
switch {
|
||||
case event.EventType == container.SubcontainerAdd:
|
||||
err = self.createContainer(event.Name)
|
||||
case event.EventType == container.SubcontainerDelete:
|
||||
err = self.destroyContainer(event.Name)
|
||||
}
|
||||
if err != nil {
|
||||
glog.Warning("failed to process watch event: %v", err)
|
||||
>>>>>>> Undo changes to if statements as requested by vmarmol. Fix typos in my changes.
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
|
@ -176,7 +176,8 @@ func TestNew(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewNilManager(t *testing.T) {
|
||||
if _, err := New(nil); err == nil {
|
||||
_, err := New(nil)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected nil manager to return error")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user