Skip to content

feat: Add an command line option to exclude root directory in the tar… #3425

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zhiyuan-chn
Copy link

@zhiyuan-chn zhiyuan-chn commented Mar 19, 2025

feat: Add an option to exclude root directory in tarball

Fixes #1375

Description

The issue is that images built by Kaniko cannot be pulled successfully by Flux because Kaniko adds an absolute directory path “/” which tar program used by Flux doesn’t allow.

This PR adds a new command line option --exclude-root-dir-tarball to allow excluding root directory in the tar archive.

Testing done:

  • Verified that all existing unit tests passed in a linux environment.
  • Verified that the updated Kaniko image can generate tarball without root directory and command flux pull artifact <oci> works properly.
    • Followed the public Kaniko tutorial here to set up local testing environment

Here are a few references about how the verification was performed.

# updated pod.yaml
  containers:
  - name: kaniko
    image: docker.io/zchen333/kaniko-project:latest
    args: ["--dockerfile=/workspace/dockerfile",
            "--context=dir://workspace",
            "--exclude-root-dir-tarball=true",
            "--destination=zchen333/kaniko"] # replace with your dockerhub account

# tested different forms of input
* `--exclude-root-dir-tarball=true` // true
* `--exclude-root-dir-tarball=false` // false
* `--exclude-root-dir-tarball` // true
* None // false by default

# dockerfile to test
echo 'FROM scratch AS builder' >> dockerfile
echo 'COPY clusters /tmp/clusters' >> dockerfile
echo 'COPY teleports /tmp/teleports' >> dockerfile
echo 'FROM scratch' >> dockerfile
echo 'COPY --from=builder /tmp /' >> dockerfile

# Kaniko logs
INFO[0001] Resolved base name scratch to builder
INFO[0001] No base image, nothing to extract
INFO[0001] No base image, nothing to extract
INFO[0001] Built cross stage deps: map[0:[/tmp]]
INFO[0001] No base image, nothing to extract
INFO[0001] Executing 0 build triggers
INFO[0001] Building stage 'scratch' [idx: '0', base-idx: '-1']
INFO[0001] Unpacking rootfs as cmd COPY clusters /tmp/clusters requires it.
INFO[0001] COPY clusters /tmp/clusters
INFO[0001] Taking snapshot of files...
INFO[0001] COPY teleport /tmp/teleport
INFO[0001] Taking snapshot of files...
INFO[0001] Saving file tmp for later use
INFO[0001] Deleting filesystem...
INFO[0001] No base image, nothing to extract
INFO[0001] Executing 0 build triggers
INFO[0001] Building stage 'scratch' [idx: '1', base-idx: '-1']
INFO[0001] Unpacking rootfs as cmd COPY --from=builder /tmp / requires it.
INFO[0001] COPY --from=builder /tmp /
INFO[0001] Taking snapshot of files...
INFO[0001] Pushing image to zchen333/kaniko
INFO[0003] Pushed index.docker.io/zchen333/kaniko@sha256:b0d296891d689a02c7c16b57d46defe08d2209ce3f4b17f7d0f65f198d32bb71


# Flux pull 
❯ flux pull artifact oci://index.docker.io/zchen333/kaniko@sha256:b0d296891d689a02c7c16b57d46defe08d2209ce3f4b17f7d0f65f198d32bb71 --output ./manifests
► pulling artifact from index.docker.io/zchen333/kaniko@sha256:b0d296891d689a02c7c16b57d46defe08d2209ce3f4b17f7d0f65f198d32bb71
✔ digest index.docker.io/zchen333/kaniko@sha256:b0d296891d689a02c7c16b57d46defe08d2209ce3f4b17f7d0f65f198d32bb71
✔ artifact content extracted to ./manifests

❯ ls ./manifests
clusters	teleport

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Adds integration tests if needed.

See the contribution guide for more details.

Reviewer Notes

  • The code flow looks good.
  • Unit tests and or integration tests added.

Release Notes

Describe any changes here so maintainer can include it in the release notes, or delete this block.

Examples of user facing changes:
- kaniko adds a new flag `--registry-repo` to override registry

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.

Layer tar files contain entry for root (/)
1 participant