Track a container by all of its aliases

This commit is contained in:
Victor Marmol 2014-06-13 18:24:59 -07:00
parent 16611eb4a0
commit 410c27a84f
4 changed files with 19 additions and 6 deletions

View File

@ -61,7 +61,7 @@ func newDockerContainerHandler(
if err != nil {
return nil, fmt.Errorf("unable to inspect container %v: %v", name, err)
}
handler.aliases = append(handler.aliases, ctnr.Name)
handler.aliases = append(handler.aliases, path.Join("/docker", ctnr.Name))
return handler, nil
}

View File

@ -114,7 +114,7 @@ func (self *factoryManager) NewContainerHandler(path string) (ContainerHandler,
err := fmt.Errorf("nil factory for container %v", path)
return nil, err
}
log.Printf("container handler factory for %v is %v\n", path, factory)
log.Printf("Container handler factory for %v is %v\n", path, factory)
return factory.NewContainerHandler(path)
}

View File

@ -91,7 +91,12 @@ func NewContainerData(containerName string) (*containerData, error) {
return nil, err
}
cont.handler = handler
cont.info.Name = containerName
ref, err := handler.ContainerReference()
if err != nil {
return nil, err
}
cont.info.Name = ref.Name
cont.info.Aliases = ref.Aliases
cont.info.Stats = list.New()
cont.stop = make(chan bool, 1)

View File

@ -112,7 +112,8 @@ func (m *manager) GetContainerInfo(containerName string) (*info.ContainerInfo, e
// Make a copy of the info for the user.
ret := &info.ContainerInfo{
ContainerReference: info.ContainerReference{
Name: cinfo.Name,
Name: cinfo.Name,
Aliases: cinfo.Aliases,
},
Subcontainers: cinfo.Subcontainers,
Spec: cinfo.Spec,
@ -152,9 +153,13 @@ func (m *manager) createContainer(containerName string) (*containerData, error)
m.containersLock.Lock()
defer m.containersLock.Unlock()
log.Printf("Added container: %s", containerName)
// Add the container name and all its aliases.
m.containers[containerName] = cont
for _, alias := range cont.info.Aliases {
m.containers[alias] = cont
}
}()
log.Printf("Added container: %s (aliases: %s)", containerName, cont.info.Aliases)
// Start the container's housekeeping.
cont.Start()
@ -202,7 +207,10 @@ func (m *manager) getContainersDiff() (added []info.ContainerReference, removed
// Determine which were added and which were removed.
allContainersSet := make(map[string]*containerData)
for name, d := range m.containers {
allContainersSet[name] = d
// Only add the canonical name.
if d.info.Name == name {
allContainersSet[name] = d
}
}
for _, c := range allContainers {
delete(allContainersSet, c.Name)