From a0e88908054f7bda436f3d43398ef0e76b69ab74 Mon Sep 17 00:00:00 2001 From: joey Date: Wed, 1 Mar 2023 23:34:02 +0800 Subject: [PATCH] fix taskrun failing with duplicate unique image found fix [issue-6257](https://github.com/tektoncd/pipeline/issues/6257) ignore unknown OS/architecture image entrypoint, because runtime.GOOS and runtime.GOARCH will not be unkonwn Signed-off-by: chengjoey --- pkg/pod/entrypoint_lookup_impl.go | 5 ++++ pkg/pod/entrypoint_lookup_impl_test.go | 32 +++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/pkg/pod/entrypoint_lookup_impl.go b/pkg/pod/entrypoint_lookup_impl.go index 3af21be8baa..fa515519734 100644 --- a/pkg/pod/entrypoint_lookup_impl.go +++ b/pkg/pod/entrypoint_lookup_impl.go @@ -139,6 +139,11 @@ func buildCommandMap(idx v1.ImageIndex, hasArgs bool) (map[string][]string, erro } for _, desc := range mf.Manifests { plat := desc.Platform.String() + // skip unknown platforms. + // Docker uses these to store attestation data: https://docs.docker.com/build/attestations/attestation-storage/#examples + if plat == "unknown/unknown" { + continue + } if got, found := platToDigest[plat]; found && got != desc.Digest { return nil, fmt.Errorf("duplicate unique image found for platform: %s: found %s and %s", plat, got, desc.Digest) } diff --git a/pkg/pod/entrypoint_lookup_impl_test.go b/pkg/pod/entrypoint_lookup_impl_test.go index f18e4a8fced..0864d7c9aef 100644 --- a/pkg/pod/entrypoint_lookup_impl_test.go +++ b/pkg/pod/entrypoint_lookup_impl_test.go @@ -197,6 +197,7 @@ func TestBuildCommandMap(t *testing.T) { desc string idx v1.ImageIndex wantErr bool + want map[string][]string }{{ // Valid multi-platform image even though some platforms only differ by variant or osversion. desc: "valid index", @@ -226,6 +227,13 @@ func TestBuildCommandMap(t *testing.T) { Platform: &v1.Platform{OS: "windows", Architecture: "amd64", OSVersion: "4.5.6"}, }, }), + want: map[string][]string{ + "linux/amd64": nil, + "linux/arm64/7": nil, + "linux/arm64/8": nil, + "windows/amd64:1.2.3": nil, + "windows/amd64:4.5.6": nil, + }, }, { desc: "valid index, with dupes", idx: mutate.AppendManifests(empty.Index, mutate.IndexAddendum{ @@ -239,6 +247,9 @@ func TestBuildCommandMap(t *testing.T) { Platform: &v1.Platform{OS: "linux", Architecture: "amd64"}, }, }), + want: map[string][]string{ + "linux/amd64": nil, + }, }, { desc: "invalid index, dupes with different digests", idx: mutate.AppendManifests(empty.Index, mutate.IndexAddendum{ @@ -253,13 +264,32 @@ func TestBuildCommandMap(t *testing.T) { }, }), wantErr: true, + }, { + desc: "valid index, with unknown platform", + idx: mutate.AppendManifests(empty.Index, mutate.IndexAddendum{ + Add: img, + Descriptor: v1.Descriptor{ + Platform: &v1.Platform{OS: "linux", Architecture: "amd64"}, + }, + }, mutate.IndexAddendum{ + Add: img, + Descriptor: v1.Descriptor{ + Platform: &v1.Platform{OS: "unknown", Architecture: "unknown"}, + }, + }), + want: map[string][]string{ + "linux/amd64": nil, + }, }} { t.Run(c.desc, func(t *testing.T) { - _, err := buildCommandMap(c.idx, true) + got, err := buildCommandMap(c.idx, true) gotErr := (err != nil) if gotErr != c.wantErr { t.Fatalf("got err: %v, want err: %t", err, c.wantErr) } + if d := cmp.Diff(c.want, got); d != "" && !c.wantErr { + t.Fatalf("Diff %s", diff.PrintWantGot(d)) + } }) } }