Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed mounting with containerized kubelet #23435

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/util/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Interface interface {
// consistent.
List() ([]MountPoint, error)
// IsLikelyNotMountPoint determines if a directory is a mountpoint.
// It should return ErrNotExist when the directory does not exist.
IsLikelyNotMountPoint(file string) (bool, error)
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/util/mount/nsenter_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ func (n *NsenterMounter) IsLikelyNotMountPoint(file string) (bool, error) {
return true, err
}

// Check the directory exists
if _, err = os.Stat(file); os.IsNotExist(err) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to run in the container's mount namespace -- don't we need to do this check in the host's mount ns?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kubernetes runs with /var/lib/kubernetes mounted to the same directory in the container so it works.

If you look e.g. into AWS volume plugin, it just calls mkdir() there without any nsenter. https://github.com/kubernetes/kubernetes/blob/master/pkg/volume/aws_ebs/aws_util.go#L75

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it /var/lib/kubelet?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's imagine we have a directory /var/lib/kubelet/test which is a mount point which contains directory foo. Now, I think that if we call IsLikelyNotMountPoint for it var/lib/kubelet/test/foo we'd get false for newer versions of findmnt (see comment in line 186). If that's the case (I haven't tested this) your change would introduce a semantic change as now we'd return true.

I'm not saying it's a bad change, but we should say it explicitly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's /var/lib/kubelet, sorry.

@fgrzadkowski, I don't understand your point. If var/lib/kubelet/test/foo exist, this patch does not change a thing. Only if it doesn't we return ErrNotExist to tell the caller to create the directory before mounting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. The change only affects the situation when the directory does not exist. I just want to make sure we are clear about semantics.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fgrzadkowski Personally I think this change is correct, and that the semantics are clear. Prior to this patch it is ambiguous how the dir-doesn't-exist case is handled; this makes nsenter_mount.go consistent with mount.go and documents the semantics.

glog.V(5).Infof("findmnt: directory %s does not exist", file)
return true, err
}

args := []string{"--mount=/rootfs/proc/1/ns/mnt", "--", n.absHostPath("findmnt"), "-o", "target", "--noheadings", "--target", file}
glog.V(5).Infof("findmnt command: %v %v", nsenterPath, args)

Expand Down