Skip to content

Commit 195ef6e

Browse files
committed
plume/release: inject oci-images key in release index
When updating the release index, gather the OCI pullspecs across all arches for a given release into a single list and inject it into the new `oci-images` key, the same way we do for OSTree commits and `commits`. Part of coreos/fedora-coreos-tracker#1823.
1 parent 21e4433 commit 195ef6e

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

mantle/cmd/plume/release.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,21 @@ func modifyReleaseMetadataIndex(api *aws.API, rel release.Release) {
297297
}
298298

299299
var commits []release.IndexReleaseCommit
300+
var pullspecs []release.IndexReleaseOciImage
300301
for arch, vals := range rel.Architectures {
301302
commits = append(commits, release.IndexReleaseCommit{
302303
Architecture: arch,
303304
Checksum: vals.Commit,
304305
})
306+
pullspecs = append(pullspecs, release.IndexReleaseOciImage{
307+
Architecture: arch,
308+
ContainerImage: *vals.OciImage,
309+
})
305310
}
306311

307312
newIdxRelease := release.IndexRelease{
308313
Commits: commits,
314+
OciImages: pullspecs,
309315
Version: specVersion,
310316
MetadataURL: url.String(),
311317
}
@@ -316,19 +322,20 @@ func modifyReleaseMetadataIndex(api *aws.API, rel release.Release) {
316322
plog.Fatalf("build is already present and is not the latest release")
317323
}
318324

319-
comp := compareCommits(rel.Commits, newIdxRelease.Commits)
320-
if comp == 0 {
325+
compCommits := compareCommits(rel.Commits, newIdxRelease.Commits)
326+
compImages := compareOciImages(rel.OciImages, newIdxRelease.OciImages)
327+
if compCommits == 0 && compImages == 0 {
321328
// the build is already the latest release, exit
322329
plog.Notice("build is already present and is the latest release")
323330
return
324-
} else if comp == -1 {
331+
} else if compCommits == -1 || compImages == -1 {
325332
// the build is present and contains a subset of the new release data,
326333
// pop the old entry and add the new version
327334
releaseIdx.Releases = releaseIdx.Releases[:len(releaseIdx.Releases)-1]
328335
break
329336
} else {
330337
// the commit hash of the new build is not a superset of the current release
331-
plog.Fatalf("build is present but commit hashes are not a superset of latest release")
338+
plog.Fatalf("build is present but commit hashes or images are not a superset of latest release")
332339
}
333340
}
334341
}
@@ -388,3 +395,27 @@ func compareCommits(a, b []release.IndexReleaseCommit) int {
388395
}
389396
return -1
390397
}
398+
399+
// returns -1 if a is a subset of b, 0 if equal, 1 if a is not a subset of b
400+
func compareOciImages(a, b []release.IndexReleaseOciImage) int {
401+
if len(a) > len(b) {
402+
return 1
403+
}
404+
sameLength := len(a) == len(b)
405+
for _, aImage := range a {
406+
found := false
407+
for _, bImage := range b {
408+
if aImage.Architecture == bImage.Architecture && aImage.ContainerImage == bImage.ContainerImage {
409+
found = true
410+
break
411+
}
412+
}
413+
if !found {
414+
return 1
415+
}
416+
}
417+
if sameLength {
418+
return 0
419+
}
420+
return -1
421+
}

0 commit comments

Comments
 (0)