Skip to content

Commit

Permalink
fix: report errors correctly when pulling, fix EEXIST
Browse files Browse the repository at this point in the history
Kaniko adds an entry for the root folder `/` in its tarballs.
Processing the file causes the process to hang when trying to
recreate the destination directory.

The root directory already exists, so it triggers an error, but as the
errors were not correctly propagated, the process hangs forever.

Fix both issues.

Signed-off-by: Andrey Smirnov <[email protected]>
(cherry picked from commit 81f9fcd)
  • Loading branch information
mottetm-roche authored and smira committed Sep 25, 2024
1 parent 1e4e5ac commit da5b526
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/archiver/untar.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func Untar(ctx context.Context, r io.Reader, rootPath string) error {

switch hdr.Typeflag {
case tar.TypeDir:
mode := hdr.FileInfo().Mode()
mode := hdr.FileInfo().Mode() & os.ModePerm
mode |= 0o700 // make rwx for the owner

if err = os.Mkdir(path, mode); err != nil {
if err = os.Mkdir(path, mode); err != nil && !os.IsExist(err) {
return fmt.Errorf("error creating directory %q mode %s: %w", path, mode, err)
}

Expand Down
18 changes: 15 additions & 3 deletions pkg/imager/profile/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,25 @@ func (c *ContainerAsset) Extract(ctx context.Context, destination, arch string,
eg, ctx := errgroup.WithContext(ctx)

eg.Go(func() error {
defer w.Close() //nolint:errcheck
if exportErr := crane.Export(img, w); exportErr != nil {
w.CloseWithError(exportErr)

return crane.Export(img, w)
return exportErr
}

w.Close() //nolint:errcheck

return nil
})

eg.Go(func() error {
return archiver.Untar(ctx, r, destination)
if untarErr := archiver.Untar(ctx, r, destination); untarErr != nil {
r.CloseWithError(untarErr)

return untarErr
}

return nil
})

return eg.Wait()
Expand Down

0 comments on commit da5b526

Please sign in to comment.