Skip to content

Commit

Permalink
[kaniko] Better error message when upload fails (#4023)
Browse files Browse the repository at this point in the history
* [kaniko] Better error message when upload fails

Fix #3944

Signed-off-by: David Gageot <david@gageot.net>

* Feedback

Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot authored Apr 26, 2020
1 parent f0364bd commit 89d9933
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pkg/skaffold/build/cluster/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package cluster

import (
"bytes"
"context"
"fmt"
"io"
Expand Down Expand Up @@ -95,10 +96,17 @@ func (b *Builder) copyKanikoBuildContext(ctx context.Context, workspace string,
buildCtxWriter.Close()
}()

if err := b.kubectlcli.Run(ctx, buildCtx, nil, "exec", "-i", podName, "-c", initContainer, "-n", b.Namespace, "--", "tar", "-xf", "-", "-C", constants.DefaultKanikoEmptyDirMountPath); err != nil {
return fmt.Errorf("uploading build context: %w", err)
// Send context by piping into `tar`.
// 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", constants.DefaultKanikoEmptyDirMountPath); err != nil {
return fmt.Errorf("uploading build context: %s", out.String())
}

// Generate a file to successfully terminate the init container
return b.kubectlcli.Run(ctx, nil, nil, "exec", podName, "-c", initContainer, "-n", b.Namespace, "--", "touch", "/tmp/complete")
// Generate a file to successfully terminate the init container.
if out, err := b.kubectlcli.RunOut(ctx, "exec", podName, "-c", initContainer, "-n", b.Namespace, "--", "touch", "/tmp/complete"); err != nil {
return fmt.Errorf("finishing upload of the build context: %s", out)
}

return nil
}

0 comments on commit 89d9933

Please sign in to comment.