Optimizing looping over namespaces

Signed-off-by: Harshal Patil <harshal.patil@in.ibm.com>
This commit is contained in:
Harshal Patil 2017-04-25 15:56:40 +05:30
parent 94cfb7955b
commit c44d4fa6ed
1 changed files with 11 additions and 10 deletions

View File

@ -1454,18 +1454,17 @@ func (c *linuxContainer) orderNamespacePaths(namespaces map[configs.NamespaceTyp
configs.NEWNS, configs.NEWNS,
} }
// Remove namespaces that we don't need to join.
var nsTypes []configs.NamespaceType
for _, ns := range order { for _, ns := range order {
if c.config.Namespaces.Contains(ns) {
nsTypes = append(nsTypes, ns) // Remove namespaces that we don't need to join.
if !c.config.Namespaces.Contains(ns) {
continue
} }
}
for _, nsType := range nsTypes { if p, ok := namespaces[ns]; ok && p != "" {
if p, ok := namespaces[nsType]; ok && p != "" {
// check if the requested namespace is supported // check if the requested namespace is supported
if !configs.IsNamespaceSupported(nsType) { if !configs.IsNamespaceSupported(ns) {
return nil, newSystemError(fmt.Errorf("namespace %s is not supported", nsType)) return nil, newSystemError(fmt.Errorf("namespace %s is not supported", ns))
} }
// only set to join this namespace if it exists // only set to join this namespace if it exists
if _, err := os.Lstat(p); err != nil { if _, err := os.Lstat(p); err != nil {
@ -1476,9 +1475,11 @@ func (c *linuxContainer) orderNamespacePaths(namespaces map[configs.NamespaceTyp
if strings.ContainsRune(p, ',') { if strings.ContainsRune(p, ',') {
return nil, newSystemError(fmt.Errorf("invalid path %s", p)) return nil, newSystemError(fmt.Errorf("invalid path %s", p))
} }
paths = append(paths, fmt.Sprintf("%s:%s", configs.NsName(nsType), p)) paths = append(paths, fmt.Sprintf("%s:%s", configs.NsName(ns), p))
} }
} }
return paths, nil return paths, nil
} }