-
Notifications
You must be signed in to change notification settings - Fork 38.9k
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 UnmountDevice with deleted pod. #64882
Conversation
When a pod is deleted, kubelet can't read VolumeAttachment objects. It should cache all information in a json file.
Unit tests added. Previous unit tests were not exactly running, because of kubernetes/pkg/volume/csi/csi_attacher_test.go Lines 686 to 692 in a7a081b
I.e. the tests stopped after the first |
/assign @saad-ali @vladimirvivien |
/LGTM |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jsafrane, vladimirvivien 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 |
/retest Review the full test history for this PR. Silence the bot with an |
I'll pick it into 1.10 and 1.11 when it gets merged (tomorrow?) |
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 few questions, otherwise lgtm
@vladimirvivien can you please review this from the block device perspective.
/assign @vladimirvivien
CC @davidz627 who authored the DeviceMount code for CSI
@@ -269,6 +269,25 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo | |||
return err | |||
} | |||
|
|||
dataDir := filepath.Dir(deviceMountPath) |
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.
Won't this end up putting the file in the same dir that is mounted?
On the mount side, it saves the file in /blah/savefile.txt
and puts the mount in /blah/mount/
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.
No, that's why there is filepath.Dir
. It ends up in /var/lib/kubelet/plugins/kubernetes.io/csi/pv/pvc-938861e4756911e8/vol_data.json
and the volume is mounted into /var/lib/kubelet/plugins/kubernetes.io/csi/pv/pvc-938861e4756911e8/globalmount
.
|
||
data := map[string]string{ | ||
volDataKey.volHandle: csiSource.VolumeHandle, | ||
volDataKey.driverName: csiSource.Driver, |
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 mount side saves a lot more:
volDataKey.specVolID: spec.Name(),
volDataKey.volHandle: pvSource.VolumeHandle,
volDataKey.driverName: pvSource.Driver,
volDataKey.nodeName: node,
volDataKey.attachmentID: attachID,
Are we sure we don't need anything else from the spec?
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.
No, UnstageVolume needs just volume id (+ driver).
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.
@saad-ali the mount side saves more info because it's needed to reconstruct the VolumeAttachment ID in subsequent steps.
volDataKey.volHandle: csiSource.VolumeHandle, | ||
volDataKey.driverName: csiSource.Driver, | ||
} | ||
if err := saveVolumeData(dataDir, volDataFileName, data); 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.
@vladimirvivien: you recently moved saveVolumeData(...)
from SetupAt(...)
to NewMounter(...)
. Does something similar need to happen here?
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.
@saad-ali unfortunately, the way the Attacher API is written, no params is available during csi_plugin.go#NewAttacher/#NewDetacher
that would allow the volume info to be persisted at that point as is done wit NewMounter/Unmounter. So, the saving of the volume info has to happen during MountDevice
call.
} | ||
return 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.
If the MountDevice(...)
operation fails below, how is the save file cleaned up?
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.
If MounDevice
fails, then the whole directory is cleaned by removeMountDir
. But you raised valid point, there are other error paths (e.g. failed to load secrets) that lead to uncleaned json file. I'll fix it.
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.
Filled #65323 + PR
[MILESTONENOTIFIER] Milestone Pull Request Labels Incomplete @jsafrane @saad-ali @vladimirvivien Action required: This pull request requires label changes. If the required changes are not made within 3 days, the pull request will be moved out of the v1.11 milestone. kind: Must specify exactly one of |
/retest |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here. |
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.
Saad's dir clean up concerns should be addressed.
volDataKey.volHandle: csiSource.VolumeHandle, | ||
volDataKey.driverName: csiSource.Driver, | ||
} | ||
if err := saveVolumeData(dataDir, volDataFileName, data); 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.
@saad-ali unfortunately, the way the Attacher API is written, no params is available during csi_plugin.go#NewAttacher/#NewDetacher
that would allow the volume info to be persisted at that point as is done wit NewMounter/Unmounter. So, the saving of the volume info has to happen during MountDevice
call.
|
||
data := map[string]string{ | ||
volDataKey.volHandle: csiSource.VolumeHandle, | ||
volDataKey.driverName: csiSource.Driver, |
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.
@saad-ali the mount side saves more info because it's needed to reconstruct the VolumeAttachment ID in subsequent steps.
#65323-upstream-release-1.11 Automatic merge from submit-queue. Automated cherry pick of #64882: Fix UnmountDevice with deleted pod. #65323: Fix cleanup of volume metadata json file. Cherry pick of #64882 #65323 on release-1.11. #64882: Fix UnmountDevice with deleted pod. #65323: Fix cleanup of volume metadata json file. ```release-note Fixed cleanup of CSI metadata files. ```
#65323-upstream-release-1.10 Automatic merge from submit-queue. Automated cherry pick of #64882: Fix UnmountDevice with deleted pod. #65323: Fix cleanup of volume metadata json file. Cherry pick of #64882 #65323 on release-1.10. #64882: Fix UnmountDevice with deleted pod. #65323: Fix cleanup of volume metadata json file. ```release-note Fixed cleanup of CSI metadata files. ```
When a pod is deleted, kubelet can't read VolumeAttachment objects. It should cache all information in a json file.
Fixes #63827
Work in progress: missing (unit?) testsRelease note:
@saad-ali @vladimirvivien @sbezverk
/sig storage