pkg/ns, pkg/types: refactored non linux build fix code to
Make GetCurrentNS platform specific instead of getCurrentThreadNetNSPath
This commit is contained in:
parent
c3cde44480
commit
0dc0845c51
13
pkg/ns/ns.go
13
pkg/ns/ns.go
@ -15,7 +15,6 @@
|
|||||||
package ns
|
package ns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -62,14 +61,6 @@ type netNS struct {
|
|||||||
// netNS implements the NetNS interface
|
// netNS implements the NetNS interface
|
||||||
var _ NetNS = &netNS{}
|
var _ NetNS = &netNS{}
|
||||||
|
|
||||||
// NotImplementedError is used to indicate that a method is not implemented for the given platform
|
|
||||||
var NotImplementedError = errors.New("Not Implemented")
|
|
||||||
|
|
||||||
// Returns an object representing the current OS thread's network namespace
|
|
||||||
func GetCurrentNS() (NetNS, error) {
|
|
||||||
return GetNS(getCurrentThreadNetNSPath())
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// https://github.com/torvalds/linux/blob/master/include/uapi/linux/magic.h
|
// https://github.com/torvalds/linux/blob/master/include/uapi/linux/magic.h
|
||||||
NSFS_MAGIC = 0x6e736673
|
NSFS_MAGIC = 0x6e736673
|
||||||
@ -139,7 +130,7 @@ func (ns *netNS) Do(toRun func(NetNS) error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
containedCall := func(hostNS NetNS) error {
|
containedCall := func(hostNS NetNS) error {
|
||||||
threadNS, err := GetNS(getCurrentThreadNetNSPath())
|
threadNS, err := GetCurrentNS()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open current netns: %v", err)
|
return fmt.Errorf("failed to open current netns: %v", err)
|
||||||
}
|
}
|
||||||
@ -155,7 +146,7 @@ func (ns *netNS) Do(toRun func(NetNS) error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save a handle to current network namespace
|
// save a handle to current network namespace
|
||||||
hostNS, err := GetNS(getCurrentThreadNetNSPath())
|
hostNS, err := GetCurrentNS()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to open current namespace: %v", err)
|
return fmt.Errorf("Failed to open current namespace: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,11 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Returns an object representing the current OS thread's network namespace
|
||||||
|
func GetCurrentNS() (NetNS, error) {
|
||||||
|
return GetNS(getCurrentThreadNetNSPath())
|
||||||
|
}
|
||||||
|
|
||||||
func getCurrentThreadNetNSPath() string {
|
func getCurrentThreadNetNSPath() string {
|
||||||
// /proc/self/ns/net returns the namespace of the main thread, not
|
// /proc/self/ns/net returns the namespace of the main thread, not
|
||||||
// of whatever thread this goroutine is running on. Make sure we
|
// of whatever thread this goroutine is running on. Make sure we
|
||||||
|
@ -16,18 +16,21 @@
|
|||||||
|
|
||||||
package ns
|
package ns
|
||||||
|
|
||||||
func getCurrentThreadNetNSPath() string {
|
import "github.com/containernetworking/cni/pkg/types"
|
||||||
return ""
|
|
||||||
|
// Returns an object representing the current OS thread's network namespace
|
||||||
|
func GetCurrentNS() (NetNS, error) {
|
||||||
|
return nil, types.NotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNS() (NetNS, error) {
|
func NewNS() (NetNS, error) {
|
||||||
return nil, NotImplementedError
|
return nil, types.NotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *netNS) Close() error {
|
func (ns *netNS) Close() error {
|
||||||
return NotImplementedError
|
return types.NotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *netNS) Set() error {
|
func (ns *netNS) Set() error {
|
||||||
return NotImplementedError
|
return types.NotImplementedError
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@ -178,3 +179,6 @@ func prettyPrint(obj interface{}) error {
|
|||||||
_, err = os.Stdout.Write(data)
|
_, err = os.Stdout.Write(data)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotImplementedError is used to indicate that a method is not implemented for the given platform
|
||||||
|
var NotImplementedError = errors.New("Not Implemented")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user