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
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// 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.
|
// defines an interface for container operation handlers.
|
||||||
package container
|
package container
|
||||||
|
|
||||||
import "github.com/google/cadvisor/info"
|
import "github.com/google/cadvisor/info"
|
||||||
|
|
||||||
// ListType describes whether listing should be just for a
|
// ListType describes whether listing should be just for a
|
||||||
// specific container or performed recurisvely.
|
// specific container or performed recursively.
|
||||||
type ListType int
|
type ListType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -27,8 +27,7 @@ const (
|
|||||||
ListRecursive
|
ListRecursive
|
||||||
)
|
)
|
||||||
|
|
||||||
// SubcontainerEventType indicated whether the event
|
// SubcontainerEventType indicates an addition or deletion event.
|
||||||
// specifies an addition or deletion.
|
|
||||||
type SubcontainerEventType int
|
type SubcontainerEventType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// TODO(cAdvosor): Package comment.
|
// TODO(cAdvisor): Package comment.
|
||||||
package raw
|
package raw
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -165,7 +165,8 @@ func listDirectories(dirpath string, parent string, recursive bool, output map[s
|
|||||||
|
|
||||||
// List subcontainers if asked to.
|
// List subcontainers if asked to.
|
||||||
if recursive {
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,7 +205,8 @@ func (self *rawContainerHandler) ListProcesses(listType container.ListType) ([]i
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *rawContainerHandler) watchDirectory(dir string, containerName string) error {
|
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
|
return err
|
||||||
}
|
}
|
||||||
self.watches[containerName] = struct{}{}
|
self.watches[containerName] = struct{}{}
|
||||||
@ -264,7 +266,8 @@ func (self *rawContainerHandler) processEvent(event *inotify.Event, events chan
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New container was created, watch it.
|
// 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
|
return err
|
||||||
}
|
}
|
||||||
case eventType == container.SubcontainerDelete:
|
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.
|
// Watch this container (all its cgroups) and all subdirectories.
|
||||||
for _, mnt := range self.cgroupSubsystems.mounts {
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// Package mananger provides per-container manager support.
|
|
||||||
package manager
|
package manager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -197,7 +196,8 @@ func (c *containerData) updateStats() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err = c.storageDriver.AddStats(ref, stats); err != nil {
|
err = c.storageDriver.AddStats(ref, stats)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -83,7 +83,8 @@ func TestUpdateSubcontainersWithError(t *testing.T) {
|
|||||||
fmt.Errorf("some error"),
|
fmt.Errorf("some error"),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := cd.updateSubcontainers(); err == nil {
|
err := cd.updateSubcontainers()
|
||||||
|
if err == nil {
|
||||||
t.Fatal("updateSubcontainers should return error")
|
t.Fatal("updateSubcontainers should return error")
|
||||||
}
|
}
|
||||||
if len(cd.info.Subcontainers) != 0 {
|
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)
|
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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,11 +87,13 @@ type manager struct {
|
|||||||
// Start the container manager.
|
// Start the container manager.
|
||||||
func (self *manager) Start() error {
|
func (self *manager) Start() error {
|
||||||
// Create root and then recover all containers.
|
// Create root and then recover all containers.
|
||||||
if err := self.createContainer("/"); err != nil {
|
err := self.createContainer("/")
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
glog.Infof("Starting recovery of all containers")
|
glog.Infof("Starting recovery of all containers")
|
||||||
if err := self.detectSubcontainers("/"); err != nil {
|
err = self.detectSubcontainers("/")
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
glog.Infof("Recovery completed")
|
glog.Infof("Recovery completed")
|
||||||
@ -111,7 +113,8 @@ func (self *manager) Start() error {
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
// Check for new containers.
|
// Check for new containers.
|
||||||
if err := self.detectSubcontainers("/"); err != nil {
|
err := self.detectSubcontainers("/")
|
||||||
|
if err != nil {
|
||||||
glog.Errorf("Failed to detect containers: %s", err)
|
glog.Errorf("Failed to detect containers: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,8 +238,9 @@ func (m *manager) createContainer(containerName string) error {
|
|||||||
m.containersLock.Lock()
|
m.containersLock.Lock()
|
||||||
defer m.containersLock.Unlock()
|
defer m.containersLock.Unlock()
|
||||||
|
|
||||||
// Check that the container didn't already exist
|
// Check that the container didn't already exist\
|
||||||
if _, ok := m.containers[containerName]; ok {
|
_, ok := m.containers[containerName]
|
||||||
|
if ok {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +315,8 @@ func (m *manager) getContainersDiff(containerName string) (added []info.Containe
|
|||||||
// Added containers
|
// Added containers
|
||||||
for _, c := range allContainers {
|
for _, c := range allContainers {
|
||||||
delete(allContainersSet, c.Name)
|
delete(allContainersSet, c.Name)
|
||||||
if _, ok := m.containers[c.Name]; !ok {
|
_, ok := m.containers[c.Name]
|
||||||
|
if !ok {
|
||||||
added = append(added, c)
|
added = append(added, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -341,7 +346,8 @@ func (m *manager) detectSubcontainers(containerName string) error {
|
|||||||
|
|
||||||
// Remove the old containers.
|
// Remove the old containers.
|
||||||
for _, cont := range removed {
|
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)
|
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.
|
// Register for new subcontainers.
|
||||||
events := make(chan container.SubcontainerEvent, 16)
|
events := make(chan container.SubcontainerEvent, 16)
|
||||||
if err := root.handler.WatchSubcontainers(events); err != nil {
|
err := root.handler.WatchSubcontainers(events)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +386,6 @@ func (self *manager) watchForNewContainers() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Listen to events from the container handler.
|
// Listen to events from the container handler.
|
||||||
var err error
|
|
||||||
for event := range events {
|
for event := range events {
|
||||||
switch {
|
switch {
|
||||||
case event.EventType == container.SubcontainerAdd:
|
case event.EventType == container.SubcontainerAdd:
|
||||||
|
@ -176,7 +176,8 @@ func TestNew(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNewNilManager(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")
|
t.Fatalf("Expected nil manager to return error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user