Skip to content

Commit 2776f6b

Browse files
committed
pkg/netns: remove NewNSWithName()
This API is not used anywhere, as such remove it and make the loop in NewNS() better as the netns dir parts should not be part of the loop. Signed-off-by: Paul Holzinger <[email protected]>
1 parent 8a5b951 commit 2776f6b

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

pkg/netns/netns_linux.go

+15-21
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,26 @@ func NewNSAtPath(nsPath string) (ns.NetNS, error) {
6262
// NewNS creates a new persistent (bind-mounted) network namespace and returns
6363
// an object representing that namespace, without switching to it.
6464
func NewNS() (ns.NetNS, error) {
65+
nsRunDir, err := GetNSRunDir()
66+
if err != nil {
67+
return nil, err
68+
}
69+
70+
// Create the directory for mounting network namespaces
71+
// This needs to be a shared mountpoint in case it is mounted in to
72+
// other namespaces (containers)
73+
err = makeNetnsDir(nsRunDir)
74+
if err != nil {
75+
return nil, err
76+
}
77+
6578
for i := 0; i < 10000; i++ {
6679
nsName, err := getRandomNetnsName()
6780
if err != nil {
6881
return nil, err
6982
}
70-
ns, err := NewNSWithName(nsName)
83+
nsPath := path.Join(nsRunDir, nsName)
84+
ns, err := newNSPath(nsPath)
7185
if err == nil {
7286
return ns, nil
7387
}
@@ -80,26 +94,6 @@ func NewNS() (ns.NetNS, error) {
8094
return nil, errNoFreeName
8195
}
8296

83-
// NewNSWithName creates a new persistent (bind-mounted) network namespace and returns
84-
// an object representing that namespace, without switching to it.
85-
func NewNSWithName(name string) (ns.NetNS, error) {
86-
nsRunDir, err := GetNSRunDir()
87-
if err != nil {
88-
return nil, err
89-
}
90-
91-
// Create the directory for mounting network namespaces
92-
// This needs to be a shared mountpoint in case it is mounted in to
93-
// other namespaces (containers)
94-
err = makeNetnsDir(nsRunDir)
95-
if err != nil {
96-
return nil, err
97-
}
98-
99-
nsPath := path.Join(nsRunDir, name)
100-
return newNSPath(nsPath)
101-
}
102-
10397
// NewNSFrom creates a persistent (bind-mounted) network namespace from the
10498
// given netns path, i.e. /proc/<pid>/ns/net, and returns the new full path to
10599
// the bind mounted file in the netns run dir.

0 commit comments

Comments
 (0)