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

Attacher/Detacher refactor for local storage #66884

Merged

Conversation

NickrenREN
Copy link
Contributor

Proposal link: kubernetes/community#2438

What this PR does / why we need it:

Attacher/Detacher refactor for the plugins which just need to mount device, but do not need to attach, such as local storage plugin.

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:

Attacher/Detacher refactor for local storage

/sig storage
/kind feature

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/storage Categorizes an issue or PR as relevant to SIG Storage. kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 2, 2018
@NickrenREN
Copy link
Contributor Author

/retest

/assign @msau42 @jsafrane @saad-ali

@@ -294,6 +294,10 @@ func (plugin *TestPlugin) NewAttacher() (volume.Attacher, error) {
return &attacher, nil
}

func (plugin *TestPlugin) NewDeviceMounter() (volume.DeviceMounter, error) {
return plugin.NewAttacher()
Copy link
Member

Choose a reason for hiding this comment

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

Hm, I wonder if this would cause any issues for attachable plugins if they had been keeping some state in the Attacher object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The refactor move MountDevice() and GetDeviceMountPath() from Attacher to DeviceMounter.
The difference is:
Before this change: we will create an Attacher and let it call WaitForAttach, GetDeviceMountPath() and MountDevice()
After this change: we will create an Attacher and a DeviceMounter, let Attacher call WaitForAttach , let DeviceMounter call GetDeviceMountPath() and MountDevice().

Here, It seems that GetDeviceMountPath() and MountDevice() will not change the state kept in Attacher object(which is attachedVolumeMap), and also the ErrorEncountered will not affect the logic, since we will return directly if error occurs

BTW: for now, we will create a new Attacher in both GenerateMountVolumeFunc and GenerateAttachVolumeFunc which are called by different components. It seems that we should avoid keeping state in Attacher object.

please correct me if i am wrong.

Copy link
Member

Choose a reason for hiding this comment

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

I'm worried about situations where a plugin may have kept some state to serialize between WaitForAttach and MountDevice, like a lock or some cached data.

Copy link
Contributor Author

@NickrenREN NickrenREN Aug 11, 2018

Choose a reason for hiding this comment

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

Got it, for now, i can not find the state kept between WaitForAttach and MountDevice through the plugins.
But should we cache the attacher info for the situations you are worried about ? e.g. if the attacher is created before, we do not need to create a new one in NewDeviceMounter...

/cc @jsafrane @saad-ali

Copy link
Member

Choose a reason for hiding this comment

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

I went through volume plugins, none of them really passes information from WaitForAttach to MountDevice via the attacher instance.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks guys for searching! This sounds fine to me then.

@jsafrane
Copy link
Member

I quickly went through the PR and I like it.
/approve
(this does not mean lgtm, I need more time or someone else may lgtm it)


// DeviceMounter can mount a block volume to a global path.
Copy link
Member

Choose a reason for hiding this comment

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

Can we drop block volume word from here? it seems iffy - there are block volumes which don't necessarily use DeviceMounter and there could be non-block volumes that use the interface?

Copy link
Contributor Author

@NickrenREN NickrenREN Aug 14, 2018

Choose a reason for hiding this comment

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

there are block volumes which don't necessarily use DeviceMounter

which is true, for block mode.

there could be non-block volumes that use the interface

Actually, for now, local storage is the only use case that we only implement DeviceMounter( not implement Attacher interface).
We will only mount block device to a global path. If the local storage is a fs dir, we will do nothing, just set global path to its Path in pv spec.

@gnufied
Copy link
Member

gnufied commented Aug 13, 2018

minor nit but otherwise lgtm!

@@ -294,6 +294,10 @@ func (plugin *TestPlugin) NewAttacher() (volume.Attacher, error) {
return &attacher, nil
}

func (plugin *TestPlugin) NewDeviceMounter() (volume.DeviceMounter, error) {
return plugin.NewAttacher()
Copy link
Member

Choose a reason for hiding this comment

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

Thanks guys for searching! This sounds fine to me then.

@@ -725,13 +734,31 @@ func (og *operationGenerator) GenerateUnmountDeviceFunc(
return volumetypes.GeneratedOperations{}, deviceToDetach.GenerateErrorDetailed("UnmountDevice.FindAttachablePluginBySpec failed", err)
}

volumeDetacher, err := attachableVolumePlugin.NewDetacher()
// Get DeviceMounter plugin
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need to get attachable plugin above?

Copy link
Member

Choose a reason for hiding this comment

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

Also, how does the caller of this detect if the plugin is device mountable?

Copy link
Contributor Author

@NickrenREN NickrenREN Aug 14, 2018

Choose a reason for hiding this comment

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

Do we still need to get attachable plugin above?

we don't need it now, thanks, i will remove it

Also, how does the caller of this detect if the plugin is device mountable?

The UnmountDevice func is only called when the volume mode is Filesystem and we find the attachedVolume is globally mounted , which is set true in MarkDeviceAsMounted. Which means the plugin is device mountable.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, just want to make sure that this attachedVolume doesn't actually require AttachablePlugin?

Copy link
Contributor Author

@NickrenREN NickrenREN Aug 14, 2018

Choose a reason for hiding this comment

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

I think so.
If the volume does not implement the attacher interface, it is assumed to be attached and the actual state of the world is updated accordingly.
see: https://github.com/kubernetes/kubernetes/blob/master/pkg/volume/util/operationexecutor/operation_executor.go#L133

@@ -478,35 +478,45 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
volumeAttacher, _ = attachableVolumePlugin.NewAttacher()
}

// get deviceMounter, if possible
deviceMountableVolumePlugin, _ := og.volumePluginMgr.FindDeviceMountablePluginBySpec(volumeToMount.VolumeSpec)
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 plugin scenarios?

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 am not sure i understand the scenarios. Just added some UTs for Concurrent Mount operations for devicemountable plugins in the third commit. PTAL, thanks

Copy link
Member

Choose a reason for hiding this comment

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

I mean adding test cases for DeviceMountable-only plugins for Mount and Unmount To ensure that we have correctly decoupled the attacher

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We haven't implemented any DeviceMountable-only plugins for now, this PR is just interface refactor. We can add these UTs in my another PR: #63011
WDYT ?

@NickrenREN
Copy link
Contributor Author

/retest

@NickrenREN
Copy link
Contributor Author

Errors seem not related to this change

/retest

@msau42
Copy link
Member

msau42 commented Aug 14, 2018

/lgtm

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

@saad-ali saad-ali left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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 Aug 14, 2018
@msau42
Copy link
Member

msau42 commented Aug 14, 2018

/retest

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. 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/storage Categorizes an issue or PR as relevant to SIG Storage. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants