Skip to content

Commit 9e0353b

Browse files
authored
Merge pull request kubernetes#122016 from carlory/ref-pr-80043
removed the dependency on `k8s.io/util/nsenter`
2 parents 6a65718 + 977c4e9 commit 9e0353b

File tree

10 files changed

+8
-392
lines changed

10 files changed

+8
-392
lines changed

pkg/volume/util/hostutil/hostutil_linux.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (hu *HostUtil) PathIsDevice(pathname string) (bool, error) {
6666
return isDevice, err
6767
}
6868

69-
// ExclusiveOpenFailsOnDevice is shared with NsEnterMounter
69+
// ExclusiveOpenFailsOnDevice checks if block device in use by calling Open with O_EXCL flag.
7070
func ExclusiveOpenFailsOnDevice(pathname string) (bool, error) {
7171
var isDevice bool
7272
finfo, err := os.Stat(pathname)
@@ -154,8 +154,6 @@ func (hu *HostUtil) PathExists(pathname string) (bool, error) {
154154
}
155155

156156
// EvalHostSymlinks returns the path name after evaluating symlinks.
157-
// TODO once the nsenter implementation is removed, this method can be removed
158-
// from the interface and filepath.EvalSymlinks used directly
159157
func (hu *HostUtil) EvalHostSymlinks(pathname string) (string, error) {
160158
return filepath.EvalSymlinks(pathname)
161159
}
@@ -280,8 +278,8 @@ func (hu *HostUtil) GetMode(pathname string) (os.FileMode, error) {
280278
return GetModeLinux(pathname)
281279
}
282280

283-
// GetOwnerLinux is shared between Linux and NsEnterMounter
284-
// pathname must already be evaluated for symlinks
281+
// pathname must already be evaluated for symlinks.
282+
// GetOwnerLinux returns the integer ID for the user and group of the given path.
285283
func GetOwnerLinux(pathname string) (int64, int64, error) {
286284
info, err := os.Stat(pathname)
287285
if err != nil {
@@ -291,7 +289,7 @@ func GetOwnerLinux(pathname string) (int64, int64, error) {
291289
return int64(stat.Uid), int64(stat.Gid), nil
292290
}
293291

294-
// GetModeLinux is shared between Linux and NsEnterMounter
292+
// GetModeLinux returns permissions of the pathname.
295293
func GetModeLinux(pathname string) (os.FileMode, error) {
296294
info, err := os.Stat(pathname)
297295
if err != nil {

pkg/volume/util/subpath/subpath_linux.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (sp *subpath) PrepareSafeSubpath(subPath Subpath) (newHostPath string, clea
7878
return newHostPath, cleanupAction, err
7979
}
8080

81-
// This implementation is shared between Linux and NsEnter
81+
// safeOpenSubPath opens subpath and returns its fd.
8282
func safeOpenSubPath(mounter mount.Interface, subpath Subpath) (int, error) {
8383
if !mount.PathWithinBase(subpath.Path, subpath.VolumePath) {
8484
return -1, fmt.Errorf("subpath %q not within volume path %q", subpath.Path, subpath.VolumePath)
@@ -92,11 +92,6 @@ func safeOpenSubPath(mounter mount.Interface, subpath Subpath) (int, error) {
9292

9393
// prepareSubpathTarget creates target for bind-mount of subpath. It returns
9494
// "true" when the target already exists and something is mounted there.
95-
// Given Subpath must have all paths with already resolved symlinks and with
96-
// paths relevant to kubelet (when it runs in a container).
97-
// This function is called also by NsEnterMounter. It works because
98-
// /var/lib/kubelet is mounted from the host into the container with Kubelet as
99-
// /var/lib/kubelet too.
10095
func prepareSubpathTarget(mounter mount.Interface, subpath Subpath) (bool, string, error) {
10196
// Early check for already bind-mounted subpath.
10297
bindPathTarget := getSubpathBindTarget(subpath)
@@ -237,7 +232,7 @@ func doBindSubPath(mounter mount.Interface, subpath Subpath) (hostPath string, e
237232
return bindPathTarget, nil
238233
}
239234

240-
// This implementation is shared between Linux and NsEnter
235+
// doCleanSubPaths tears down the subpath bind mounts for a pod
241236
func doCleanSubPaths(mounter mount.Interface, podDir string, volumeName string) error {
242237
// scan /var/lib/kubelet/pods/<uid>/volume-subpaths/<volume>/*
243238
subPathDir := filepath.Join(podDir, containerSubPathDirectoryName, volumeName)
@@ -372,9 +367,7 @@ func removeEmptyDirs(baseDir, endDir string) error {
372367
return nil
373368
}
374369

375-
// This implementation is shared between Linux and NsEnterMounter. Both pathname
376-
// and base must be either already resolved symlinks or thet will be resolved in
377-
// kubelet's mount namespace (in case it runs containerized).
370+
// doSafeMakeDir creates a directory at pathname, but only if it is within base.
378371
func doSafeMakeDir(pathname string, base string, perm os.FileMode) error {
379372
klog.V(4).Infof("Creating directory %q within base %q", pathname, base)
380373

@@ -523,7 +516,6 @@ func findExistingPrefix(base, pathname string) (string, []string, error) {
523516
return pathname, []string{}, nil
524517
}
525518

526-
// This implementation is shared between Linux and NsEnterMounter
527519
// Open path and return its fd.
528520
// Symlinks are disallowed (pathname must already resolve symlinks),
529521
// and the path must be within the base directory.

pkg/volume/util/subpath/subpath_unsupported.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"os"
2525

2626
"k8s.io/mount-utils"
27-
"k8s.io/utils/nsenter"
2827
)
2928

3029
type subpath struct{}
@@ -36,12 +35,6 @@ func New(mount.Interface) Interface {
3635
return &subpath{}
3736
}
3837

39-
// NewNSEnter is to satisfy the compiler for having NewSubpathNSEnter exist for all
40-
// OS choices. however, NSEnter is only valid on Linux
41-
func NewNSEnter(mounter mount.Interface, ne *nsenter.Nsenter, rootDir string) Interface {
42-
return nil
43-
}
44-
4538
func (sp *subpath) PrepareSafeSubpath(subPath Subpath) (newHostPath string, cleanupAction func(), err error) {
4639
return subPath.Path, nil, errUnsupported
4740
}

pkg/volume/util/subpath/subpath_windows.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929

3030
"k8s.io/klog/v2"
3131
"k8s.io/mount-utils"
32-
"k8s.io/utils/nsenter"
3332
)
3433

3534
// MaxPathLength is the maximum length of Windows path. Normally, it is 260, but if long path is enable,
@@ -43,12 +42,6 @@ func New(mount.Interface) Interface {
4342
return &subpath{}
4443
}
4544

46-
// NewNSEnter is to satisfy the compiler for having NewSubpathNSEnter exist for all
47-
// OS choices. however, NSEnter is only valid on Linux
48-
func NewNSEnter(mounter mount.Interface, ne *nsenter.Nsenter, rootDir string) Interface {
49-
return nil
50-
}
51-
5245
// isDriveLetterPath returns true if the given path is empty or it ends with ":" or ":\" or ":\\"
5346
func isDriveLetterorEmptyPath(path string) bool {
5447
if path == "" || strings.HasSuffix(path, ":\\\\") || strings.HasSuffix(path, ":") || strings.HasSuffix(path, ":\\") {

staging/src/k8s.io/mount-utils/mount_linux.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ func (mounter *SafeFormatAndMount) GetDiskFormat(disk string) (string, error) {
722722
return getDiskFormat(mounter.Exec, disk)
723723
}
724724

725-
// ListProcMounts is shared with NsEnterMounter
725+
// ListProcMounts returns a list of all mounted filesystems.
726726
func ListProcMounts(mountFilePath string) ([]MountPoint, error) {
727727
content, err := readMountInfo(mountFilePath)
728728
if err != nil {
@@ -776,7 +776,6 @@ func parseProcMounts(content []byte) ([]MountPoint, error) {
776776
// Some filesystems may share a source name, e.g. tmpfs. And for bind mounting,
777777
// it's possible to mount a non-root path of a filesystem, so we need to use
778778
// root path and major:minor to represent mount source uniquely.
779-
// This implementation is shared between Linux and NsEnterMounter
780779
func SearchMountPoints(hostSource, mountInfoPath string) ([]string, error) {
781780
mis, err := ParseMountInfo(mountInfoPath)
782781
if err != nil {

vendor/k8s.io/utils/nsenter/OWNERS

Lines changed: 0 additions & 10 deletions
This file was deleted.

vendor/k8s.io/utils/nsenter/README.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)