Undo changes to if statements as requested by vmarmol. Fix typos in my changes.
This commit is contained in:
parent
f097c2b4ab
commit
cab052cc8a
@ -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 (
|
||||
@ -165,7 +165,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
|
||||
}
|
||||
}
|
||||
@ -204,7 +205,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{}{}
|
||||
@ -264,7 +266,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:
|
||||
@ -303,7 +306,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)
|
||||
}
|
||||
|
||||
|
@ -87,11 +87,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")
|
||||
@ -111,7 +113,8 @@ func (self *manager) Start() error {
|
||||
start := time.Now()
|
||||
|
||||
// Check for new containers.
|
||||
if err := self.detectSubcontainers("/"); err != nil {
|
||||
err := self.detectSubcontainers("/")
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to detect containers: %s", err)
|
||||
}
|
||||
|
||||
@ -235,8 +238,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
|
||||
}
|
||||
|
||||
@ -311,7 +315,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)
|
||||
}
|
||||
}
|
||||
@ -341,7 +346,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)
|
||||
}
|
||||
}
|
||||
@ -369,7 +375,8 @@ func (self *manager) watchForNewContainers() 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
|
||||
}
|
||||
|
||||
@ -379,7 +386,6 @@ func (self *manager) watchForNewContainers() error {
|
||||
}
|
||||
|
||||
// Listen to events from the container handler.
|
||||
var err error
|
||||
for event := range events {
|
||||
switch {
|
||||
case event.EventType == container.SubcontainerAdd:
|
||||
|
@ -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