-
Notifications
You must be signed in to change notification settings - Fork 39.5k
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
kubeadm: fix the invalid cross-device link bug during upgrade #123406
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: SataQiu 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 |
@SataQiu: GitHub didn't allow me to request PR reviews from the following users: shubham-yewalekar. Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this: 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. |
a2eb1fb
to
31af998
Compare
err := os.Rename(oldPath, newPath) | ||
if err != nil { | ||
klog.V(4).Infof("failed to rename %v to %v: %v, fallback to copy file", oldPath, newPath, err) | ||
if err := kubeadmutil.CopyFile(oldPath, newPath); 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.
is it safe to use it directly instead of a fallback? seems better to me.
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.
os.Rename
has better performance, this is useful for copying large files
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.
klog.V(4).Infof("failed to rename %v to %v: %v, fallback to copy file", oldPath, newPath, err)
users might find this message confusing.
suggesting:
klog.V(4).Infof("failed to rename %v to %v: %v, attempting an alternative method", oldPath, newPath, 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.
can we do better error handling here?
I mean we should only call this alternative function for copying the file across the devices if we see the cross device link error
also, can we put some comments to describe the cross device link error we saw and mention how this function solves that problem
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 error checking can be done like so:
https://gist.github.com/var23rav/23ae5d0d4d830aff886c3c970b8f6c6b?permalink_comment_id=4431960#gistcomment-4431960
$ grep "os.Rename" * -rnI
app/phases/upgrade/postupgrade_test.go:215: if err := os.Rename(from, to); err != nil {
app/phases/upgrade/postupgrade_test.go:227: if err := os.Rename(from, to); err != nil {
app/phases/upgrade/staticpods_test.go:327: moveFileFunc: os.Rename,
app/phases/upgrade/staticpods_test.go:338: moveFileFunc: os.Rename,
app/phases/upgrade/staticpods_test.go:349: moveFileFunc: os.Rename,
app/phases/upgrade/staticpods_test.go:360: moveFileFunc: os.Rename,
app/phases/upgrade/staticpods_test.go:376: return os.Rename(oldPath, newPath)
app/phases/upgrade/staticpods_test.go:393: return os.Rename(oldPath, newPath)
app/phases/upgrade/staticpods_test.go:410: return os.Rename(oldPath, newPath)
app/phases/upgrade/staticpods_test.go:422: moveFileFunc: os.Rename,
app/phases/upgrade/staticpods_test.go:434: moveFileFunc: os.Rename,
app/phases/upgrade/staticpods_test.go:446: moveFileFunc: os.Rename,
app/phases/upgrade/staticpods_test.go:457: moveFileFunc: os.Rename,
app/phases/upgrade/staticpods.go:126: return os.Rename(oldPath, newPath)
so we seem to not have any other locations with os.Rename outside of tests, but i think we should:
- create a new function kubeadmutil.MoveFile()
- use this function in staticpods.go
- it tries to do the os.Rename if it fails with the cross link error use the alternative way CopyFile / Remove
- add some comments why this can happen
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.
Updated
@@ -17,19 +17,30 @@ limitations under the License. | |||
package util | |||
|
|||
import ( | |||
"io" | |||
"os" | |||
) | |||
|
|||
// CopyFile copies a file from src to dest. | |||
func CopyFile(src, dest 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.
see #123254
recently we reverted a copy file unti test, would these changes break it again?
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.
we also need to make sure it works on windows.
i think all of these stdlib functions are portable to Windows, but hopefully there are no gotchas.
we should do a chmod on the destination file to give it appropriate permissions |
New file will have the same permissions as the old file: destFile, err := os.OpenFile(dest, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, sourceFileInfo.Mode()) |
/release-note-edit
|
/triage accepted |
…o mount a new device and create a symbolic link for /etc/kubernetes (or a sub-directory) so that kubeadm stores its information on the mounted device
31af998
to
f3cb505
Compare
/retest |
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.
/lgtm
thanks
LGTM label has been added. Git tree hash: c57df17ba0bdd7e1bcbaa36f9b3d95268bbb260d
|
What type of PR is this?
/kind bug
What this PR does / why we need it:
kubeadm: fix the invalid cross-device link bug during upgrade
Which issue(s) this PR fixes:
Fixes kubernetes/kubeadm#3023
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: