Skip to content

Commit 80b80c6

Browse files
chengjoeytekton-robot
authored andcommitted
fix taskrun failing with duplicate unique image found
fix [issue-6257](#6257) ignore unknown OS/architecture image entrypoint, because runtime.GOOS and runtime.GOARCH will not be unkonwn. all possible GOOS values are defined in src/go/build/syslist.go Signed-off-by: chengjoey <[email protected]>
1 parent 8cb2529 commit 80b80c6

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

pkg/pod/entrypoint_lookup_impl.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ func buildCommandMap(idx v1.ImageIndex, hasArgs bool) (map[string][]string, erro
139139
}
140140
for _, desc := range mf.Manifests {
141141
plat := desc.Platform.String()
142+
// skip unknown platforms.
143+
// Docker uses these to store attestation data: https://docs.docker.com/build/attestations/attestation-storage/#examples
144+
if plat == "unknown/unknown" {
145+
continue
146+
}
142147
if got, found := platToDigest[plat]; found && got != desc.Digest {
143148
return nil, fmt.Errorf("duplicate unique image found for platform: %s: found %s and %s", plat, got, desc.Digest)
144149
}

pkg/pod/entrypoint_lookup_impl_test.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func TestBuildCommandMap(t *testing.T) {
197197
desc string
198198
idx v1.ImageIndex
199199
wantErr bool
200+
want map[string][]string
200201
}{{
201202
// Valid multi-platform image even though some platforms only differ by variant or osversion.
202203
desc: "valid index",
@@ -226,6 +227,13 @@ func TestBuildCommandMap(t *testing.T) {
226227
Platform: &v1.Platform{OS: "windows", Architecture: "amd64", OSVersion: "4.5.6"},
227228
},
228229
}),
230+
want: map[string][]string{
231+
"linux/amd64": nil,
232+
"linux/arm64/7": nil,
233+
"linux/arm64/8": nil,
234+
"windows/amd64:1.2.3": nil,
235+
"windows/amd64:4.5.6": nil,
236+
},
229237
}, {
230238
desc: "valid index, with dupes",
231239
idx: mutate.AppendManifests(empty.Index, mutate.IndexAddendum{
@@ -239,6 +247,9 @@ func TestBuildCommandMap(t *testing.T) {
239247
Platform: &v1.Platform{OS: "linux", Architecture: "amd64"},
240248
},
241249
}),
250+
want: map[string][]string{
251+
"linux/amd64": nil,
252+
},
242253
}, {
243254
desc: "invalid index, dupes with different digests",
244255
idx: mutate.AppendManifests(empty.Index, mutate.IndexAddendum{
@@ -253,13 +264,41 @@ func TestBuildCommandMap(t *testing.T) {
253264
},
254265
}),
255266
wantErr: true,
267+
}, {
268+
desc: "valid index, with unknown platform",
269+
idx: mutate.AppendManifests(empty.Index, mutate.IndexAddendum{
270+
Add: img,
271+
Descriptor: v1.Descriptor{
272+
Platform: &v1.Platform{OS: "linux", Architecture: "amd64"},
273+
},
274+
}, mutate.IndexAddendum{
275+
Add: img,
276+
Descriptor: v1.Descriptor{
277+
Platform: &v1.Platform{OS: "unknown", Architecture: "unknown"},
278+
},
279+
}),
280+
want: map[string][]string{
281+
"linux/amd64": nil,
282+
},
283+
}, {
284+
desc: "valid index, only unknown platform",
285+
idx: mutate.AppendManifests(empty.Index, mutate.IndexAddendum{
286+
Add: img,
287+
Descriptor: v1.Descriptor{
288+
Platform: &v1.Platform{OS: "unknown", Architecture: "unknown"},
289+
},
290+
}),
291+
want: map[string][]string{},
256292
}} {
257293
t.Run(c.desc, func(t *testing.T) {
258-
_, err := buildCommandMap(c.idx, true)
294+
got, err := buildCommandMap(c.idx, true)
259295
gotErr := (err != nil)
260296
if gotErr != c.wantErr {
261297
t.Fatalf("got err: %v, want err: %t", err, c.wantErr)
262298
}
299+
if d := cmp.Diff(c.want, got); d != "" && !c.wantErr {
300+
t.Errorf("Diff %s", diff.PrintWantGot(d))
301+
}
263302
})
264303
}
265304
}

0 commit comments

Comments
 (0)