Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: write directory headers in kodata tar archives#1604

Merged
imjasonh merged 3 commits into
ko-build:mainfrom
0xiso:fix-kodata-tar-directory-headers
Mar 17, 2026
Merged

fix: write directory headers in kodata tar archives#1604
imjasonh merged 3 commits into
ko-build:mainfrom
0xiso:fix-kodata-tar-directory-headers

Conversation

@0xiso

@0xiso 0xiso commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

Problem

The walkRecursive() function in pkg/build/gobuild.go skips directory entries without writing tar headers. This causes issues with strict tar implementations that expect directory entries to be present. For example, container image scanners like Wiz fail to extract images that contain kodata with subdirectories.

Solution

Refactor walkRecursive to write directory headers:

  • Write directory headers when encountering directories instead of skipping them
  • Write directory headers before recursing into symlinked directories

Supporting changes:

  • Add writeDirToTar and writeFileToTar helper functions for better code organization
  • Update tarKoData to use writeDirToTar helper

Test plan

  • Added test for directory header presence in kodata layer
  • ./hack/presubmit.sh passes

0xiso and others added 3 commits January 23, 2026 21:05
The walkRecursive() function was skipping directory entries without
writing tar headers. This causes some strict tar implementations to
fail extraction.

- Add writeDirToTar helper to write directory headers
- Add writeFileToTar helper to write file headers and content
- Refactor walkRecursive to write directory headers before recursing
- Update tarKoData to use writeDirToTar helper
- Add test for directory header presence in kodata layer
Copilot AI review requested due to automatic review settings March 17, 2026 16:43

@imjasonh imjasonh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for this contribution, and for adding tests -- and mostly for your patience while it sat waiting for review :)

LGTM

@imjasonh imjasonh enabled auto-merge (rebase) March 17, 2026 16:44
@imjasonh imjasonh merged commit 351db11 into ko-build:main Mar 17, 2026
19 of 20 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors kodata tar-layer creation to include explicit directory entries, fixing extraction failures in strict tar consumers (e.g., container scanners) when kodata contains subdirectories.

Changes:

  • Add writeDirToTar / writeFileToTar helpers and refactor walkRecursive() to emit directory headers (including for symlinked directories) before recursing.
  • Update tarKoData() to use the new directory-header helper for parent directories.
  • Add a regression test and new kodata fixture to assert subdirectory directory headers are present in the produced layer.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/build/gobuild.go Refactors tar-writing logic and ensures directory headers are emitted during kodata packaging.
pkg/build/gobuild_test.go Adds a test that validates directory headers exist for a kodata subdirectory in the layer tar stream.
test/kodata/subdir/file.txt Adds a kodata subdirectory fixture used by the new test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread pkg/build/gobuild.go
Comment on lines +722 to +723
// This magic value is for some reason needed for Windows to be
// able to execute the binary.
@0xiso 0xiso deleted the fix-kodata-tar-directory-headers branch March 18, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants