1743: preserve hardlinks during COPY --from - part 2 - #626
Conversation
|
whether to FF gate this fix is debatable. the image will be different yes, but "more correct". Then on the other hand spending a FF is also not too complicated and makes the issue come up neatly in the 1.28.0 release. |
14a79df to
4340cd2
Compare
|
AI summary review OverviewFixes a real, well-documented regression: Code QualityGood:
Issues: 1.
|
| Priority | Issue |
|---|---|
| Low | checkCopyHardlink called unconditionally even when flag is off — restructure the else if |
| Low | No unit test for the new code path |
| Low | No EXDEV fallback in os.Link |
| Nit | Log message argument order is inverted |
876b087 to
718ec16
Compare
cddbf06 to
a72dcb8
Compare
a72dcb8 to
33ac1c0
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
33ac1c0 to
a0fc55b
Compare
a0fc55b to
b0d0ab1
Compare
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds feature flags for skipping special files and using native copy operations. Copy utilities now recreate FIFOs, preserve hardlinks and symlinks, and support bulk tree/path copying across Dockerfile, bind-mount, multistage, integration, and unit-test paths. ChangesCopy behavior and feature flags
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Dockerfile
participant CopyCommand
participant CopyTree
participant copyDirInner
participant Destination
Dockerfile->>CopyCommand: COPY source
CopyCommand->>CopyTree: copy tree or paths
CopyTree->>copyDirInner: process filesystem entries
copyDirInner->>Destination: recreate FIFOs and preserve links
Destination-->>CopyCommand: copied entries
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
64ca708 to
1768be6
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/util/fs_util.go`:
- Line 1319: Update both native copy helper calls in pkg/util/fs_util.go at
lines 1319 and 917 to pass config.FF.CopySkipSpecialFiles instead of hard-coded
true for the skipSpecialFiles argument; preserve CreateFifo’s safe FIFO
handling.
In `@README.md`:
- Around line 1266-1270: Update the FF_KANIKO_PRESERVE_HARDLINKS documentation
to clarify that preserving hardlinks also requires FF_KANIKO_NATIVE_COPY=true
until NativeCopy becomes the default in v1.29.0. Keep the existing explanation
of the preserve-hardlinks default unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4f8b489f-00e0-4792-b6cf-2152d30b22ad
📒 Files selected for processing (11)
README.mdintegration/dockerfiles/Dockerfile_test_issue_1599integration/dockerfiles/Dockerfile_test_issue_1743integration/images.gopkg/commands/copy.gopkg/commands/run.gopkg/config/featureflags.gopkg/executor/build.gopkg/executor/copy_multistage_test.gopkg/util/fs_util.gopkg/util/fs_util_test.go
|
@coderabbitai review |
✅ Action performedReview finished.
|
b791c66 to
2359db9
Compare
|
Second one applied, the Declining the first one. The hard-coded Those two call sites replace If they passed the flag instead, then The flag exists for regular |
bc9e288 to
4b0a85e
Compare
|
Retracting my previous reply, the finding was right and it is now fixed. My argument was that hard-coding Since all three call sites now want the same value, the The fifo case is unaffected either way. Also reverted the |
fb00aff to
e5342c5
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/util/fs_util.go (1)
836-841: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winReplace an existing destination before creating the hardlink.
If
destPathalready exists, Line 839 fails withEEXIST. For example, copying hardlinkeda/bonto a layer that already containsbcopiesathen fails onb; regular-file copying instead overwrites. Apply the same destination replacement semantics beforeos.Link.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/util/fs_util.go` around lines 836 - 841, Update the hardlink branch in checkCopyHardlink’s caller before os.Link(linkDst, destPath) to remove or replace any existing destPath, matching regular-file copy overwrite semantics; then create the hardlink and preserve the existing error propagation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@integration/dockerfiles/Dockerfile_test_issue_cg73`:
- Around line 24-27: Update the capability assertions after getcap in the
Dockerfile to match the complete expected value cap_net_raw=ep for both /blubb
and /dir/nested, rather than accepting any output containing cap_net_raw.
Preserve the existing checks that fail when capabilities are missing or have a
different state.
In `@pkg/commands/copy.go`:
- Around line 130-135: Update the FIFO branch in the copy flow to apply the same
c.fileContext.ExcludesFile(fullPath) and kConfig.KanikoDir destination guards
used by CopySymlink and CopyFile before calling util.CreateFifo. Preserve the
existing exclusion behavior and reject protected Kaniko paths without removing
or recreating them.
In `@pkg/util/fs_util.go`:
- Line 779: Update hardlink tracking around hardlinksSeen and checkCopyHardlink
to key entries by both device and inode rather than inode alone. Introduce a
comparable key containing the file’s device and inode values, and use it
consistently for lookup and insertion so identical inode numbers on different
filesystems remain distinct.
---
Outside diff comments:
In `@pkg/util/fs_util.go`:
- Around line 836-841: Update the hardlink branch in checkCopyHardlink’s caller
before os.Link(linkDst, destPath) to remove or replace any existing destPath,
matching regular-file copy overwrite semantics; then create the hardlink and
preserve the existing error propagation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 5270ec76-78e5-4100-a732-3679f114a167
📒 Files selected for processing (12)
README.mdintegration/dockerfiles/Dockerfile_test_issue_1599integration/dockerfiles/Dockerfile_test_issue_1743integration/dockerfiles/Dockerfile_test_issue_cg73integration/images.gopkg/commands/copy.gopkg/commands/run.gopkg/config/featureflags.gopkg/executor/build.gopkg/executor/copy_multistage_test.gopkg/util/fs_util.gopkg/util/fs_util_test.go
🚧 Files skipped from review as they are similar to previous changes (9)
- integration/dockerfiles/Dockerfile_test_issue_1599
- integration/dockerfiles/Dockerfile_test_issue_1743
- README.md
- pkg/executor/copy_multistage_test.go
- pkg/config/featureflags.go
- pkg/executor/build.go
- pkg/commands/run.go
- pkg/util/fs_util_test.go
- integration/images.go
3adedb5 to
994aade
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/executor/build.go`:
- Around line 1354-1357: Update the CopyPaths/copyDirInner hardlink handling so
an os.Link failure caused by EXDEV falls back to copying the file contents
normally, while preserving hardlinks when linking succeeds and retaining
existing errors for other failures. Ensure the NativeCopy flow continues to
report only unrecoverable copy errors.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2298364a-9237-4f1f-9ee5-eb773db4226f
📒 Files selected for processing (11)
README.mdintegration/dockerfiles/Dockerfile_test_issue_1743integration/dockerfiles/Dockerfile_test_issue_cg73integration/images.gopkg/commands/copy.gopkg/commands/run.gopkg/config/featureflags.gopkg/executor/build.gopkg/executor/copy_multistage_test.gopkg/util/fs_util.gopkg/util/fs_util_test.go
🚧 Files skipped from review as they are similar to previous changes (8)
- pkg/executor/copy_multistage_test.go
- integration/dockerfiles/Dockerfile_test_issue_1743
- pkg/config/featureflags.go
- pkg/util/fs_util_test.go
- README.md
- pkg/commands/run.go
- pkg/commands/copy.go
- pkg/util/fs_util.go
|
need to verify whether there is a performance impact of switching away from otiai10, i would assume positive |
0688740 to
199bcf1
Compare
199bcf1 to
193b564
Compare
a48fecf to
2041b1c
Compare
193b564 to
43cbc74
Compare
2041b1c to
f126cb8
Compare
43cbc74 to
9a379af
Compare
Fixes GoogleContainerTools/kaniko#1743
Description
Part 1 (#630) fixed 2594, hardlinks broken by
COPY --from=<image>. This second part coversCOPY --from=<stage>, where kaniko first persists the source stage's files into its internal dependency dir and later extracts them into the dependent stage.That persist step went through
github.com/otiai10/copy, which copies every file on its own and knows nothing about hardlinks. Files sharing an inode were already independent copies before the dependent stage saw them, soFF_KANIKO_PRESERVE_HARDLINKShad nothing left to preserve. It now walks the tree once and links subsequent occurrences of an inode instead of duplicating content.Capabilities were a narrower problem than hardlinks. The save path called
CopyCapabilitiesafterwards, but only for the path named in theCOPY, so a file carrying capabilities directly was fine while one sitting inside a copied directory lost them.Dockerfile_test_issue_cg73covered the first shape already and now covers the second.The same substitution covers the two other places the library was used, the cross-device fallback when a bind mount target is moved aside and the
RUN --mount=type=bindsource copy. Neither of those reapplied capabilities at all.Gated behind
FF_KANIKO_NATIVE_COPY=false. Becomes default in v1.29.0. Stacked on #948, which the save path needs so that a socket or device in a saved directory is skipped rather than read.Summary by CodeRabbit
New Features
COPYhandling and enable native copy behavior.RUN --mount=type=bindbind sources and multistage saved artifacts use native copy logic.Bug Fixes
COPYnow properly recreates FIFOs (including metadata preservation) and improves symlink/hardlink handling across stages.Tests