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

Support both directory and block device for local volume plugin FileSystem VolumeMode #63011

Merged
merged 6 commits into from Sep 4, 2018

Conversation

NickrenREN
Copy link
Contributor

@NickrenREN NickrenREN commented Apr 23, 2018

Support both directory and block device for local volume plugin FileSystem VolumeMode

xref: local storage dynamic provisioning design #1914

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

Release note:

Support both directory and block device for local volume plugin FileSystem VolumeMode 

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 23, 2018
@k8s-github-robot k8s-github-robot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Apr 23, 2018
@msau42
Copy link
Member

msau42 commented Apr 23, 2018

/assign

// Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs". Implicitly inferred to be "ext4" if unspecified.
// +optional
FSType string
Copy link
Contributor

Choose a reason for hiding this comment

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

should be a pointer, as the field is optional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do we need to use pointer for optional field ? I notice that other persistent volume sources are just using string except AzureDiskVolumeSource , see https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/core/types.go#L578
https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/core/types.go#L960
...

Copy link
Member

Choose a reason for hiding this comment

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

New optional fields to existing types need to be pointers for backwards compatibility. See #50121

Copy link
Member

Choose a reason for hiding this comment

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

I think there also needs to be defaulting logic in v1/defaults.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good to know, thanks

Copy link
Member

Choose a reason for hiding this comment

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

ah sorry, I think we may not be able to default the field, because it would not work on windows.

return devicePath, "", err
}

if string(fileType) == string(mount.FileTypeDirectory) {
Copy link
Member

Choose a reason for hiding this comment

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

this could be a switch statement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks

}
if string(fileType) == string(mount.FileTypeDirectory) {
return spec.PersistentVolume.Spec.Local.Path, nil
} else if string(fileType) == string(mount.FileTypeBlockDev) {
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 only called when path is a block device. Do we need these checks again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is called in MountDevice() and before UnmountDevice(), here, i add FileTypeDirectory check in order to set deviceMountPath to local volume source path if the local PV is fs dir, so, if we want to remove this check, we need to set deviceMountPath to "" if local PV is fs dir ?

var _ volume.DeviceUmounter = &deviceMounter{}

func (dm *deviceMounter) UnmountDevice(deviceMountPath string) error {
basemountPath := filepath.Join(dm.plugin.host.GetPluginDir(localVolumePluginName), mount.MountsInGlobalPDPath)
Copy link
Member

Choose a reason for hiding this comment

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

Can you just do a Dir() on the deviceMountPath?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here is not try to get deviceMountPath dir, we want to get the expected base mount Dir, and then compare with deviceMountPath to see if we need to unmount device.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we want to remove fs dir check in GetDeviceMountPath as we pointed out above, we need to add deviceMountPath != ""/ len(...) == 0 check

Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment here explaining the deviceMountPath formats that can be passed into here? That will help better understand why we can't just call Dir().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, done

}, nil
}

func (dm *deviceMounter) MountDevice(spec *volume.Spec, devicePath string, _ *v1.Pod) (string, string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add unit tests for these new functions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

// Must be a filesystem type supported by the host operating system.
// Ex. "ext4", "xfs", "ntfs". Implicitly inferred to be "ext4" if unspecified.
// +optional
FSType string
Copy link
Member

Choose a reason for hiding this comment

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

I think there also needs to be defaulting logic in v1/defaults.go

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 27, 2018

switch fileType {
case mount.FileTypeBlockDev:
return dm.mountLocalBlockDevice(spec, devicePath)
Copy link
Member

Choose a reason for hiding this comment

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

Does SetUp also have to change, to bind mount from this global path instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. i think so

return dm.mountLocalBlockDevice(spec, devicePath)
case mount.FileTypeDirectory:
// if the given local volume path is of already filesystem directory, return directly
return spec.PersistentVolume.Spec.Local.Path, spec.PersistentVolume.Spec.Local.Path, nil
Copy link
Member

Choose a reason for hiding this comment

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

I wonder, can we return nil path for this case? Could UnmountDevice be simplified if it is only called for blockdev scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think they are the same. deviceMountPath is set to local pv path If it is filesystem dir. and UnmountPath will not be executed for this case.

@@ -1442,6 +1442,12 @@ type LocalVolumeSource struct {
// Block devices can be represented only by VolumeMode=Block, which also requires the
Copy link
Member

Choose a reason for hiding this comment

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

This comment also needs to be updated because now you can specify a block device with VolumeMode=Filesystem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted the last three lines

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Sep 3, 2018
@NickrenREN
Copy link
Contributor Author

/retest

@andyzhangx
Copy link
Member

@PatrickLang raw block device is not supported on Windows k8s now. Will windows 2019 supports raw block device for windows container? If so, I could enable it in k8s level.
Anyway, this PR deals with linux implementation, I am ok with that.

@andyzhangx
Copy link
Member

/test pull-kubernetes-cross

@thockin
Copy link
Member

thockin commented Sep 4, 2018

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 4, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jsafrane, msau42, NickrenREN, thockin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 4, 2018
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 63011, 68089, 67944, 68132). If you want to cherry-pick this change to another branch, please follow the instructions here: https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md.

@k8s-github-robot k8s-github-robot merged commit 9c86087 into kubernetes:master Sep 4, 2018
@NickrenREN NickrenREN deleted the local-plugin-change branch September 5, 2018 01:36
msau42 added a commit to msau42/kubernetes that referenced this pull request Sep 6, 2018
@msau42
Copy link
Member

msau42 commented Sep 6, 2018

@NickrenREN can you also investigate if the functionality of local volumes (bind mount/read/write/fsgroup) would have worked before this change if the volume was created with permissions that kubelet did not have?

We need to figure out if this has the potential to be a regression, and if so, we need an appropriate release note with "ACTION REQUIRED"

@msau42
Copy link
Member

msau42 commented Sep 8, 2018

We discussed, this is only an issue with /tmp directories, which is only a testing issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. sig/windows Categorizes an issue or PR as relevant to SIG Windows. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants