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

Fix for Premature iSCSI logout #39202. #41196

Merged
merged 3 commits into from
Feb 15, 2017

Conversation

cristianpop
Copy link

What this PR does / why we need it:

Modifies the iSCSI volume plugin code to prevent premature iSCSI logouts and the establishment of multiple iSCSI connections to the same target in certain cases.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #39202, fixes #41041, fixes #40941

Special notes for your reviewer:

The existing iSCSI connections are now rescanned on every AttachDisk call to discover newly created LUNs.

The disk mount points now contain an additional directory in the path corresponding to the disk iface that is later used for iSCSI logout.

The device prefixes that are used to count the existing references to the portal-target pair now contain the whole path including the mount point until the lun index.

Release note:

Fixed issues #39202, #41041 and #40941 that caused the iSCSI connections to be prematurely closed when deleting a pod with an iSCSI persistent volume attached and that prevented the use of newly created LUNs on targets with preestablished connections.

@k8s-ci-robot
Copy link
Contributor

Hi @cristianpop. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with @k8s-bot ok to test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://github.com/kubernetes/kubernetes/wiki/CLA-FAQ to sign the CLA.

Once you've signed, please reply here (e.g. "I signed it!") and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Feb 9, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Feb 9, 2017
@rootfs
Copy link
Contributor

rootfs commented Feb 9, 2017

/approve

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 9, 2017
@rootfs
Copy link
Contributor

rootfs commented Feb 9, 2017

@k8s-bot ok to test

@rootfs
Copy link
Contributor

rootfs commented Feb 9, 2017

@cristianpop have you signed CLA yet?

@rootfs
Copy link
Contributor

rootfs commented Feb 9, 2017

@cdragga

return path.Join(host.GetPluginDir(iscsiPluginName), portal+"-"+iqn+"-lun-"+lun)
// make a directory like /var/lib/kubelet/plugins/kubernetes.io/iscsi/iface_name/portal-some_iqn-lun-lun_id
func makePDNameInternal(host volume.VolumeHost, portal string, iqn string, lun string, iface string) string {
return path.Join(host.GetPluginDir(iscsiPluginName), iface, portal+"-"+iqn+"-lun-"+lun)
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be a problem for kubelet upgrade

Copy link
Author

Choose a reason for hiding this comment

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

I thought it may be problematic but I needed to somehow obtain the iSCSI iface in DettachDisk to logout only on the given iface in case there are multiple connections to the same target using different ifaces. The use of multiple connections on different ifaces might not be common, but that's the setup I have. The servers are booted using iSCSI and if the persistent volumes end up on the same target as the boot image, the disk dettaches would end up closing the iSCSI connection that imported the boot image as well.

Copy link
Member

Choose a reason for hiding this comment

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

I understand you need to make the code more robust, but it should work out of the box when updated from older Kubernetes release without killing pods. So you should "adopt" iSCSI LUNs mounted to the old directory too and unmount+"logoff" them when the pods are deleted.

Looking at the code, it seems it could work, however I'd like someone to confirm this.

Copy link
Author

Choose a reason for hiding this comment

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

I think it would work but it would not log out of any interface, supposing the directory name is not a legit iSCSI interface.

Copy link
Author

Choose a reason for hiding this comment

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

I could use the plugin directory to determine whether the path is an old one or not and return the "default" interface or an empty string in extractIface and act accordingly, either log out on the default iface or do not log out at all to avoid logging out of sessions that may be used by other pods.

@@ -185,14 +192,20 @@ func (util *ISCSIUtil) DetachDisk(c iscsiDiskUnmounter, mntPath string) error {
refCount, err := getDevicePrefixRefCount(c.mounter, prefix)
Copy link
Contributor

Choose a reason for hiding this comment

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

also see this #41041 (comment)

Copy link
Author

Choose a reason for hiding this comment

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

I thought about changing the HasPrefix call to Contains but I wanted to account for the iface as well and log out only if there are no other pods that use that specific iface. I know it's not foul proof especially when there are multiple ifaces using the same transport to the same target as the devices that get mounted are not necessarily the ones that were imported on the given iface, but I could not find a better solution until now.

Copy link

Choose a reason for hiding this comment

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

This seems like a solid solution to me, at least for the moment. In the long-term, I'm concerned about cases where sessions that exist independently of Kubernetes get logged off because a pod used a volume connected to the target using the same interface (I think this is the same concern @cristianpop cited just now, but I'm not totally sure). Solving that might be doable with something like resolving all of the symlinks in /dev/disk/by-path to their devices and then checking whether any of the devices that belong to the session are still mounted; I don't know if this would behave well with multipathing, though.

At any rate, this is a better fix than just changing HasPrefix to Contains.

@cristianpop
Copy link
Author

@cristianpop have you signed CLA yet?

I haven't signed the CLA yet, but I'm working on it (the company I'm working for has to sign it).

@eparis
Copy link
Contributor

eparis commented Feb 10, 2017

@k8s-bot gci gce e2e test this

@cristianpop do you know when you will be able to get the CLA signed? I know that it can be difficult with many companies.

Are you willing to say that the contribution was created in whole by you and that you have the right to submit it under the Apache License Version 2.0? Do you also understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information you submited with it) is maintained indefinitely and may be redistributed consistent with this project or the license involved?

@cristianpop
Copy link
Author

@eparis I'm sorry for the delay. The management is handling it and I've been told it will be signed today or tomorrow at the latest.

Yes, the contribution is mine, I have the right to submit it and I understand the contribution is public.

@rootfs
Copy link
Contributor

rootfs commented Feb 14, 2017

@cristianpop can you rebase it?

@saad-ali PTAL

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 14, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 14, 2017
@cristianpop
Copy link
Author

@rootfs I've rebased it.

@cristianpop
Copy link
Author

The CLA has been signed. Sorry for the delay.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Feb 14, 2017
@rootfs
Copy link
Contributor

rootfs commented Feb 14, 2017

@k8s-bot gci gce e2e test this

@rootfs
Copy link
Contributor

rootfs commented Feb 14, 2017

LGTM

return device, prefix, nil
}

