Skip to content

Commit

Permalink
fix taskrun failing with duplicate unique image found
Browse files Browse the repository at this point in the history
fix [issue-6257](#6257)

ignore unknown OS/architecture image entrypoint, because runtime.GOOS and runtime.GOARCH will not be unkonwn

Signed-off-by: chengjoey <zchengjoey@gmail.com>
  • Loading branch information
chengjoey committed Mar 10, 2023
1 parent 4ee897b commit a0e8890
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/pod/entrypoint_lookup_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
32 changes: 31 additions & 1 deletion pkg/pod/entrypoint_lookup_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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))
}
})
}
}
Expand Down

0 comments on commit a0e8890

Please sign in to comment.