-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 flake TestRun/Dockerfile_test_copy_symlink #1030
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -584,7 +584,7 @@ func CopyDir(src, dest, buildcontext string, uid, gid int64) ([]string, error) { | |
} | ||
} else if IsSymlink(fi) { | ||
// If file is a symlink, we want to create the same relative symlink | ||
if _, err := CopySymlink(fullPath, destPath, buildcontext); err != nil { | ||
if _, err := CopySymlink(fullPath, destPath, buildcontext, uid, gid); err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
|
@@ -599,12 +599,12 @@ func CopyDir(src, dest, buildcontext string, uid, gid int64) ([]string, error) { | |
} | ||
|
||
// CopySymlink copies the symlink at src to dest | ||
func CopySymlink(src, dest, buildcontext string) (bool, error) { | ||
func CopySymlink(src, dest, buildcontext string, uid int64, gid int64) (bool, error) { | ||
if ExcludeFile(src, buildcontext) { | ||
logrus.Debugf("%s found in .dockerignore, ignoring", src) | ||
return true, nil | ||
} | ||
link, err := os.Readlink(src) | ||
link, err := filepath.EvalSymlinks(src) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
@@ -616,7 +616,7 @@ func CopySymlink(src, dest, buildcontext string) (bool, error) { | |
if err := createParentDirectory(dest); err != nil { | ||
return false, err | ||
} | ||
return false, os.Symlink(link, dest) | ||
return CopyFile(link, dest, buildcontext, uid, gid) | ||
} | ||
|
||
// CopyFile copies the file at src to dest | ||
|
@@ -789,11 +789,15 @@ func getSymlink(path string) error { | |
func CopyFileOrSymlink(src string, destDir string) error { | ||
destFile := filepath.Join(destDir, src) | ||
if fi, _ := os.Lstat(src); IsSymlink(fi) { | ||
link, err := os.Readlink(src) | ||
link, err := EvalSymLink(src) | ||
if err != nil { | ||
return err | ||
} | ||
return os.Symlink(link, destFile) | ||
linkPath := filepath.Join(destDir, link) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain this code a bit? I'm having trouble wraping my head around it. It looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was error 1 mentioned in here This ensures, we are copying/creating the required file in kaniko sratch workspace. |
||
if err := createParentDirectory(destFile); err != nil { | ||
return err | ||
} | ||
return os.Symlink(linkPath, destFile) | ||
} | ||
return otiai10Cpy.Copy(src, destFile) | ||
} | ||
|
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 the change from link to copy? I'm struggling to connect this change to a flaky test.
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.
This test was flaky because of 2 reasons
link
value was/tmp/target
.We were linking
kaniko/0/tmp/link
to/tmp/target
- should have been/kaniko/0/tmp/link
/tmp/target
was getting wiped out before call toos.Symlink(link, dest)
. - this caused flakiness.(I still don't know why this is caused. However, imitating docker by actually creating the destlink as a regular file with contents of target file fixed the flakiness)
In the description, i mentioned i fixed the
CopySymlink
to replicate docker behavior. Docker copies the target file to destination link and hence i replacedos.Symlink
toCopyFile
.