|
@@ -6,6 +6,7 @@ import (
|
|
|
"net"
|
|
|
"os"
|
|
|
"os/exec"
|
|
|
+ "path/filepath"
|
|
|
"runtime"
|
|
|
"strconv"
|
|
|
"strings"
|
|
@@ -21,7 +22,7 @@ import (
|
|
|
"github.com/vishvananda/netns"
|
|
|
)
|
|
|
|
|
|
-const prefix = "/var/run/docker/netns"
|
|
|
+const defaultPrefix = "/var/run/docker"
|
|
|
|
|
|
var (
|
|
|
once sync.Once
|
|
@@ -30,6 +31,7 @@ var (
|
|
|
gpmWg sync.WaitGroup
|
|
|
gpmCleanupPeriod = 60 * time.Second
|
|
|
gpmChan = make(chan chan struct{})
|
|
|
+ prefix = defaultPrefix
|
|
|
)
|
|
|
|
|
|
// The networkNamespace type is the linux implementation of the Sandbox
|
|
@@ -48,12 +50,21 @@ type networkNamespace struct {
|
|
|
sync.Mutex
|
|
|
}
|
|
|
|
|
|
+// SetBasePath sets the base url prefix for the ns path
|
|
|
+func SetBasePath(path string) {
|
|
|
+ prefix = path
|
|
|
+}
|
|
|
+
|
|
|
func init() {
|
|
|
reexec.Register("netns-create", reexecCreateNamespace)
|
|
|
}
|
|
|
|
|
|
+func basePath() string {
|
|
|
+ return filepath.Join(prefix, "netns")
|
|
|
+}
|
|
|
+
|
|
|
func createBasePath() {
|
|
|
- err := os.MkdirAll(prefix, 0755)
|
|
|
+ err := os.MkdirAll(basePath(), 0755)
|
|
|
if err != nil {
|
|
|
panic("Could not create net namespace path directory")
|
|
|
}
|
|
@@ -142,7 +153,7 @@ func GenerateKey(containerID string) string {
|
|
|
indexStr string
|
|
|
tmpkey string
|
|
|
)
|
|
|
- dir, err := ioutil.ReadDir(prefix)
|
|
|
+ dir, err := ioutil.ReadDir(basePath())
|
|
|
if err != nil {
|
|
|
return ""
|
|
|
}
|
|
@@ -172,7 +183,7 @@ func GenerateKey(containerID string) string {
|
|
|
maxLen = len(containerID)
|
|
|
}
|
|
|
|
|
|
- return prefix + "/" + containerID[:maxLen]
|
|
|
+ return basePath() + "/" + containerID[:maxLen]
|
|
|
}
|
|
|
|
|
|
// NewSandbox provides a new sandbox instance created in an os specific way
|