Commit Graph

70 Commits

Author SHA1 Message Date
Jeff Widman
13aab1c53f Fake commit to prevent Dependabot updating/rebasing PR 2023-01-13 20:32:51 +00:00
dependabot[bot]
c6c9d6a28e
Bump golang.org/x/sys from 0.2.0 to 0.4.0
Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.2.0 to 0.4.0.
- [Release notes](https://github.com/golang/sys/releases)
- [Commits](https://github.com/golang/sys/compare/v0.2.0...v0.4.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sys
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-13 20:19:17 +00:00
Sebastiaan van Stijn
9e0c8171ea go.mod: update minimum version to go1.17
golang.org/x/sys now requires go1.17 as a minimum, and otherwise
fails:

    Error: ../../../go/pkg/mod/golang.org/x/sys@v0.2.0/unix/syscall.go:83:16: undefined: unsafe.Slice
    Error: ../../../go/pkg/mod/golang.org/x/sys@v0.2.0/unix/syscall_linux.go:2256:9: undefined: unsafe.Slice
    Error: ../../../go/pkg/mod/golang.org/x/sys@v0.2.0/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
    Error: ../../../go/pkg/mod/golang.org/x/sys@v0.2.0/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice

unsafe.Slice was added in go1.17; https://pkg.go.dev/unsafe#Slice

Now that go1.17 is the minimum version, we cal also replace the deprecated io/ioutil
package (which was deprecated in go1.16).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-01-13 12:18:28 -08:00
Matthieu MOREL
a33d97be0e chore(deps): bump golang.org/x/sys to v0.2.0
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-01-13 09:58:21 -08:00
Junhuang Hong
358cc6be9e fix: named ns handler may leak 2023-01-13 09:57:54 -08:00
Sebastiaan van Stijn
a21f45a794 GetFromName: use /run/netns instead of /var/run/netns
The GetFromName() function looked for network namespaces in "/var/run",
whereas DeleteNamed() and NewNamed() used the "bindMountPath" const (which
points to "/run/netns"). While "/var/run" should be symlink to "/run" on
most distros, this is not a guarantee, so use the same paths so that at
least the code is consistently using this path.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-01-13 09:56:59 -08:00
Sebastiaan van Stijn
e6c3e222e7 don't deprecate bindMountPath
The bindMountPath const was in the same group as the deprecated consts,
which were deprecated as a whole. This patch moves the bindMountPath
const outside of the group to make sure it's not considered deprecated.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-01-13 09:56:59 -08:00
Sebastiaan van Stijn
5db4494c3d make deprecated consts an alias, and don't use internally
The consts were deprecated in favor of their counterparts in
golang.org/x/sys/unix. This patch makes them an alias / sets them
to those values, which makes it more transparent that they're the
same.

Also update internal uses of the deprecated consts, as they
should no longer be used, and updated the "stub" function
to be deprecated as well.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-01-13 09:56:59 -08:00
Sebastiaan van Stijn
f2b79daebc fix unhandled error in TestGetNewSetDelete
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-01-13 09:56:59 -08:00
Sebastiaan van Stijn
974e44d5c7 fix build-tags for non-linux platforms
- NSHandle could only be used on Unix systems. Given that all other parts
  of the code are only implemented on Linux (not for other Unix-y platforms),
  I moved this file to be Linux-only.
- Rename "_unspecified" to "_others", which is a common suffix for such cases.
- Introduce stubs for NSHandle for non-Linux platforms.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-01-13 09:56:59 -08:00
Sebastiaan van Stijn
69e96a5f5f move package description to a doc.go
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-01-13 09:56:59 -08:00
Sebastiaan van Stijn
95c0705164 make tests linux-only
These tests were testing functionality that was only supported on
Linux, but stubbed for other platforms, so move them to a linux-only
file.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-01-13 09:56:59 -08:00
Sebastiaan van Stijn
22a9216d17 remove redundant build-tag comments
- The "linux" build tags were redundant as they were in a _linux file
- The project already states that go1.10 is a minimum (and long obsolete,
  so unlikely to be used still).
- Format the remaining build-tags for current go versions.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-01-13 09:56:59 -08:00
Pratik Raj
43aa913982 feat: dependabot workflow automation for updating dependency
Signed-off-by: Pratik Raj <Rajpratik71@gmail.com>
2022-11-02 13:11:37 -07:00
Will Fantom
e414ad8e04 Expose named functions when not linux 2022-10-27 17:28:47 -07:00
Stephan Boyer
0c37222dc3 Update the documentation for netns.NewNamed
Update the documentation for `netns.NewNamed` to fix https://github.com/vishvananda/netns/issues/50.
2022-10-27 17:28:32 -07:00
Jeff Widman
18c4f42342 Migrate syscall --> golang.org/x/sys/unix, redux
This completes the migration from `syscall` --> `golang.org/x/sys/unix`
which was started in https://github.com/vishvananda/netns/pull/40:
> The syscall package is deprecated and no longer updated as per
https://golang.org/pkg/syscall/. Use the golang.org/x/sys/unix package
instead.
2022-09-13 08:08:50 -07:00
Steffen Vogel
50045581ed extend GetFromDocker() to support also newer distros with cgroup v2 support 2021-11-01 11:37:01 -05:00
Alessandro Boch
2eb08e3e57
Merge pull request #47 from imilchev/upstream
Add support for detecting netns for all possible QoS in Kubernetes
2021-01-04 10:30:10 -08:00
Alessandro Boch
c4f3ca719c
Merge pull request #30 from brb/safer-netns
Add go1.10 build constraint
2020-12-29 17:22:02 -08:00
Ivan Milchev
dc62fc17c5 Add support for detecting netns for all possible QoS in Kubernetes 2020-12-28 13:01:43 +01:00
Thomas Maurice
db3c7e526a Allows to create and delete named network namespaces 2020-07-28 12:18:58 -07:00
fanjiyun
1e46305e59 Set O_CLOEXEC when opening a network namespace
Signed-off-by: fanjiyun <fan.jiyun@zte.com.cn>
2020-07-28 12:17:46 -07:00
Tobias Klauser
52d707b772 Use golang.org/x/sys/unix instead of syscall
The syscall package is deprecated and no longer updated as per
https://golang.org/pkg/syscall/. Use the golang.org/x/sys/unix package
instead, which also provides a wrapper for SYS_SETNS, so the syscall
number encoding depending on runtime.GOARCH can be dropped.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2020-05-19 21:18:08 -07:00
Tobias Klauser
0a2b9b5464 Add support for Go modules
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2019-11-06 09:42:02 -08:00
matte21
7109fa855b Remove useless setting of new netns from README.md
Remove from the README.md example the instruction which explicitly sets
the newly created netns as the netns of the current OS Thread. The removed
instruction is not needed because the setting is implicitly done by netns.New().
2019-06-25 16:32:34 -07:00
Damon Wang
4eab129c9c add ns support mips64le arch
go env info
[root@node152 weaver]# go env
GOARCH="mips64le"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOHOSTARCH="mips64le"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/goworkspace"
GORACE=""
GOROOT="/home/longxin/workspace/go"
GOTMPDIR=""
GOTOOLDIR="/home/longxin/workspace/go/pkg/tool/linux_mips64le"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -mabi=64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build929428261=/tmp/go-build -gno-record-gcc-switches"
2019-06-25 16:30:54 -07:00
Martin Povišer
6ed29a60d4 Document that New() changes the current ns 2019-06-25 16:29:52 -07:00
Tonis Tiigi
a1b8f1f3bd add riscv64 support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2019-06-25 16:29:20 -07:00
Martynas Pumputis
b8d862b06e Add go1.10 build constraint
This prevents netns from being used on older Go runtimes on which it's
not safe to perform any state manipulations of a scheduling thread
(https://github.com/golang/go/issues/20676).

Signed-off-by: Martynas Pumputis <m@lambda.lt>
2018-12-21 10:35:45 +01:00
Serguei Bezverkhi
13995c7128 In contaner path fix
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
2018-07-20 10:01:59 -07:00
Serguei Bezverkhi
ef6f981729 Adding new location for containers in recent k8s 1.11+
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
2018-07-18 18:39:51 -07:00
Yann Ramin
be1fbeda19 Search kubepods for Docker containers
When using Kubernetes with CNI and Docker, the cgroup entries are
dropped in yet another creative place. This adds yet another attempt
to locate the container within `kubepods`. All of this because there
are no named network namespaces created.
2017-11-11 00:15:04 +00:00
Lars Lehtonen
86bef332bf fixed swallowed err variable 2017-07-06 18:15:35 -07:00
harche
54f0e4339c Fixing README.md
newly created ns must be set for net.Interfaces() to return interfaces from that ns.
2017-02-19 15:34:38 -08:00
Vladimir Stefanovic
8d723eab75 Add mips, mipsle to the SYS_SETNS map 2017-02-19 15:33:56 -08:00
Zhang Wei
2c9454e4fc Fix typo
Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
2016-12-19 10:16:06 -08:00
Ethan J. Jackson
6dbaac84c5 Add missing stub functions to netns_unspecified.go 2016-12-19 10:15:34 -08:00
Lei Jitang
8ba1072b58 Typo: fix typo in readme (#16)
Signed-off-by: Lei Jitang <leijitang@huawei.com>
2016-04-29 22:37:23 -07:00
Zhenfang Wei
11c323fbd3 Fixed the docker netns detection err on xenial (#15)
With ubuntu 16.04 and docker-engine 1.11, the docker netns detection
function failed to look for the correct location of task file. This
change fixed the issue.

Signed-off-by: Zhenfang Wei <kopkop@gmail.com>
2016-04-29 22:37:00 -07:00
Ashok Mudukutore
003a74c01d Added function UniqueId which returns a string that uniquely identifies (#14)
the namespace associated with a network handle.
2016-04-29 22:36:46 -07:00
Vish Ishaya
1fec6582c0 Merge pull request #13 from michelmno/master
netns add ppc64 same as ppc64le
2016-03-17 13:51:17 -07:00
Michel Normand
b49e32fb51 netns add ppc64 same as ppc64le 2016-03-04 06:47:31 +01:00
Vish Ishaya
b87167f660 Merge pull request #12 from tanksuzuki/fix-example-code
Fix example code
2016-02-26 09:07:17 -08:00
Asuka Suzuki
dd823845f2 Fix example code 2016-02-24 23:51:21 +09:00
Vish Ishaya
f0b8d0aad3 Merge pull request #11 from krhubert/master
refactor netns
2016-01-13 11:21:53 -08:00
Vish Ishaya
b73cffff5a Merge pull request #10 from nickethier/docker-cgroup-mount
Container cgroup location under systemd
2015-12-03 08:41:21 -08:00
Hubert
dff3fd240d docs: fix typo 2015-09-16 17:01:26 +02:00
Hubert
f19e34ff16 dosc: fix golint errors 2015-09-16 16:52:32 +02:00
Hubert
3e1d42c9bc refactor: remove netns_linux_*.go files and use map instead 2015-09-16 16:47:11 +02:00