diff --git a/pkg/apis/build/v1alpha2/build_pod.go b/pkg/apis/build/v1alpha2/build_pod.go index 0d525daa..0263c9bc 100644 --- a/pkg/apis/build/v1alpha2/build_pod.go +++ b/pkg/apis/build/v1alpha2/build_pod.go @@ -269,6 +269,8 @@ func (b *Build) BuildPod(images BuildPodImages, buildContext BuildContext) (*cor useCacheFromLastBuild := b.Spec.LastBuild != nil && b.Spec.LastBuild.Cache.Image != "" if useCacheFromLastBuild { genericCacheArgs = []string{fmt.Sprintf("-cache-image=%s", b.Spec.LastBuild.Cache.Image)} + } else { + genericCacheArgs = []string{fmt.Sprintf("-cache-image=%s", b.Spec.Cache.Registry.Tag)} } analyzerCacheArgs = genericCacheArgs exporterCacheArgs = []string{fmt.Sprintf("-cache-image=%s", b.Spec.Cache.Registry.Tag)} diff --git a/pkg/apis/build/v1alpha2/build_pod_test.go b/pkg/apis/build/v1alpha2/build_pod_test.go index 7ade6f4e..cdc8bf47 100644 --- a/pkg/apis/build/v1alpha2/build_pod_test.go +++ b/pkg/apis/build/v1alpha2/build_pod_test.go @@ -1053,19 +1053,19 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) { assert.Len(t, podWithImageCache.Spec.Volumes, len(podWithVolumeCache.Spec.Volumes)-1) }) - it("does not add the cache to analyze container", func() { + it("does add the cache to analyze container", func() { podWithImageCache, err := build.BuildPod(config, buildContext) require.NoError(t, err) analyzeContainer := podWithImageCache.Spec.InitContainers[2] - assert.NotContains(t, analyzeContainer.Args, "-cache-image=test-cache-image") + assert.Contains(t, analyzeContainer.Args, "-cache-image=test-cache-image") }) - it("does not add the cache to restore container", func() { + it("does add cache to restore container", func() { podWithImageCache, err := build.BuildPod(config, buildContext) require.NoError(t, err) restoreContainer := podWithImageCache.Spec.InitContainers[3] - assert.NotContains(t, restoreContainer.Args, "-cache-image=test-cache-image") + assert.Contains(t, restoreContainer.Args, "-cache-image=test-cache-image") }) it("adds the cache to export container", func() { podWithImageCache, err := build.BuildPod(config, buildContext)