func extractIface(mntPath string) (string, error) {
ind := strings.LastIndex(mntPath, "/")
Copy link
Member

Choose a reason for hiding this comment

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

use path.Dir()?

Copy link
Author

Choose a reason for hiding this comment

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

I wanted to keep it consistent with the existing code but I can change it.

Copy link
Author

Choose a reason for hiding this comment

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

If I use path.Base and path.Dir to extract the interface, I would lose the malformed mount path checks. I could keep the checks as they are and use path.Base and path.Dir but it would not make any sense to not use the indexes, or I could rewrite them to use path.Match or check for empty strings and ".", or scrap the checks. I would prefer to keep the checks, although they may end up not failing ever. What do you prefer?

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 get the check work correctly as the first priority.

return "", fmt.Errorf("iscsi detach disk: malformatted mnt path: %s", mntPath)
}

iface := baseMntPath[(ind + 1):]
Copy link
Member

Choose a reason for hiding this comment

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

path.Dir()?

@rootfs
Copy link
Contributor

rootfs commented Feb 14, 2017

@cristianpop @jsafrane

here is my 2 cents dealing with backward compatiblity.

In makePDNameInternal, make the path look like iface-iface_name/portal/iqn/lun-0.

In extractIface, search pattern iface-, if not found, return not exist. And caller skips this error and not use -I during log out. Otherwise, use the iface for logout.

@cristianpop
Copy link
Author

@rootfs

Sounds good to me. Better than searching for the volume plugin directory in the path.

…t upgrade. The detachDisk behavior is now preserved for pods that were created before the kubelet upgrade.
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

The following people have approved this PR: CristianPop, rootfs

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@childsb childsb assigned rootfs and unassigned saad-ali Feb 14, 2017
@rootfs
Copy link
Contributor

rootfs commented Feb 14, 2017

@k8s-bot test this

@rootfs
Copy link
Contributor

rootfs commented Feb 14, 2017

/lgtm

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

@k8s-bot kops aws e2e test this

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit a50ea2f into kubernetes:master Feb 15, 2017
@adkerr
Copy link

adkerr commented Feb 16, 2017

Would it be possible to get this cherry-picked to 1.5?

@saad-ali
Copy link
Member

saad-ali commented Feb 25, 2017

CC @mwielgus 1.5 release branch manager for cherry pick approval

@saad-ali saad-ali added this to the v1.5 milestone Feb 25, 2017
@saad-ali
Copy link
Member

@cristianpop: Once this is approved for cherry pick, execute ./hack/cherry_pick_pull.sh upstream/release-1.5 41196 to cherry pick this to the 1.5 branch.

@innergy
Copy link

innergy commented Mar 14, 2017

@saad-ali Anything that needs to be done to start the cherry pick approval process?

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. 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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet