Skip to content

Commit

Permalink
Fix kaniko test
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 committed Dec 8, 2020
1 parent f96742f commit 35bff8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/skaffold/build/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (b *Builder) runBuildForArtifact(ctx context.Context, out io.Writer, a *lat
requiredImages := docker.ResolveDependencyImages(a.Dependencies, b.artifactStore, true)
switch {
case a.KanikoArtifact != nil:
return b.buildWithKaniko(ctx, out, a.Workspace, a.KanikoArtifact, tag, requiredImages)
return b.buildWithKaniko(ctx, out, a.Workspace, a.ImageName, a.KanikoArtifact, tag, requiredImages)

case a.CustomArtifact != nil:
return custom.NewArtifactBuilder(nil, b.cfg, true, append(b.retrieveExtraEnv(), util.EnvPtrMapToSlice(requiredImages, "=")...)).Build(ctx, out, a, tag)
Expand Down
8 changes: 4 additions & 4 deletions pkg/skaffold/build/cluster/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (

const initContainer = "kaniko-init-container"

func (b *Builder) buildWithKaniko(ctx context.Context, out io.Writer, workspace string, artifact *latest.KanikoArtifact, tag string, requiredImages map[string]*string) (string, error) {
func (b *Builder) buildWithKaniko(ctx context.Context, out io.Writer, workspace string, artifactName string, artifact *latest.KanikoArtifact, tag string, requiredImages map[string]*string) (string, error) {
generatedEnvs, err := generateEnvFromImage(tag)
if err != nil {
return "", fmt.Errorf("error processing generated env variables from image uri: %w", err)
Expand Down Expand Up @@ -77,7 +77,7 @@ func (b *Builder) buildWithKaniko(ctx context.Context, out io.Writer, workspace
}
}()

if err := b.copyKanikoBuildContext(ctx, workspace, artifact, pods, pod.Name); err != nil {
if err := b.copyKanikoBuildContext(ctx, workspace, artifactName, artifact, pods, pod.Name); err != nil {
return "", fmt.Errorf("copying sources: %w", err)
}

Expand All @@ -97,15 +97,15 @@ func (b *Builder) buildWithKaniko(ctx context.Context, out io.Writer, workspace
// first copy over the buildcontext tarball into the init container tmp dir via kubectl cp
// Via kubectl exec, we extract the tarball to the empty dir
// Then, via kubectl exec, create the /tmp/complete file via kubectl exec to complete the init container
func (b *Builder) copyKanikoBuildContext(ctx context.Context, workspace string, artifact *latest.KanikoArtifact, pods corev1.PodInterface, podName string) error {
func (b *Builder) copyKanikoBuildContext(ctx context.Context, workspace string, artifactName string, artifact *latest.KanikoArtifact, pods corev1.PodInterface, podName string) error {
if err := kubernetes.WaitForPodInitialized(ctx, pods, podName); err != nil {
return fmt.Errorf("waiting for pod to initialize: %w", err)
}

buildCtx, buildCtxWriter := io.Pipe()
go func() {
err := docker.CreateDockerTarContext(ctx, buildCtxWriter, docker.NewBuildConfig(
workspace, artifact.Image, artifact.DockerfilePath, artifact.BuildArgs), b.cfg)
workspace, artifactName, artifact.DockerfilePath, artifact.BuildArgs), b.cfg)
if err != nil {
buildCtxWriter.CloseWithError(fmt.Errorf("creating docker context: %w", err))
return
Expand Down

0 comments on commit 35bff8e

Please sign in to comment.