Skip to content

Commit 241d1ed

Browse files
author
Venkatesh
committed
Get tmp storage from os env in kaniko local context storing
1 parent 36e9cbd commit 241d1ed

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pkg/skaffold/build/kaniko/sources/localdir.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type LocalDir struct {
4848

4949
// Setup for LocalDir creates a tarball of the buildcontext and stores it in /tmp
5050
func (g *LocalDir) Setup(ctx context.Context, out io.Writer, artifact *latest.Artifact, initialTag string) (string, error) {
51-
g.tarPath = filepath.Join("/tmp", fmt.Sprintf("context-%s.tar.gz", initialTag))
51+
g.tarPath = filepath.Join("os.TempDir()", fmt.Sprintf("context-%s.tar.gz", initialTag))
5252
color.Default.Fprintln(out, "Storing build context at", g.tarPath)
5353

5454
f, err := os.Create(g.tarPath)
@@ -105,12 +105,13 @@ func (g *LocalDir) ModifyPod(ctx context.Context, p *v1.Pod) error {
105105
return errors.Wrap(err, "waiting for pod to initialize")
106106
}
107107
// Copy over the buildcontext tarball into the init container
108-
copy := exec.CommandContext(ctx, "kubectl", "cp", g.tarPath, fmt.Sprintf("%s:/%s", p.Name, g.tarPath), "-c", initContainer, "-n", p.Namespace)
108+
tarCopyPath := fmt.Sprintf("/tmp/%s", filepath.Base(g.tarPath))
109+
copy := exec.CommandContext(ctx, "kubectl", "cp", g.tarPath, fmt.Sprintf("%s:%s", p.Name, tarCopyPath), "-c", initContainer, "-n", p.Namespace)
109110
if err := util.RunCmd(copy); err != nil {
110111
return errors.Wrap(err, "copying buildcontext into init container")
111112
}
112113
// Next, extract the buildcontext to the empty dir
113-
extract := exec.CommandContext(ctx, "kubectl", "exec", p.Name, "-c", initContainer, "-n", p.Namespace, "--", "tar", "-xzf", g.tarPath, "-C", constants.DefaultKanikoEmptyDirMountPath)
114+
extract := exec.CommandContext(ctx, "kubectl", "exec", p.Name, "-c", initContainer, "-n", p.Namespace, "--", "tar", "-xzf", tarCopyPath, "-C", constants.DefaultKanikoEmptyDirMountPath)
114115
if err := util.RunCmd(extract); err != nil {
115116
return errors.Wrap(err, "extracting buildcontext to empty dir")
116117
}

0 commit comments

Comments
 (0)