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 cleanup of volume metadata json file. #65323

Merged
merged 1 commit into from
Jun 27, 2018

Conversation

jsafrane
Copy link
Member

@jsafrane jsafrane commented Jun 21, 2018

Create the json file with metadata as the last item, when everything else is ready, so we don't need to clean up the file in all error cases in this function.

Fixes #65322

Release note:

Fixed cleanup of CSI metadata files.

/assign @saad-ali @vladimirvivien

Create the json file with metadata as the last item, when everything
else is ready, so we don't need to clean up the file in all error cases
in this function.
@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jun 21, 2018
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jun 21, 2018
@k8s-ci-robot k8s-ci-robot requested review from jingxu97 and msau42 June 21, 2018 17:08
}
if err := saveVolumeData(dataDir, volDataFileName, data); err != nil {
glog.Error(log("failed to save volume info data: %v", err))
if err := os.RemoveAll(dataDir); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Do all the error returns above also need to RemoveAll(dataDir)? Maybe this cleanup should be in a defer function that only runs if err != nil ?

Copy link
Member Author

Choose a reason for hiding this comment

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

MkdirAll() is just a few lines above and there is no return in between. I'll move it even closer to NodeStageVolume with some comment.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 22, 2018
@jsafrane
Copy link
Member Author

Moved staging directory creating closer to NodeStageVolume call

@jsafrane
Copy link
Member Author

/hold

This PR makes is actually worse. UnmountDevice needs the json file even if the driver does not support UnstageVolume - UnmountDevice checks it by itself and it needs the driver name.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 22, 2018
@jsafrane
Copy link
Member Author

/hold cancel

Now the json file is created early and cleaned in defer.

@msau42, PTAL

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 22, 2018
// clean up metadata
glog.Errorf(log("attacher.MountDevice failed: %v", err))
if err := removeMountDir(c.plugin, deviceMountPath); err != nil {
glog.Error(log("attacher.MountDevice failed to remove mount dir after a NodeStageVolume() error [%s]: %v", deviceMountPath, err))
Copy link
Member

Choose a reason for hiding this comment

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

It may not always be a NodeStageVolume() call that errored

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the log message

defer func() {
if err != nil {
// clean up metadata
glog.Errorf(log("attacher.MountDevice failed: %v", err))
Copy link
Member

Choose a reason for hiding this comment

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

Also should all the early error returns set err first so that the correct error will be logged here? For example L311, 322, 331, 336, 345

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed 322, 331 336 and 345. I can't see anything wrong in 311.

Copy link
Member

Choose a reason for hiding this comment

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

My question regarding 311, 332, 337: is there a reason to log almost the same message first before returning the error, which will then be logged again in the defer?

Copy link
Member Author

Choose a reason for hiding this comment

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

I see, I removed these error logs.

@jsafrane jsafrane force-pushed the fix-csi-json branch 3 times, most recently from c62d16b to 9069efe Compare June 26, 2018 15:40
@msau42
Copy link
Member

msau42 commented Jun 26, 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 Jun 26, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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

@msau42
Copy link
Member

msau42 commented Jun 26, 2018

/retest

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 65404, 65323, 65468). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit e55ea16 into kubernetes:master Jun 27, 2018
k8s-github-robot pushed a commit that referenced this pull request Jul 12, 2018
#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.
```
k8s-github-robot pushed a commit that referenced this pull request Jul 19, 2018
#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.
```
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
Development

Successfully merging this pull request may close these issues.

6 participants