Start() exits gracefully when there are no factories.
This allows us to handle the case where there are no factories as happens when testing in a non-container environment. We will still serve the machine information that is available.
This commit is contained in:
parent
4e2479bcab
commit
ffdb6f5c7d
@ -48,6 +48,14 @@ func RegisterContainerHandlerFactory(factory ContainerHandlerFactory) {
|
||||
factories = append(factories, factory)
|
||||
}
|
||||
|
||||
// Returns whether there are any container handler factories registered.
|
||||
func HasFactories() bool {
|
||||
factoriesLock.Lock()
|
||||
defer factoriesLock.Unlock()
|
||||
|
||||
return len(factories) != 0
|
||||
}
|
||||
|
||||
// Create a new ContainerHandler for the specified container.
|
||||
func NewContainerHandler(name string) (ContainerHandler, error) {
|
||||
factoriesLock.RLock()
|
||||
|
@ -175,8 +175,19 @@ func (self *manager) Start() error {
|
||||
}
|
||||
}
|
||||
|
||||
// Watch for OOMs.
|
||||
err := self.watchForNewOoms()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to start OOM watcher, will not get OOM events: %v", err)
|
||||
}
|
||||
|
||||
// If there are no factories, don't start any housekeeping and serve the information we do have.
|
||||
if !container.HasFactories() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create root and then recover all containers.
|
||||
err := self.createContainer("/")
|
||||
err = self.createContainer("/")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -194,10 +205,6 @@ func (self *manager) Start() error {
|
||||
return err
|
||||
}
|
||||
self.quitChannels = append(self.quitChannels, quitWatcher)
|
||||
err = self.watchForNewOoms()
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to start OOM watcher, will not get OOM events: %v", err)
|
||||
}
|
||||
|
||||
// Look for new containers in the main housekeeping thread.
|
||||
quitGlobalHousekeeping := make(chan error)
|
||||
|
Loading…
Reference in New Issue
Block a user