Skip to content
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

[kaniko] Better error message when upload fails #4023

Merged
merged 2 commits into from
Apr 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}