> nerdctl uses this package for netns, for finch one of our customer requested it for their systems which uses nerdctl to create a container and have a custom network namespace the container connects to.
Signed-off-by: Shubharanshu Mahapatra <shubhum@amazon.com>
Linting is disabled on Windows, as the current build-tags do not
properly exclude non-unix platforms;
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 1.0348ms"
Error: level=error msg="[linters_context] typechecking error: D:\\a\\netns\\netns\\netns.go:28:18: Stat_t not declared by package unix"
Error: level=error msg="[linters_context] typechecking error: D:\\a\\netns\\netns\\netns.go:29:17: Fstat not declared by package unix"
Error: level=error msg="[linters_context] typechecking error: D:\\a\\netns\\netns\\netns.go:32:17: Fstat not declared by package unix"
Error: level=error msg="[linters_context] typechecking error: D:\\a\\netns\\netns\\netns.go:43:13: Stat_t not declared by package unix"
Error: level=error msg="[linters_context] typechecking error: D:\\a\\netns\\netns\\netns.go:44:17: Fstat not declared by package unix"
Error: level=error msg="[linters_context] typechecking error: D:\\a\\netns\\netns\\netns.go:56:13: Stat_t not declared by package unix"
Error: level=error msg="[linters_context] typechecking error: D:\\a\\netns\\netns\\netns.go:57:17: Fstat not declared by package unix"
Error: level=error msg="[linters_context] typechecking error: D:\\a\\netns\\netns\\netns.go:71:17: Close not declared by package unix"
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Test against the "oldest" supported version and the current version
of go. Go 1.17 is kept in this matrix as it is the minimum version
specified in go.mod, and maintaining compatibility with go 1.17 is
currently not much of a burden. Most projects using this module are
using newer versions than that, so we can drop the old version if
it becomes too much of a burden.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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>
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>
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>
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>
- 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>
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>
- 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>
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>
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().
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>
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.