-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
Log out from multiple target portals when using iscsi storage plugin #46239
Conversation
Hi @mtanino. 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 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. |
/assign @rootfs |
@k8s-bot ok to test |
pkg/volume/iscsi/iscsi_util.go
Outdated
portals = append(portals, tp) | ||
} | ||
} | ||
return portals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My go fu is not great but this looks like it will return an array with empty elements at the end in case it removes some duplicates which would mean the kubelet tries to execute iscsiadm commands on empty data.
This go playground example avoids it, maybe can use that
https://play.golang.org/p/q3bZ3hpOzD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comment. Your suggestion looks good.
My go is not great too, so I'm curious what kind of input causes empty elements return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad
I expected the len of the new array to be 3 and the last element empty in the case
of having a list of three portals with on set of duplicates
pkg/volume/iscsi/iscsi_util.go
Outdated
return portals | ||
} | ||
|
||
// If all mntPaths indicate global mounts, then return ture. Otherwise return false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: ture = true
pkg/volume/iscsi/iscsi_util.go
Outdated
return false | ||
} | ||
} | ||
return flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can just return true here as flag isn't used anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. Thanks.
pkg/volume/iscsi/iscsi_util.go
Outdated
glog.Errorf("iscsi: failed to delete node record Error: %s", string(out)) | ||
} | ||
} else { | ||
glog.Infof("iscsi: log out target %s iqn %s", portal, iqn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rootfs how long backwards compatibility is promised.
Can this code be removed after X versions of k8s.
If so would be good to add a todo for when it should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a todo is good for note taking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Will do.
pkg/volume/iscsi/iscsi_util.go
Outdated
|
||
for _, mntPath := range mntPaths { | ||
// if device is no longer used, see if need to logout the target | ||
if cnt == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite following the logic here
If there is two mntpaths where the first one has a cnt of 0 and the first one the second one a count of 2.
Won't we skip logging out the first one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. This logic should be changed like following.
In case of multipath with two portals, mntpaths has two global mount paths like;
/var/lib/kubelet/plugins/kubernetes.io/iscsi/iface-default/x.x.x.10:3260-iqn.aaa
/var/lib/kubelet/plugins/kubernetes.io/iscsi/iface-default/x.x.x.20:3260-iqn.bbb
Then, we should;
(1) Unmount all mntPaths
(2) Count num(cnt) of remained devices with GetDeviceNameFromMount
(3) If cnt == 0,then logout from these two iSCSI sessions
Any concerns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we need to wait to log out one device until the other one has cnt == 0
If we don't have to wait and just log out any device with cnt == 0 then we can combine the loops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cnt shows that the number of remained devices
If we have two remaining paths like this, then GetDeviceNameFromMount returns '2'.
/var/lib/kubelet/plugins/kubernetes.io/iscsi/iface-default/x.x.x.10:3260-iqn.aaa
/var/lib/kubelet/plugins/kubernetes.io/iscsi/iface-default/x.x.x.20:3260-iqn.bbb
In this case, I think we should unmount these paths at first. Then if these unmount is succeeded and cnt == 0, it means no one is using iSCSI connection so we can logout each iSCSI connections step by step. so I'm using divided for two loop for these steps.
But can we combine these steps into single for loop? Please let me know if you have good idea.
Thanks,
pkg/volume/iscsi/iscsi_util.go
Outdated
// This portal/iqn/iface is no longer referenced, log out. | ||
// Extract the portal and iqn from device path. | ||
portal, iqn, err := extractPortalAndIqn(device) | ||
if err = c.mounter.Unmount(mntPath); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By doing Unmount first and GetDeviceNameFromMount second can't the cnt, cnt-- be skipped
and only use cnt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
@k8s-bot ok to test |
@rootfs |
@k8s-bot pull-kubernetes-cross test this |
pkg/volume/iscsi/iscsi_util.go
Outdated
if len(bkpPortal) == 1 { | ||
globalPDPath = b.manager.MakeGlobalPDName(*b.iscsiDisk, "") | ||
} else { | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove it.
pkg/volume/iscsi/iscsi_util.go
Outdated
@@ -167,7 +171,11 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskMounter) error { | |||
|
|||
iscsiTransport = extractTransportname(string(out)) | |||
|
|||
bkpPortal := b.portals | |||
bkpPortal := removeDuplicate(b.portals) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need removeDuplicate
in attachdisk, can you please give some details on why we need this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I thought if user passes duplicate portal IPs like this, iscsiadm will be called multiple times unnecessarily, but it was my misunderstanding.
iscsi:
targetPortal: 192.168.122.85:3260
portals: ['192.168.122.85:3260', '192.168.122.7:3260']
iqn: iqn.2017-05.com.example:rhel7
Actually waitForPathToExist() checks existing path so even if user specify duplicate portal IPs in the config, duplicate IPs will be skipped.
I'll remove removeDuplicate() logic from attachdisk()
Thanks,
pkg/volume/iscsi/iscsi_util.go
Outdated
@@ -167,7 +171,11 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskMounter) error { | |||
|
|||
iscsiTransport = extractTransportname(string(out)) | |||
|
|||
bkpPortal := b.portals | |||
bkpPortal := removeDuplicate(b.portals) | |||
if len(bkpPortal) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its perfectly valid that portal
can be empty. I may be missing the logic here, can you please fill me in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same above.
pkg/volume/iscsi/disk_manager.go
Outdated
@@ -27,16 +27,16 @@ import ( | |||
|
|||
// Abstract interface to disk operations. | |||
type diskManager interface { | |||
MakeGlobalPDName(disk iscsiDisk) string | |||
MakeGlobalPDName(disk iscsiDisk, portal string) string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
portal
is a known member here in this code path as []string. May be you could use some other name to avoid confusion. Just a thought.
@mtanino Thanks for this PR ! I have few comments. Also it would be appreciated if you can explain some more on the |
@mtanino : The test failure looks to be valid as well.
|
@mtanino also the PR says, logout from multiple target portals when using iscsi plugin, however it change the code in attachdisk()..etc, where my expectation was that, the change would be more or less in detachdisk(). It could be better if you can split this PR into different commits and organize the changes. It will make the review process bit easier. At time of merging we could squash it . |
In my understanding,
Is this correct? In my approach, In order to logout from multiple iSCSI sessions, we need following two fix in this PR.
As a result, if user specify multiple portals like this,
we can see mount points like this.
Then we can properly logout using these two iSCSI connection information. Any thought? Thanks, |
@humblec |
@mtanino thanks for giving more details about the approach! iirc, when there are entries in
@rootfs Any thoughts? |
@mtanino if going down the route of saving a json file wont that become an issue in the scenario where the umount goes through but something happens with the iscsi logout. |
@tobad357 the json file lives on the host, so it will survive an unmount and iscsi logout. |
pkg/volume/iscsi/iscsi_util.go
Outdated
file := path.Join(mnt, "iscsi.json") | ||
fp, err := os.Create(file) | ||
if err != nil { | ||
return fmt.Errorf("iscsi: create err %s/%s", file, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iscsi: create %s err %s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/volume/iscsi/iscsi_util.go
Outdated
file := path.Join(mnt, "iscsi.json") | ||
fp, err := os.Open(file) | ||
if err != nil { | ||
return fmt.Errorf("iscsi: open err %s/%s", file, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/approve |
return nil | ||
} | ||
|
||
func (util *ISCSIUtil) loadISCSI(conf *iscsiDisk, mnt string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: make a note here, the iscsi config json is not deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
When using iscsi storage with multiple target portal (TP) addresses and multipathing the volume manager logs on to the IQN for all portal addresses, but when a pod gets destroyed the volume manager only logs out for the primary TP and sessions for another TPs are always remained. This patch adds methods to store and load iscsi disk configrations, then uses the stored config at DetachDisk path. Fix kubernetes#45394
@mtanino: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. |
/lgtm |
@k8s-bot pull-kubernetes-e2e-gce-etcd3 test this |
@k8s-bot pull-kubernetes-node-e2e test this |
/lgtm. Thanks !! |
After merged the fix, can we cherry pick the PR to v1.6.x tree? |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: childsb, mtanino, rootfs The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
@mtanino I agree this is very important to us as well |
Automatic merge from submit-queue |
Automatic merge from submit-queue (batch tested with PRs 46112, 46764, 46727, 46974, 46968) iscsi storage plugin: bkpPortal should be initialized beforehand **What this PR does / why we need it**: This patch is a follow up patch for the PR #46239. The bkpPortal in DetachDisk() path should be initialized before using it. **Special notes for your reviewer**: /cc @rootfs @childsb **Release note**: ``` NONE ```
…9-upstream-release-1.6 Automatic merge from submit-queue Automated cherry pick of #46239 Cherry pick of #46239 on release-1.6. #46239: Log out from multiple portals with iscsi storage plugin This Cherry pick also includes fix #46968(follow-up fix for #46239) #46968: iscsi storage plugin: bkpPortal should be initialized beforehand
What this PR does / why we need it:
When using iscsi storage with multiple target portal (TP) addresses
and multipathing the volume manager logs on to the IQN for all
portal addresses, but when a pod gets destroyed the volume manager
only logs out for the primary TP and sessions for another TPs are
always remained.
This patch adds mount points for all TPs, and then log out from all
TPs when a pod is destroyed. If a TP is referred from another pods,
the connection will be remained as usual.
Which issue this PR fixes
fixes #45394
Special notes for your reviewer:
Release note: