Commit Graph

83 Commits

Author SHA1 Message Date
Subhransu 4c46424d73
Adding file path for nerdctl and finch (#87)
> 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>
2024-08-13 12:31:45 -07:00
dependabot[bot] d37cca38c2
Bump golangci/golangci-lint-action from 5 to 6 (#86)
Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 5 to 6.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v5...v6)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-13 14:59:00 -07:00
dependabot[bot] 261288576c
Bump golangci/golangci-lint-action from 4 to 5 (#83)
Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 4 to 5.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v4...v5)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-01 16:04:06 -07:00
dependabot[bot] 9469873f46
Bump golangci/golangci-lint-action from 3 to 4 (#82)
Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3 to 4.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-12 09:47:33 -07:00
dependabot[bot] ae796331e5
Bump actions/setup-go from 4 to 5 (#80)
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 4 to 5.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-12 09:46:38 -07:00
dependabot[bot] fa017945dd
Bump actions/checkout from 3 to 4 (#78)
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-13 07:07:42 -07:00
dependabot[bot] 16c2fa0b2f
Bump actions/setup-go from 3 to 4 (#73)
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 3 to 4.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-04 22:05:19 -07:00
Matthieu MOREL df76f818b3
enable gocritic, gosec, gosimple, govet unconvert, unparam, unused and whitespace linters (#72)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-03-27 09:41:34 -07:00
Matthieu MOREL 364b2a2cb9
ci(lint): enable errcheck, errorlint, gci, misspell, nonamedreturns and staticcheck linters (#71)
Enable the following linters:
  - errcheck
  - errorlint
  - gci
  - misspell
  - nonamedreturns
  - staticcheck

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-03-25 17:04:45 -07:00
Matthieu MOREL 59920981a6
ci(lint): setup YAML Lint step (#68)
Setup YAMLLint

---------

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-02-05 09:30:06 -08:00
杨刚 7a452d2d15
code clean for the Ns(none) return string. (#67)
Signed-off-by: yanggang <gang.yang@daocloud.io>
2023-01-23 10:27:00 -08:00
Sebastiaan van Stijn 1104d961a9 gha: add golangci-lint
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>
2023-01-18 13:02:58 -08:00
Sebastiaan van Stijn 4ed91700c8 gha: add basic test
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>
2023-01-18 13:02:58 -08:00
Jeff Widman 8590eaee85 Make Dependabot watch github actions 2023-01-16 13:07:19 -08:00
Jeff Widman 7cae74baef Drop note about `go` `1.10` compatibility
Now that we require `go` `1.17`, this note is no longer relevant.
2023-01-13 12:20:54 -08: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