X Tutup
Skip to content

Commit 708299c

Browse files
committed
Move RunningInUserNS() to its own package
This allows using the utility without bringing whole of "sys" with it. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent edf6484 commit 708299c

File tree

9 files changed

+38
-13
lines changed

9 files changed

+38
-13
lines changed

archive/tar_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"strings"
2525
"syscall"
2626

27-
"github.com/containerd/containerd/sys"
27+
"github.com/containerd/containerd/pkg/userns"
2828
"github.com/containerd/continuity/fs"
2929
"github.com/containerd/continuity/sysx"
3030
"github.com/pkg/errors"
@@ -87,7 +87,7 @@ func skipFile(hdr *tar.Header) bool {
8787
switch hdr.Typeflag {
8888
case tar.TypeBlock, tar.TypeChar:
8989
// cannot create a device if running in user namespace
90-
return sys.RunningInUserNS()
90+
return userns.RunningInUserNS()
9191
default:
9292
return false
9393
}

diff/apply/apply_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"github.com/containerd/containerd/archive"
2727
"github.com/containerd/containerd/errdefs"
2828
"github.com/containerd/containerd/mount"
29-
"github.com/containerd/containerd/sys"
29+
"github.com/containerd/containerd/pkg/userns"
3030
"github.com/pkg/errors"
3131
)
3232

@@ -35,7 +35,7 @@ func apply(ctx context.Context, mounts []mount.Mount, r io.Reader) error {
3535
case len(mounts) == 1 && mounts[0].Type == "overlay":
3636
// OverlayConvertWhiteout (mknod c 0 0) doesn't work in userns.
3737
// https://github.com/containerd/containerd/issues/3762
38-
if sys.RunningInUserNS() {
38+
if userns.RunningInUserNS() {
3939
break
4040
}
4141
path, parents, err := getOverlayPath(mounts[0].Options)

pkg/cri/server/service_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package server
1818

1919
import (
2020
"github.com/containerd/containerd/pkg/cap"
21-
"github.com/containerd/containerd/sys"
21+
"github.com/containerd/containerd/pkg/userns"
2222
cni "github.com/containerd/go-cni"
2323
"github.com/opencontainers/selinux/go-selinux"
2424
"github.com/pkg/errors"
@@ -33,7 +33,7 @@ const networkAttachCount = 2
3333
func (c *criService) initPlatform() error {
3434
var err error
3535

36-
if sys.RunningInUserNS() {
36+
if userns.RunningInUserNS() {
3737
if !(c.config.DisableCgroup && !c.apparmorEnabled() && c.config.RestrictOOMScoreAdj) {
3838
logrus.Warn("Running containerd in a user namespace typically requires disable_cgroup, disable_apparmor, restrict_oom_score_adj set to be true")
3939
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package sys
17+
package userns
1818

1919
import (
2020
"bufio"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
limitations under the License.
1717
*/
1818

19-
package sys
19+
package userns
2020

2121
// RunningInUserNS is a stub for non-Linux systems
2222
// Always returns false

runtime/v2/runc/v2/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ import (
4141
oomv2 "github.com/containerd/containerd/pkg/oom/v2"
4242
"github.com/containerd/containerd/pkg/process"
4343
"github.com/containerd/containerd/pkg/stdio"
44+
"github.com/containerd/containerd/pkg/userns"
4445
"github.com/containerd/containerd/runtime/v2/runc"
4546
"github.com/containerd/containerd/runtime/v2/runc/options"
4647
"github.com/containerd/containerd/runtime/v2/shim"
4748
taskAPI "github.com/containerd/containerd/runtime/v2/task"
48-
"github.com/containerd/containerd/sys"
4949
"github.com/containerd/containerd/sys/reaper"
5050
runcC "github.com/containerd/go-runc"
5151
"github.com/containerd/typeurl"
@@ -386,7 +386,7 @@ func (s *service) Start(ctx context.Context, r *taskAPI.StartRequest) (*taskAPI.
386386
logrus.WithError(err).Error("failed to get root controllers")
387387
} else {
388388
if err := cg.ToggleControllers(allControllers, cgroupsv2.Enable); err != nil {
389-
if sys.RunningInUserNS() {
389+
if userns.RunningInUserNS() {
390390
logrus.WithError(err).Debugf("failed to enable controllers (%v)", allControllers)
391391
} else {
392392
logrus.WithError(err).Errorf("failed to enable controllers (%v)", allControllers)

snapshots/overlay/overlayutils/check.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
"github.com/containerd/containerd/log"
2828
"github.com/containerd/containerd/mount"
29-
"github.com/containerd/containerd/sys"
29+
"github.com/containerd/containerd/pkg/userns"
3030
"github.com/containerd/continuity/fs"
3131
"github.com/pkg/errors"
3232
)
@@ -108,7 +108,7 @@ func Supported(root string) error {
108108
//
109109
// The "userxattr" support is not exposed in "/sys/module/overlay/parameters".
110110
func NeedsUserXAttr(d string) (bool, error) {
111-
if !sys.RunningInUserNS() {
111+
if !userns.RunningInUserNS() {
112112
// we are the real root (i.e., the root in the initial user NS),
113113
// so we do never need "userxattr" opt.
114114
return false, nil

sys/oom_unix.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"os"
2525
"strconv"
2626
"strings"
27+
28+
"github.com/containerd/containerd/pkg/userns"
2729
)
2830

2931
const (
@@ -42,7 +44,7 @@ func SetOOMScore(pid, score int) error {
4244
}
4345
defer f.Close()
4446
if _, err = f.WriteString(strconv.Itoa(score)); err != nil {
45-
if os.IsPermission(err) && (RunningInUserNS() || RunningUnprivileged()) {
47+
if os.IsPermission(err) && (userns.RunningInUserNS() || RunningUnprivileged()) {
4648
return nil
4749
}
4850
return err

sys/userns_deprecated.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package sys
18+
19+
import "github.com/containerd/containerd/pkg/userns"
20+
21+
// RunningInUserNS detects whether we are currently running in a user namespace.
22+
// Deprecated: use github.com/containerd/containerd/pkg/userns.RunningInUserNS instead.
23+
var RunningInUserNS = userns.RunningInUserNS

0 commit comments

Comments
 (0)
X Tutup