pkg/ns: fixed the check for network namespace path.
authorAvinash Sridharan <avinash@mesosphere.io>
Wed, 24 Aug 2016 23:49:50 +0000 (23:49 +0000)
committerAvinash Sridharan <avinash@mesosphere.io>
Wed, 31 Aug 2016 21:41:00 +0000 (21:41 +0000)
The expectation on older kernels (< 3.19) was to have the network
namespace always be a directory. This is not true if the network
namespace is bind mounted to a file, and will make the plugin fail
erroneously in such cases. The fix is to remove this assumption
completely and just do a basic check on the file system types being
returned.

Fixes #288

pkg/ns/ns.go

index e29f712..5c531c0 100644 (file)
@@ -20,7 +20,6 @@ import (
        "os"
        "path"
        "runtime"
-       "strings"
        "sync"
        "syscall"
 
@@ -101,19 +100,7 @@ func IsNSorErr(nspath string) error {
        }
 
        switch stat.Type {
-       case PROCFS_MAGIC:
-               // Kernel < 3.19
-
-               validPathContent := "ns/"
-               validName := strings.Contains(nspath, validPathContent)
-               if !validName {
-                       return NSPathNotNSErr{msg: fmt.Sprintf("path %q doesn't contain %q", nspath, validPathContent)}
-               }
-
-               return nil
-       case NSFS_MAGIC:
-               // Kernel >= 3.19
-
+       case PROCFS_MAGIC, NSFS_MAGIC:
                return nil
        default:
                return NSPathNotNSErr{msg: fmt.Sprintf("unknown FS magic on %q: %x", nspath, stat.Type)}