From ce47f2db662444819214e60bdb8e384ba72df59c Mon Sep 17 00:00:00 2001 From: Jonathan Boulle Date: Fri, 1 May 2015 16:27:30 -0700 Subject: [PATCH] networking: podRoot -> rktRoot rktRoot is misleading as the directory is really the root of a specific pod. Also add a TODO note that this is currently only ever set to cwd (i.e. "."), and hence necessitates relative paths. --- networking/net_plugin.go | 2 +- networking/networking.go | 24 ++++++++++++------------ networking/podenv.go | 8 ++++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/networking/net_plugin.go b/networking/net_plugin.go index 5011723..6333cc5 100644 --- a/networking/net_plugin.go +++ b/networking/net_plugin.go @@ -60,7 +60,7 @@ func (e *podEnv) pluginPaths() []string { // try 3rd-party path first return []string{ UserNetPluginsPath, - filepath.Join(common.Stage1RootfsPath(e.rktRoot), BuiltinNetPluginsPath), + filepath.Join(common.Stage1RootfsPath(e.podRoot), BuiltinNetPluginsPath), } } diff --git a/networking/networking.go b/networking/networking.go index cb61fa4..19090f2 100644 --- a/networking/networking.go +++ b/networking/networking.go @@ -49,13 +49,14 @@ type Networking struct { nets []activeNet } -// Setup creates a new networking namespace and executes network -// plugins to setup private networking. It returns in the new pod -// namespace -func Setup(rktRoot string, podID types.UUID, fps []ForwardedPort) (*Networking, error) { +// Setup creates a new networking namespace and executes network plugins to +// setup private networking. It returns in the new pod namespace +func Setup(podRoot string, podID types.UUID, fps []ForwardedPort) (*Networking, error) { + // TODO(jonboulle): currently podRoot is _always_ ".", and behaviour in other + // circumstances is untested. This should be cleaned up. n := Networking{ podEnv: podEnv{ - rktRoot: rktRoot, + podRoot: podRoot, podID: podID, }, } @@ -101,11 +102,11 @@ func Setup(rktRoot string, podID types.UUID, fps []ForwardedPort) (*Networking, // Load creates the Networking object from saved state. // Assumes the current netns is that of the host. -func Load(rktRoot string, podID *types.UUID) (*Networking, error) { +func Load(podRoot string, podID *types.UUID) (*Networking, error) { // the current directory is pod root - pdirfd, err := syscall.Open(rktRoot, syscall.O_RDONLY|syscall.O_DIRECTORY, 0) + pdirfd, err := syscall.Open(podRoot, syscall.O_RDONLY|syscall.O_DIRECTORY, 0) if err != nil { - return nil, fmt.Errorf("Failed to open pod root directory (%v): %v", rktRoot, err) + return nil, fmt.Errorf("Failed to open pod root directory (%v): %v", podRoot, err) } defer syscall.Close(pdirfd) @@ -139,7 +140,7 @@ func Load(rktRoot string, podID *types.UUID) (*Networking, error) { return &Networking{ podEnv: podEnv{ - rktRoot: rktRoot, + podRoot: podRoot, podID: *podID, }, hostNS: hostNS, @@ -164,8 +165,7 @@ func (n *Networking) GetDefaultHostIP() net.IP { // Teardown cleans up a produced Networking object. func (n *Networking) Teardown() { // Teardown everything in reverse order of setup. - // This should be indempotent -- be tolerant of - // missing stuff + // This should be idempotent -- be tolerant of missing stuff if err := n.enterHostNS(); err != nil { log.Printf("Error switching to host netns: %v", err) @@ -217,7 +217,7 @@ func (e *Networking) Save() error { nis = append(nis, *n.runtime) } - return netinfo.Save(e.rktRoot, nis) + return netinfo.Save(e.podRoot, nis) } func newNetNS() (hostNS, childNS *os.File, err error) { diff --git a/networking/podenv.go b/networking/podenv.go index 48c3763..af5e92f 100644 --- a/networking/podenv.go +++ b/networking/podenv.go @@ -45,7 +45,7 @@ const ( // describing the environment in which the pod // is running in type podEnv struct { - rktRoot string + podRoot string podID types.UUID } @@ -64,7 +64,7 @@ func (e *podEnv) loadNets() ([]activeNet, error) { } if !netExists(nets, "default") { - defPath := path.Join(common.Stage1RootfsPath(e.rktRoot), DefaultNetPath) + defPath := path.Join(common.Stage1RootfsPath(e.podRoot), DefaultNetPath) n, err := loadNet(defPath) if err != nil { return nil, err @@ -76,11 +76,11 @@ func (e *podEnv) loadNets() ([]activeNet, error) { } func (e *podEnv) podNSPath() string { - return filepath.Join(e.rktRoot, "netns") + return filepath.Join(e.podRoot, "netns") } func (e *podEnv) netDir() string { - return filepath.Join(e.rktRoot, "net") + return filepath.Join(e.podRoot, "net") } func (e *podEnv) setupNets(nets []activeNet) error {