Skip to content

Commit

Permalink
Log kaniko errors that happen during the tar phase
Browse files Browse the repository at this point in the history
  • Loading branch information
pearj committed Nov 24, 2021
1 parent 2e5439d commit eb6c7ec
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/skaffold/build/cluster/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ func (b *Builder) copyKanikoBuildContext(ctx context.Context, workspace string,
return fmt.Errorf("waiting for pod to initialize: %w", err)
}

errs := make(chan error, 1)
buildCtx, buildCtxWriter := io.Pipe()
go func() {
err := docker.CreateDockerTarContext(ctx, buildCtxWriter, docker.NewBuildConfig(
workspace, artifactName, artifact.DockerfilePath, artifact.BuildArgs), b.cfg)
if err != nil {
buildCtxWriter.CloseWithError(fmt.Errorf("creating docker context: %w", err))
errs <- err
return
}
buildCtxWriter.Close()
Expand All @@ -117,7 +119,12 @@ func (b *Builder) copyKanikoBuildContext(ctx context.Context, workspace string,
// In case of an error, print the command's output. (The `err` itself is useless: exit status 1).
var out bytes.Buffer
if err := b.kubectlcli.Run(ctx, buildCtx, &out, "exec", "-i", podName, "-c", initContainer, "-n", b.Namespace, "--", "tar", "-xf", "-", "-C", kaniko.DefaultEmptyDirMountPath); err != nil {
return fmt.Errorf("uploading build context: %s", out.String())
errRun := fmt.Errorf("uploading build context: %s", out.String())
errTar := <-errs
if errTar != nil {
errRun = fmt.Errorf("%v\ntar errors: %w", errRun, errTar)
}
return errRun
}

// Generate a file to successfully terminate the init container.
Expand Down

0 comments on commit eb6c7ec

Please sign in to comment.