Merge pull request #555 from vmarmol/docs
Register container handler factories in manager.New().
This commit is contained in:
commit
60b223596c
12
cadvisor.go
12
cadvisor.go
@ -27,8 +27,6 @@ import (
|
|||||||
auth "github.com/abbot/go-http-auth"
|
auth "github.com/abbot/go-http-auth"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/google/cadvisor/api"
|
"github.com/google/cadvisor/api"
|
||||||
"github.com/google/cadvisor/container/docker"
|
|
||||||
"github.com/google/cadvisor/container/raw"
|
|
||||||
"github.com/google/cadvisor/healthz"
|
"github.com/google/cadvisor/healthz"
|
||||||
"github.com/google/cadvisor/info"
|
"github.com/google/cadvisor/info"
|
||||||
"github.com/google/cadvisor/manager"
|
"github.com/google/cadvisor/manager"
|
||||||
@ -76,16 +74,6 @@ func main() {
|
|||||||
glog.Fatalf("Failed to create a Container Manager: %s", err)
|
glog.Fatalf("Failed to create a Container Manager: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register Docker.
|
|
||||||
if err := docker.Register(containerManager); err != nil {
|
|
||||||
glog.Errorf("Docker registration failed: %v.", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register the raw driver.
|
|
||||||
if err := raw.Register(containerManager); err != nil {
|
|
||||||
glog.Fatalf("Raw registration failed: %v.", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Basic health handler.
|
// Basic health handler.
|
||||||
if err := healthz.RegisterHandler(); err != nil {
|
if err := healthz.RegisterHandler(); err != nil {
|
||||||
glog.Fatalf("Failed to register healthz handler: %s", err)
|
glog.Fatalf("Failed to register healthz handler: %s", err)
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/google/cadvisor/container"
|
"github.com/google/cadvisor/container"
|
||||||
"github.com/google/cadvisor/container/docker"
|
"github.com/google/cadvisor/container/docker"
|
||||||
|
"github.com/google/cadvisor/container/raw"
|
||||||
"github.com/google/cadvisor/events"
|
"github.com/google/cadvisor/events"
|
||||||
"github.com/google/cadvisor/info"
|
"github.com/google/cadvisor/info"
|
||||||
"github.com/google/cadvisor/storage/memory"
|
"github.com/google/cadvisor/storage/memory"
|
||||||
@ -115,6 +116,18 @@ func New(memoryStorage *memory.InMemoryStorage, sysfs sysfs.SysFs) (Manager, err
|
|||||||
|
|
||||||
newManager.eventHandler = events.NewEventManager()
|
newManager.eventHandler = events.NewEventManager()
|
||||||
|
|
||||||
|
// Register Docker container factory.
|
||||||
|
err = docker.Register(newManager)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("Docker container factory registration failed: %v.", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register the raw driver.
|
||||||
|
err = raw.Register(newManager)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("registration of the raw container factory failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
return newManager, nil
|
return newManager, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,11 +40,11 @@ func createManagerAndAddContainers(
|
|||||||
t *testing.T,
|
t *testing.T,
|
||||||
) *manager {
|
) *manager {
|
||||||
container.ClearContainerHandlerFactories()
|
container.ClearContainerHandlerFactories()
|
||||||
mif, err := New(memoryStorage, sysfs)
|
mif := &manager{
|
||||||
if err != nil {
|
containers: make(map[namespacedContainerName]*containerData),
|
||||||
t.Fatal(err)
|
quitChannels: make([]chan error, 0, 2),
|
||||||
|
memoryStorage: memoryStorage,
|
||||||
}
|
}
|
||||||
if ret, ok := mif.(*manager); ok {
|
|
||||||
for _, name := range containers {
|
for _, name := range containers {
|
||||||
mockHandler := container.NewMockContainerHandler(name)
|
mockHandler := container.NewMockContainerHandler(name)
|
||||||
spec := itest.GenerateRandomContainerSpec(4)
|
spec := itest.GenerateRandomContainerSpec(4)
|
||||||
@ -56,22 +56,19 @@ func createManagerAndAddContainers(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
ret.containers[namespacedContainerName{
|
mif.containers[namespacedContainerName{
|
||||||
Name: name,
|
Name: name,
|
||||||
}] = cont
|
}] = cont
|
||||||
// Add Docker containers under their namespace.
|
// Add Docker containers under their namespace.
|
||||||
if strings.HasPrefix(name, "/docker") {
|
if strings.HasPrefix(name, "/docker") {
|
||||||
ret.containers[namespacedContainerName{
|
mif.containers[namespacedContainerName{
|
||||||
Namespace: docker.DockerNamespace,
|
Namespace: docker.DockerNamespace,
|
||||||
Name: strings.TrimPrefix(name, "/docker/"),
|
Name: strings.TrimPrefix(name, "/docker/"),
|
||||||
}] = cont
|
}] = cont
|
||||||
}
|
}
|
||||||
f(mockHandler)
|
f(mockHandler)
|
||||||
}
|
}
|
||||||
return ret
|
return mif
|
||||||
}
|
|
||||||
t.Fatal("Wrong type")
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expect a manager with the specified containers and query. Returns the manager, map of ContainerInfo objects,
|
// Expect a manager with the specified containers and query. Returns the manager, map of ContainerInfo objects,
|
||||||
@ -206,17 +203,6 @@ func TestDockerContainersInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNew(t *testing.T) {
|
|
||||||
memoryStorage := memory.New(60, nil)
|
|
||||||
manager, err := New(memoryStorage, &fakesysfs.FakeSysFs{})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Expected manager.New to succeed: %s", err)
|
|
||||||
}
|
|
||||||
if manager == nil {
|
|
||||||
t.Fatalf("Expected returned manager to not be nil")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNewNilManager(t *testing.T) {
|
func TestNewNilManager(t *testing.T) {
|
||||||
_, err := New(nil, nil)
|
_, err := New(nil, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user